Search in sources :

Example 1 with DebugCloseable

use of com.oracle.truffle.espresso.perf.DebugCloseable in project graal by oracle.

the class StructsAccess method initializeStructs.

@SuppressWarnings("try")
private static Structs initializeStructs(EspressoContext context, TruffleObject initializeStructs, TruffleObject lookupMemberOffset) {
    try (DebugCloseable timer = STRUCTS_TIMER.scope(context.getTimers())) {
        Structs[] box = new Structs[1];
        Callback doInitStructs = new Callback(1, new Callback.Function() {

            @Override
            @CompilerDirectives.TruffleBoundary
            public Object call(Object... args) {
                TruffleObject memberInfoPtr = (TruffleObject) args[0];
                box[0] = new Structs(context.getJNI(), memberInfoPtr, lookupMemberOffset);
                return RawPointer.nullInstance();
            }
        });
        /*
             * Go down to native to initialize the data structure storing the offsets of used
             * structs (The memberInfoPtr seen in the callback). This will get back to java code
             * once the data structure is created. Once we get out of the native call, the structure
             * is freed and cannot be used anymore.
             */
        @Pointer TruffleObject closure = context.getNativeAccess().createNativeClosure(doInitStructs, NativeSignature.create(NativeType.VOID, NativeType.POINTER));
        try {
            InteropLibrary.getUncached().execute(initializeStructs, closure);
        } catch (UnsupportedTypeException | ArityException | UnsupportedMessageException e) {
            throw EspressoError.shouldNotReachHere();
        }
        return box[0];
    }
}
Also used : RawPointer(com.oracle.truffle.espresso.ffi.RawPointer) Pointer(com.oracle.truffle.espresso.ffi.Pointer) ArityException(com.oracle.truffle.api.interop.ArityException) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Callback(com.oracle.truffle.espresso.jni.Callback) UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) UnsupportedTypeException(com.oracle.truffle.api.interop.UnsupportedTypeException) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) DebugCloseable(com.oracle.truffle.espresso.perf.DebugCloseable)

Example 2 with DebugCloseable

use of com.oracle.truffle.espresso.perf.DebugCloseable in project graal by oracle.

the class LoadingConstraints method checkConstraint.

/**
 * Checks that loader1 and loader2 resolve type as the same Klass instance.
 */
@SuppressWarnings("try")
void checkConstraint(Symbol<Type> type, StaticObject loader1, StaticObject loader2) {
    try (DebugCloseable constraints = CONSTRAINTS.scope(getContext().getTimers())) {
        Klass k1 = getContext().getRegistries().findLoadedClass(type, loader1);
        Klass k2 = getContext().getRegistries().findLoadedClass(type, loader2);
        checkOrAdd(type, getKlassID(k1), getKlassID(k2), getLoaderID(loader1, getMeta()), getLoaderID(loader2, getMeta()));
    }
}
Also used : DebugCloseable(com.oracle.truffle.espresso.perf.DebugCloseable)

Example 3 with DebugCloseable

use of com.oracle.truffle.espresso.perf.DebugCloseable in project graal by oracle.

the class ClassRegistry method loadKlass.

/**
 * Queries a registry to load a Klass for us.
 *
 * @param type the symbolic reference to the Klass we want to load
 * @param protectionDomain The protection domain extracted from the guest class, or
 *            {@link StaticObject#NULL} if trusted.
 * @return The Klass corresponding to given type
 */
@SuppressWarnings("try")
Klass loadKlass(Symbol<Type> type, StaticObject protectionDomain) {
    if (Types.isArray(type)) {
        Klass elemental = loadKlass(getTypes().getElementalType(type), protectionDomain);
        if (elemental == null) {
            return null;
        }
        return elemental.getArrayClass(Types.getArrayDimensions(type));
    }
    loadKlassCountInc();
    // Double-checked locking on the symbol (globally unique).
    ClassRegistries.RegistryEntry entry;
    try (DebugCloseable probe = KLASS_PROBE.scope(getContext().getTimers())) {
        entry = classes.get(type);
    }
    if (entry == null) {
        synchronized (type) {
            entry = classes.get(type);
            if (entry == null) {
                if (loadKlassImpl(type) == null) {
                    return null;
                }
                entry = classes.get(type);
            }
        }
    } else {
        // Grabbing a lock to fetch the class is not considered a hit.
        loadKlassCacheHitsInc();
    }
    assert entry != null;
    StaticObject classLoader = getClassLoader();
    if (!StaticObject.isNull(classLoader)) {
        entry.checkPackageAccess(getMeta(), classLoader, protectionDomain);
    }
    return entry.klass();
}
Also used : StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) DebugCloseable(com.oracle.truffle.espresso.perf.DebugCloseable)

Example 4 with DebugCloseable

use of com.oracle.truffle.espresso.perf.DebugCloseable in project graal by oracle.

the class ClassfileParser method getClassName.

private Symbol<Symbol.Name> getClassName() {
    readMagic();
    minorVersion = stream.readU2();
    majorVersion = stream.readU2();
    verifyVersion(majorVersion, minorVersion);
    try (DebugCloseable closeable = CONSTANT_POOL.scope(context.getTimers())) {
        this.pool = ConstantPool.parse(context.getLanguage(), stream, this, classDefinitionInfo.patches, context, majorVersion, minorVersion);
    }
    // JVM_ACC_MODULE is defined in JDK-9 and later.
    if (majorVersion >= JAVA_9_VERSION) {
        classFlags = stream.readU2() & (JVM_RECOGNIZED_CLASS_MODIFIERS | ACC_MODULE);
    } else {
        classFlags = stream.readU2() & (JVM_RECOGNIZED_CLASS_MODIFIERS);
    }
    int thisKlassIndex = stream.readU2();
    return pool.classAt(thisKlassIndex).getName(pool);
}
Also used : DebugCloseable(com.oracle.truffle.espresso.perf.DebugCloseable)

Example 5 with DebugCloseable

use of com.oracle.truffle.espresso.perf.DebugCloseable in project graal by oracle.

the class LivenessAnalysis method analyze.

@SuppressWarnings("try")
public static LivenessAnalysis analyze(Method.MethodVersion methodVersion) {
    EspressoContext context = methodVersion.getMethod().getContext();
    if (!enableLivenessAnalysis(context, methodVersion)) {
        return NO_ANALYSIS;
    }
    Method method = methodVersion.getMethod();
    TimerCollection scope = method.getContext().getTimers();
    try (DebugCloseable liveness = LIVENESS_TIMER.scope(scope)) {
        Graph<? extends LinkedBlock> graph;
        try (DebugCloseable builder = BUILDER_TIMER.scope(scope)) {
            graph = GraphBuilder.build(method);
        }
        // Transform the graph into a more manageable graph consisting of only the history of
        // load/stores.
        LoadStoreFinder loadStoreClosure;
        try (DebugCloseable loadStore = LOADSTORE_TIMER.scope(scope)) {
            loadStoreClosure = new LoadStoreFinder(graph, method);
            loadStoreClosure.analyze();
        }
        // Computes the entry/end live sets for each variable for each block.
        BlockBoundaryFinder blockBoundaryFinder;
        try (DebugCloseable boundary = STATE_TIMER.scope(scope)) {
            blockBoundaryFinder = new BlockBoundaryFinder(methodVersion, loadStoreClosure.result());
            DepthFirstBlockIterator.analyze(method, graph, blockBoundaryFinder);
        }
        try (DebugCloseable propagation = PROPAGATE_TIMER.scope(scope)) {
            // Forces loop ends to inherit the loop entry state, and propagates the changes.
            LoopPropagatorClosure loopPropagation = new LoopPropagatorClosure(graph, blockBoundaryFinder.result());
            while (loopPropagation.process(graph)) {
            /*
                     * This loop should iterate at MOST exactly the maximum number of nested loops
                     * in the method.
                     *
                     * The reasoning is the following:
                     *
                     * - The only reason a new iteration is required is when a loop entry's state
                     * gets modified by the previous iteration.
                     *
                     * - This can happen only if a new live variable gets propagated from an outer
                     * loop.
                     *
                     * - Which means that we do not need to re-propagate the state of the outermost
                     * loop.
                     */
            }
        }
        // frees as early as possible each dead local.
        try (DebugCloseable actionFinder = ACTION_TIMER.scope(scope)) {
            Builder builder = new Builder(graph, methodVersion, blockBoundaryFinder.result());
            builder.build();
            return new LivenessAnalysis(builder.actions, builder.edge, builder.onStart);
        }
    }
}
Also used : TimerCollection(com.oracle.truffle.espresso.perf.TimerCollection) GraphBuilder(com.oracle.truffle.espresso.analysis.GraphBuilder) EspressoContext(com.oracle.truffle.espresso.runtime.EspressoContext) Method(com.oracle.truffle.espresso.impl.Method) DebugCloseable(com.oracle.truffle.espresso.perf.DebugCloseable)

Aggregations

DebugCloseable (com.oracle.truffle.espresso.perf.DebugCloseable)12 BootstrapMethodsAttribute (com.oracle.truffle.espresso.classfile.attributes.BootstrapMethodsAttribute)3 CodeAttribute (com.oracle.truffle.espresso.classfile.attributes.CodeAttribute)3 ConstantValueAttribute (com.oracle.truffle.espresso.classfile.attributes.ConstantValueAttribute)3 EnclosingMethodAttribute (com.oracle.truffle.espresso.classfile.attributes.EnclosingMethodAttribute)3 ExceptionsAttribute (com.oracle.truffle.espresso.classfile.attributes.ExceptionsAttribute)3 InnerClassesAttribute (com.oracle.truffle.espresso.classfile.attributes.InnerClassesAttribute)3 LineNumberTableAttribute (com.oracle.truffle.espresso.classfile.attributes.LineNumberTableAttribute)3 MethodParametersAttribute (com.oracle.truffle.espresso.classfile.attributes.MethodParametersAttribute)3 NestHostAttribute (com.oracle.truffle.espresso.classfile.attributes.NestHostAttribute)3 NestMembersAttribute (com.oracle.truffle.espresso.classfile.attributes.NestMembersAttribute)3 PermittedSubclassesAttribute (com.oracle.truffle.espresso.classfile.attributes.PermittedSubclassesAttribute)3 RecordAttribute (com.oracle.truffle.espresso.classfile.attributes.RecordAttribute)3 SignatureAttribute (com.oracle.truffle.espresso.classfile.attributes.SignatureAttribute)3 SourceDebugExtensionAttribute (com.oracle.truffle.espresso.classfile.attributes.SourceDebugExtensionAttribute)3 SourceFileAttribute (com.oracle.truffle.espresso.classfile.attributes.SourceFileAttribute)3 StackMapTableAttribute (com.oracle.truffle.espresso.classfile.attributes.StackMapTableAttribute)3 Symbol (com.oracle.truffle.espresso.descriptors.Symbol)3 Name (com.oracle.truffle.espresso.descriptors.Symbol.Name)3 Type (com.oracle.truffle.espresso.descriptors.Symbol.Type)3