use of jdk.vm.ci.meta.ResolvedJavaMethod in project graal by oracle.
the class CompilationWatchDog method run.
@Override
public void run() {
try {
trace("Started%n", this);
while (true) {
// get a copy of the last set method
final ResolvedJavaMethod currentlyCompiling = currentMethod;
if (currentlyCompiling == null) {
// continue sleeping, compilation is either over before starting
// to watch the compiler thread or no compilation at all started
reset();
} else {
switch(state) {
case SLEEPING:
lastWatched = currentlyCompiling;
elapsed = 0;
tick(WatchDogState.WATCHING_WITHOUT_STACK_INSPECTION);
break;
case WATCHING_WITHOUT_STACK_INSPECTION:
if (currentlyCompiling.equals(lastWatched)) {
if (elapsed >= startDelayMilliseconds) {
// we looked at the same compilation for a certain time
// so now we start to collect stack traces
tick(WatchDogState.WATCHING_WITH_STACK_INSPECTION);
trace("changes mode to watching with stack traces");
} else {
// we still compile the same method but won't collect traces
// yet
trace("watching without stack traces [%.2f seconds]", secs(elapsed));
}
elapsed += SPIN_TIMEOUT_MS;
} else {
// compilation finished before we exceeded initial watching
// period
reset();
}
break;
case WATCHING_WITH_STACK_INSPECTION:
if (currentlyCompiling.equals(lastWatched)) {
if (elapsed >= startDelayMilliseconds + (traceIntervals * stackTraceIntervalMilliseconds)) {
trace("took a stack trace");
boolean newStackTrace = recordStackTrace(compilerThread.getStackTrace());
if (!newStackTrace) {
trace("%d identical stack traces in a row", numberOfIdenticalStackTraces);
numberOfIdenticalStackTraces = 0;
}
numberOfIdenticalStackTraces++;
if (numberOfIdenticalStackTraces > nonFatalIdenticalCompilationSnapshots) {
synchronized (CompilationWatchDog.class) {
TTY.printf("======================= WATCH DOG THREAD =======================%n" + "%s took %d identical stack traces, which indicates a stuck compilation (id=%d) of %s%n%sExiting VM%n", this, numberOfIdenticalStackTraces, currentId, fmt(currentMethod), fmt(lastStackTrace));
System.exit(-1);
}
} else if (newStackTrace) {
synchronized (CompilationWatchDog.class) {
TTY.printf("======================= WATCH DOG THREAD =======================%n" + "%s detected long running compilation (id=%d) of %s [%.2f seconds]%n%s", this, currentId, fmt(currentMethod), secs(elapsed), fmt(lastStackTrace));
}
}
traceIntervals++;
} else {
// we still watch the compilation in the same trace interval
trace("watching with stack traces [%.2f seconds]", secs(elapsed));
}
elapsed += SPIN_TIMEOUT_MS;
} else {
// compilation finished before we are able to collect stack
// traces
reset();
}
break;
default:
break;
}
}
try {
Thread.sleep(SPIN_TIMEOUT_MS);
} catch (InterruptedException e) {
// Silently swallow
}
}
} catch (VirtualMachineError vmError) {
/*
* We encounter a VM error. This includes for example OutOfMemoryExceptions. In such a
* case we silently swallow the error. If it happens again the application thread will
* most likely encounter the same problem. If not the watchdog thread will no longer
* monitor the compilation and thus the error cannot happen again.
*/
} catch (Throwable t) {
/*
* A real exception happened on the compilation watchdog. This is unintended behavior
* and must not happen in any case.
*/
throw new InternalError(String.format("%s encountered an exception%n%s%n", this, fmt(t)), t);
}
}
use of jdk.vm.ci.meta.ResolvedJavaMethod in project graal by oracle.
the class HotSpotCompiledCodeBuilder method createCompiledCode.
public static HotSpotCompiledCode createCompiledCode(CodeCacheProvider codeCache, ResolvedJavaMethod method, HotSpotCompilationRequest compRequest, CompilationResult compResult) {
String name = compResult.getName();
byte[] targetCode = compResult.getTargetCode();
int targetCodeSize = compResult.getTargetCodeSize();
Site[] sites = getSortedSites(codeCache, compResult);
Assumption[] assumptions = compResult.getAssumptions();
ResolvedJavaMethod[] methods = compResult.getMethods();
List<CodeAnnotation> annotations = compResult.getAnnotations();
Comment[] comments = new Comment[annotations.size()];
if (!annotations.isEmpty()) {
for (int i = 0; i < comments.length; i++) {
CodeAnnotation annotation = annotations.get(i);
String text;
if (annotation instanceof CodeComment) {
CodeComment codeComment = (CodeComment) annotation;
text = codeComment.value;
} else if (annotation instanceof JumpTable) {
JumpTable jumpTable = (JumpTable) annotation;
text = "JumpTable [" + jumpTable.low + " .. " + jumpTable.high + "]";
} else {
text = annotation.toString();
}
comments[i] = new Comment(annotation.position, text);
}
}
DataSection data = compResult.getDataSection();
byte[] dataSection = new byte[data.getSectionSize()];
ByteBuffer buffer = ByteBuffer.wrap(dataSection).order(ByteOrder.nativeOrder());
Builder<DataPatch> patchBuilder = Stream.builder();
data.buildDataSection(buffer, (position, vmConstant) -> {
patchBuilder.accept(new DataPatch(position, new ConstantReference(vmConstant)));
});
int dataSectionAlignment = data.getSectionAlignment();
DataPatch[] dataSectionPatches = patchBuilder.build().toArray(len -> new DataPatch[len]);
int totalFrameSize = compResult.getTotalFrameSize();
StackSlot customStackArea = compResult.getCustomStackArea();
boolean isImmutablePIC = compResult.isImmutablePIC();
if (method instanceof HotSpotResolvedJavaMethod) {
HotSpotResolvedJavaMethod hsMethod = (HotSpotResolvedJavaMethod) method;
int entryBCI = compResult.getEntryBCI();
boolean hasUnsafeAccess = compResult.hasUnsafeAccess();
int id;
long jvmciEnv;
if (compRequest != null) {
id = compRequest.getId();
jvmciEnv = compRequest.getJvmciEnv();
} else {
id = hsMethod.allocateCompileId(entryBCI);
jvmciEnv = 0L;
}
return new HotSpotCompiledNmethod(name, targetCode, targetCodeSize, sites, assumptions, methods, comments, dataSection, dataSectionAlignment, dataSectionPatches, isImmutablePIC, totalFrameSize, customStackArea, hsMethod, entryBCI, id, jvmciEnv, hasUnsafeAccess);
} else {
return new HotSpotCompiledCode(name, targetCode, targetCodeSize, sites, assumptions, methods, comments, dataSection, dataSectionAlignment, dataSectionPatches, isImmutablePIC, totalFrameSize, customStackArea);
}
}
use of jdk.vm.ci.meta.ResolvedJavaMethod in project graal by oracle.
the class StandardGraphBuilderPlugins method registerClassPlugins.
private static void registerClassPlugins(InvocationPlugins plugins) {
Registration r = new Registration(plugins, Class.class);
r.register2("isInstance", Receiver.class, Object.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver type, ValueNode object) {
LogicNode condition = b.append(InstanceOfDynamicNode.create(b.getAssumptions(), b.getConstantReflection(), type.get(), object, false));
b.push(JavaKind.Boolean, b.append(new ConditionalNode(condition).canonical(null)));
return true;
}
});
r.register2("isAssignableFrom", Receiver.class, Class.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver type, ValueNode otherType) {
ClassIsAssignableFromNode condition = b.append(new ClassIsAssignableFromNode(type.get(), otherType));
b.push(JavaKind.Boolean, b.append(new ConditionalNode(condition).canonical(null)));
return true;
}
});
}
use of jdk.vm.ci.meta.ResolvedJavaMethod in project graal by oracle.
the class StandardGraphBuilderPlugins method registerCharacterPlugins.
private static void registerCharacterPlugins(InvocationPlugins plugins) {
Registration r = new Registration(plugins, Character.class);
r.register1("reverseBytes", char.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
// return (char) (Integer.reverse(i) >> 16);
ReverseBytesNode reverse = b.add(new ReverseBytesNode(value));
RightShiftNode rightShift = b.add(new RightShiftNode(reverse, b.add(ConstantNode.forInt(16))));
ZeroExtendNode charCast = b.add(new ZeroExtendNode(b.add(new NarrowNode(rightShift, 16)), 32));
b.push(JavaKind.Char, b.append(charCast.canonical(null)));
return true;
}
});
}
use of jdk.vm.ci.meta.ResolvedJavaMethod in project graal by oracle.
the class StandardGraphBuilderPlugins method registerDoublePlugins.
private static void registerDoublePlugins(InvocationPlugins plugins) {
Registration r = new Registration(plugins, Double.class);
r.register1("doubleToRawLongBits", double.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
b.push(JavaKind.Long, b.append(ReinterpretNode.create(JavaKind.Long, value, NodeView.DEFAULT)));
return true;
}
});
r.register1("longBitsToDouble", long.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
b.push(JavaKind.Double, b.append(ReinterpretNode.create(JavaKind.Double, value, NodeView.DEFAULT)));
return true;
}
});
}
Aggregations