All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.oracle.truffle.object.DynamicObjectImplGen Maven / Gradle / Ivy

Go to download

Truffle is a multi-language framework for executing dynamic languages that achieves high performance when combined with Graal.

There is a newer version: 24.1.1
Show newest version
// CheckStyle: start generated
package com.oracle.truffle.object;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.GeneratedBy;
import com.oracle.truffle.api.library.DynamicDispatchLibrary;
import com.oracle.truffle.api.library.LibraryExport;
import com.oracle.truffle.api.nodes.NodeCost;
import com.oracle.truffle.api.object.ObjectType;
import com.oracle.truffle.api.object.Shape;
import com.oracle.truffle.object.DynamicObjectImpl.Accepts;
import com.oracle.truffle.object.DynamicObjectImpl.Dispatch;
import java.util.concurrent.locks.Lock;

@GeneratedBy(DynamicObjectImpl.class)
@SuppressWarnings("unused")
final class DynamicObjectImplGen {

    static  {
        LibraryExport.register(DynamicObjectImpl.class, new DynamicDispatchLibraryExports());
    }

    private DynamicObjectImplGen() {
    }

    @GeneratedBy(DynamicObjectImpl.class)
    private static final class DynamicDispatchLibraryExports extends LibraryExport {

        private DynamicDispatchLibraryExports() {
            super(DynamicDispatchLibrary.class, DynamicObjectImpl.class, false);
        }

        @Override
        protected DynamicDispatchLibrary createUncached(Object receiver) {
            assert receiver instanceof DynamicObjectImpl;
            DynamicDispatchLibrary uncached = new Uncached(receiver);
            return uncached;
        }

        @Override
        protected DynamicDispatchLibrary createCached(Object receiver) {
            assert receiver instanceof DynamicObjectImpl;
            return new Cached(receiver);
        }

        @GeneratedBy(DynamicObjectImpl.class)
        private static final class Cached extends DynamicDispatchLibrary {

            private final Class receiverClass_;
            @CompilationFinal private volatile int state_;
            @CompilationFinal private volatile int exclude_;
            @CompilationFinal private Shape cachedShape;
            @CompilationFinal private Class cachedTypeClass;

            Cached(Object originalReceiver) {
                DynamicObjectImpl receiver = ((DynamicObjectImpl) originalReceiver) ;
                this.receiverClass_ = receiver.getClass();
            }

            @Override
            public Object cast(Object receiver) {
                return CompilerDirectives.castExact(receiver, receiverClass_);
            }

            @Override
            public boolean accepts(Object receiver) {
                return receiver.getClass() == this.receiverClass_ && accepts_(receiver);
            }

            private boolean accepts_(Object arg0Value_) {
                DynamicObjectImpl arg0Value = CompilerDirectives.castExact(arg0Value_, receiverClass_);
                int state = state_;
                if ((state & 0b11) != 0 /* is-active doCachedShape(DynamicObjectImpl, Shape, Class) || doCachedTypeClass(DynamicObjectImpl, Class) */) {
                    if ((state & 0b1) != 0 /* is-active doCachedShape(DynamicObjectImpl, Shape, Class) */) {
                        if ((this.cachedShape == arg0Value.getShape())) {
                            return Accepts.doCachedShape(arg0Value, this.cachedShape, this.cachedTypeClass);
                        }
                    }
                    if ((state & 0b10) != 0 /* is-active doCachedTypeClass(DynamicObjectImpl, Class) */) {
                        return Accepts.doCachedTypeClass(arg0Value, this.cachedTypeClass);
                    }
                }
                CompilerDirectives.transferToInterpreterAndInvalidate();
                return acceptsAndSpecialize(arg0Value);
            }

            private boolean acceptsAndSpecialize(DynamicObjectImpl arg0Value) {
                Lock lock = getLock();
                boolean hasLock = true;
                lock.lock();
                int state = state_;
                int exclude = exclude_;
                try {
                    if (((exclude & 0b1)) == 0 /* is-not-excluded doCachedShape(DynamicObjectImpl, Shape, Class) */) {
                        boolean CachedShape_duplicateFound_ = false;
                        if ((state & 0b1) != 0 /* is-active doCachedShape(DynamicObjectImpl, Shape, Class) */) {
                            if ((this.cachedShape == arg0Value.getShape())) {
                                CachedShape_duplicateFound_ = true;
                            }
                        }
                        if (!CachedShape_duplicateFound_) {
                            {
                                Shape accepts_cachedShape_cachedShape__ = (arg0Value.getShape());
                                if ((accepts_cachedShape_cachedShape__ == arg0Value.getShape()) && ((state & 0b1)) == 0 /* is-not-active doCachedShape(DynamicObjectImpl, Shape, Class) */) {
                                    if (this.cachedShape == null) {
                                        this.cachedShape = accepts_cachedShape_cachedShape__;
                                    }
                                    if (this.cachedTypeClass == null) {
                                        this.cachedTypeClass = (DynamicObjectImpl.getObjectType(arg0Value.getShape()).getClass());
                                    }
                                    this.state_ = state = state | 0b1 /* add-active doCachedShape(DynamicObjectImpl, Shape, Class) */;
                                    CachedShape_duplicateFound_ = true;
                                }
                            }
                        }
                        if (CachedShape_duplicateFound_) {
                            lock.unlock();
                            hasLock = false;
                            return Accepts.doCachedShape(arg0Value, this.cachedShape, this.cachedTypeClass);
                        }
                    }
                    if (this.cachedTypeClass == null) {
                        this.cachedTypeClass = (DynamicObjectImpl.getObjectType(arg0Value.getShape()).getClass());
                    }
                    this.exclude_ = exclude = exclude | 0b1 /* add-excluded doCachedShape(DynamicObjectImpl, Shape, Class) */;
                    state = state & 0xfffffffe /* remove-active doCachedShape(DynamicObjectImpl, Shape, Class) */;
                    this.state_ = state = state | 0b10 /* add-active doCachedTypeClass(DynamicObjectImpl, Class) */;
                    lock.unlock();
                    hasLock = false;
                    return Accepts.doCachedTypeClass(arg0Value, this.cachedTypeClass);
                } finally {
                    if (hasLock) {
                        lock.unlock();
                    }
                }
            }

            @Override
            public NodeCost getCost() {
                int state = state_;
                if ((state & 0b11) == 0b0) {
                    return NodeCost.UNINITIALIZED;
                } else if (((state & 0b11) & ((state & 0b11) - 1)) == 0 /* is-single-active  */) {
                    return NodeCost.MONOMORPHIC;
                }
                return NodeCost.POLYMORPHIC;
            }

            @Override
            public Class dispatch(Object arg0Value_) {
                assert this.accepts(arg0Value_) : "Invalid library usage. Library does not accept given receiver.";
                assert getRootNode() != null : "Invalid libray usage. Cached library must be adopted by a RootNode before it is executed.";
                DynamicObjectImpl arg0Value = CompilerDirectives.castExact(arg0Value_, receiverClass_);
                int state = state_;
                if ((state & 0b1100) != 0 /* is-active doCachedShape(DynamicObjectImpl, Shape, Class) || doCachedTypeClass(DynamicObjectImpl, Class) */) {
                    if ((state & 0b100) != 0 /* is-active doCachedShape(DynamicObjectImpl, Shape, Class) */) {
                        if ((this.cachedShape == arg0Value.getShape())) {
                            return Dispatch.doCachedShape(arg0Value, this.cachedShape, this.cachedTypeClass);
                        }
                    }
                    if ((state & 0b1000) != 0 /* is-active doCachedTypeClass(DynamicObjectImpl, Class) */) {
                        return Dispatch.doCachedTypeClass(arg0Value, this.cachedTypeClass);
                    }
                }
                CompilerDirectives.transferToInterpreterAndInvalidate();
                return dispatchAndSpecialize(arg0Value);
            }

            private Class dispatchAndSpecialize(DynamicObjectImpl arg0Value) {
                Lock lock = getLock();
                boolean hasLock = true;
                lock.lock();
                int state = state_;
                int exclude = exclude_;
                try {
                    if (((exclude & 0b10)) == 0 /* is-not-excluded doCachedShape(DynamicObjectImpl, Shape, Class) */) {
                        boolean CachedShape_duplicateFound_ = false;
                        if ((state & 0b100) != 0 /* is-active doCachedShape(DynamicObjectImpl, Shape, Class) */) {
                            if ((this.cachedShape == arg0Value.getShape())) {
                                CachedShape_duplicateFound_ = true;
                            }
                        }
                        if (!CachedShape_duplicateFound_) {
                            {
                                Shape dispatch_cachedShape_cachedShape__ = (arg0Value.getShape());
                                if ((dispatch_cachedShape_cachedShape__ == arg0Value.getShape()) && ((state & 0b100)) == 0 /* is-not-active doCachedShape(DynamicObjectImpl, Shape, Class) */) {
                                    if (this.cachedShape == null) {
                                        this.cachedShape = dispatch_cachedShape_cachedShape__;
                                    }
                                    if (this.cachedTypeClass == null) {
                                        this.cachedTypeClass = (DynamicObjectImpl.getObjectType(arg0Value.getShape()).getClass());
                                    }
                                    this.state_ = state = state | 0b100 /* add-active doCachedShape(DynamicObjectImpl, Shape, Class) */;
                                    CachedShape_duplicateFound_ = true;
                                }
                            }
                        }
                        if (CachedShape_duplicateFound_) {
                            lock.unlock();
                            hasLock = false;
                            return Dispatch.doCachedShape(arg0Value, this.cachedShape, this.cachedTypeClass);
                        }
                    }
                    if (this.cachedTypeClass == null) {
                        this.cachedTypeClass = (DynamicObjectImpl.getObjectType(arg0Value.getShape()).getClass());
                    }
                    this.exclude_ = exclude = exclude | 0b10 /* add-excluded doCachedShape(DynamicObjectImpl, Shape, Class) */;
                    state = state & 0xfffffffb /* remove-active doCachedShape(DynamicObjectImpl, Shape, Class) */;
                    this.state_ = state = state | 0b1000 /* add-active doCachedTypeClass(DynamicObjectImpl, Class) */;
                    lock.unlock();
                    hasLock = false;
                    return Dispatch.doCachedTypeClass(arg0Value, this.cachedTypeClass);
                } finally {
                    if (hasLock) {
                        lock.unlock();
                    }
                }
            }

        }
        @GeneratedBy(DynamicObjectImpl.class)
        private static final class Uncached extends DynamicDispatchLibrary {

            Uncached(Object receiver) {
            }

            @TruffleBoundary
            @Override
            public boolean accepts(Object receiver) {
                return receiver instanceof DynamicObjectImpl && accepts_(receiver);
            }

            @SuppressWarnings("cast")
            @TruffleBoundary
            @Override
            public Object cast(Object receiver) {
                return ((DynamicObjectImpl) receiver);
            }

            @Override
            public boolean isAdoptable() {
                return false;
            }

            @Override
            public NodeCost getCost() {
                return NodeCost.MEGAMORPHIC;
            }

            @TruffleBoundary
            @Override
            public Class dispatch(Object arg0Value_) {
                assert this.accepts(arg0Value_) : "Invalid library usage. Library does not accept given receiver.";
                DynamicObjectImpl arg0Value = ((DynamicObjectImpl) arg0Value_);
                return Dispatch.doCachedTypeClass(arg0Value, (DynamicObjectImpl.getObjectType(arg0Value.getShape()).getClass()));
            }

            @TruffleBoundary
            private static boolean accepts_(Object arg0Value_) {
                DynamicObjectImpl arg0Value = ((DynamicObjectImpl) arg0Value_);
                return Accepts.doCachedTypeClass(arg0Value, (DynamicObjectImpl.getObjectType(arg0Value.getShape()).getClass()));
            }

        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy