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];
}
}
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()));
}
}
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();
}
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);
}
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);
}
}
}
Aggregations