use of org.graalvm.compiler.debug.DebugContext.Builder in project graal by oracle.
the class DebugContextTest method testEnabledSandbox.
@Test
public void testEnabledSandbox() {
TimerKeyTest.assumeManagementLibraryIsLoadable();
EconomicMap<OptionKey<?>, Object> map = EconomicMap.create();
// Configure with an option that enables scopes
map.put(DebugOptions.DumpOnError, true);
OptionValues options = new OptionValues(map);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DebugContext debug = new Builder(options).globalMetrics(NO_GLOBAL_METRIC_VALUES).description(NO_DESCRIPTION).logStream(new PrintStream(baos)).build();
Exception e = new Exception("testEnabledSandbox");
String scopeName = "";
try {
try (DebugContext.Scope d = debug.sandbox("TestExceptionHandling", debug.getConfig())) {
scopeName = d.getQualifiedName();
throw e;
} catch (Throwable t) {
assert e == t;
debug.handle(t);
}
} catch (Throwable t) {
// The exception object should propagate all the way out through
// a enabled sandbox scope
Assert.assertEquals(e, t);
}
String logged = baos.toString();
String expected = String.format("Exception raised in scope %s: %s", scopeName, e);
String line = "-------------------------------------------------------";
Assert.assertTrue(String.format("Could not find \"%s\" in content between lines below:%n%s%n%s%s", expected, line, logged, line), logged.contains(expected));
}
use of org.graalvm.compiler.debug.DebugContext.Builder in project graal by oracle.
the class NegateNodeCanonicalizationTest method before.
@Before
public void before() {
OptionValues options = getInitialOptions();
DebugContext debug = new Builder(options).build();
graph = new StructuredGraph.Builder(options, debug, AllowAssumptions.YES).build();
}
use of org.graalvm.compiler.debug.DebugContext.Builder in project graal by oracle.
the class StructuredGraphTest method testGetBytecodeSize.
@Test
public void testGetBytecodeSize() {
OptionValues options = getInitialOptions();
DebugContext debug = new Builder(options).build();
ResolvedJavaMethod rootMethod = getResolvedJavaMethod("testGetBytecodeSize");
// Test graph with root method and inlined methods
StructuredGraph graph = new StructuredGraph.Builder(options, debug, AllowAssumptions.YES).method(rootMethod).build();
ResolvedJavaMethod otherMethod = getResolvedJavaMethod(GraalCompilerTest.class, "createSuites");
int expectedBytecodeSize = rootMethod.getCodeSize();
for (int i = 0; i < 10; i++) {
graph.recordMethod(otherMethod);
expectedBytecodeSize += otherMethod.getCodeSize();
}
Assert.assertEquals(expectedBytecodeSize, graph.getBytecodeSize());
// Test graph with only root method, no inlined methods
graph = new StructuredGraph.Builder(options, debug, AllowAssumptions.YES).method(rootMethod).build();
expectedBytecodeSize = rootMethod.getCodeSize();
Assert.assertEquals(expectedBytecodeSize, graph.getBytecodeSize());
// Test graph with no root method, only inlined methods
graph = new StructuredGraph.Builder(options, debug, AllowAssumptions.YES).build();
expectedBytecodeSize = 0;
for (int i = 0; i < 10; i++) {
graph.recordMethod(otherMethod);
expectedBytecodeSize += otherMethod.getCodeSize();
}
Assert.assertEquals(expectedBytecodeSize, graph.getBytecodeSize());
// Test graph with no root method, no inlined methods
graph = new StructuredGraph.Builder(options, debug, AllowAssumptions.YES).build();
expectedBytecodeSize = 0;
Assert.assertEquals(expectedBytecodeSize, graph.getBytecodeSize());
}
use of org.graalvm.compiler.debug.DebugContext.Builder in project graal by oracle.
the class AbortOnDisallowedNode method canInitializeWithoutSideEffects.
@SuppressWarnings("try")
boolean canInitializeWithoutSideEffects(Class<?> clazz, Set<Class<?>> existingAnalyzedClasses) {
ResolvedJavaType type = originalProviders.getMetaAccess().lookupJavaType(clazz);
assert type.getSuperclass() == null || type.getSuperclass().isInitialized() : "This analysis assumes that the superclass was successfully analyzed and initialized beforehand: " + type.toJavaName(true);
ResolvedJavaMethod clinit = type.getClassInitializer();
if (clinit == null) {
/* No class initializer, so the class can trivially be initialized. */
return true;
} else if (clinit.getCode() == null) {
/*
* Happens e.g. when linking of the class failed. Note that we really need to check for
* getCode(), because getCodeSize() still returns a value > 0 for such methods.
*/
return false;
}
Set<Class<?>> analyzedClasses = existingAnalyzedClasses;
if (analyzedClasses == null) {
analyzedClasses = new HashSet<>();
} else if (analyzedClasses.contains(clazz)) {
/* Cyclic dependency of class initializers. */
return false;
}
analyzedClasses.add(clazz);
OptionValues options = HostedOptionValues.singleton();
DebugContext debug = new Builder(options).build();
try (DebugContext.Scope s = debug.scope("EarlyClassInitializerAnalysis", clinit)) {
return canInitializeWithoutSideEffects(clinit, analyzedClasses, options, debug);
} catch (Throwable ex) {
throw debug.handle(ex);
}
}
use of org.graalvm.compiler.debug.DebugContext.Builder in project graal by oracle.
the class LambdaProxyRenamingSubstitutionProcessor method getSubstitution.
private LambdaSubstitutionType getSubstitution(ResolvedJavaType original) {
return typeSubstitutions.computeIfAbsent(original, (key) -> {
OptionValues options = bb.getOptions();
DebugContext debug = new Builder(options, new GraalDebugHandlersFactory(bb.getProviders().getSnippetReflection())).build();
Providers providers = GraalAccess.getOriginalProviders();
String lambdaTargetName = LambdaUtils.findStableLambdaName(new NoClassInitializationPlugin(), providers, key, options, debug, this);
return new LambdaSubstitutionType(key, findUniqueLambdaProxyName(lambdaTargetName));
});
}
Aggregations