use of jdk.vm.ci.code.site.Infopoint in project graal by oracle.
the class InfopointReasonTest method lineInfopoints.
@Test
public void lineInfopoints() {
final ResolvedJavaMethod method = getResolvedJavaMethod("testMethod");
final StructuredGraph graph = parse(builder(method, AllowAssumptions.ifTrue(OptAssumptions.getValue(getInitialOptions()))), getDebugGraphBuilderSuite());
int graphLineSPs = 0;
for (FullInfopointNode ipn : graph.getNodes().filter(FullInfopointNode.class)) {
if (ipn.getReason() == InfopointReason.BYTECODE_POSITION) {
++graphLineSPs;
}
}
assertTrue(graphLineSPs > 0);
PhaseSuite<HighTierContext> graphBuilderSuite = getCustomGraphBuilderSuite(GraphBuilderConfiguration.getDefault(getDefaultGraphBuilderPlugins()).withFullInfopoints(true));
final CompilationResult cr = compileGraph(graph, graph.method(), getProviders(), getBackend(), graphBuilderSuite, OptimisticOptimizations.ALL, graph.getProfilingInfo(), createSuites(graph.getOptions()), createLIRSuites(graph.getOptions()), new CompilationResult(graph.compilationId()), CompilationResultBuilderFactory.Default);
int lineSPs = 0;
for (Infopoint sp : cr.getInfopoints()) {
assertNotNull(sp.reason);
if (sp.reason == InfopointReason.BYTECODE_POSITION) {
++lineSPs;
}
}
assertTrue(lineSPs > 0);
}
use of jdk.vm.ci.code.site.Infopoint in project graal by oracle.
the class Stub method checkStubInvariants.
/**
* Checks the conditions a compilation must satisfy to be installed as a RuntimeStub.
*/
private boolean checkStubInvariants(CompilationResult compResult) {
assert compResult.getExceptionHandlers().isEmpty() : this;
// assumptions and there is no point in recording evol_method dependencies
assert compResult.getAssumptions() == null : "stubs should not use assumptions: " + this;
for (DataPatch data : compResult.getDataPatches()) {
if (data.reference instanceof ConstantReference) {
ConstantReference ref = (ConstantReference) data.reference;
if (ref.getConstant() instanceof HotSpotMetaspaceConstant) {
HotSpotMetaspaceConstant c = (HotSpotMetaspaceConstant) ref.getConstant();
if (c.asResolvedJavaType() != null && c.asResolvedJavaType().getName().equals("[I")) {
// embedding the type '[I' is safe, since it is never unloaded
continue;
}
}
}
assert !(data.reference instanceof ConstantReference) : this + " cannot have embedded object or metadata constant: " + data.reference;
}
for (Infopoint infopoint : compResult.getInfopoints()) {
assert infopoint instanceof Call : this + " cannot have non-call infopoint: " + infopoint;
Call call = (Call) infopoint;
assert call.target instanceof HotSpotForeignCallLinkage : this + " cannot have non runtime call: " + call.target;
HotSpotForeignCallLinkage callLinkage = (HotSpotForeignCallLinkage) call.target;
assert !callLinkage.isCompiledStub() || callLinkage.getDescriptor().equals(UNCOMMON_TRAP_HANDLER) : this + " cannot call compiled stub " + callLinkage;
}
return true;
}
use of jdk.vm.ci.code.site.Infopoint in project graal by oracle.
the class InstalledCodeBuilder method patchCalls.
private int patchCalls(AMD64InstructionPatcher patcher) {
/*
* Patch the direct call instructions. TODO: This is highly x64 specific. Should be
* rewritten to generic backends.
*/
Map<Long, Integer> directTargets = new HashMap<>();
int currentPos = codeSize;
for (Infopoint infopoint : compilation.getInfopoints()) {
if (infopoint instanceof Call && ((Call) infopoint).direct) {
Call call = (Call) infopoint;
long targetAddress = getTargetCodeAddress(call);
long pcDisplacement = targetAddress - (code.rawValue() + call.pcOffset);
if (pcDisplacement != (int) pcDisplacement || testTrampolineJumps) {
/*
* In case a trampoline jump is need we just "call" the trampoline jump at the
* end of the code.
*/
Long destAddr = Long.valueOf(targetAddress);
Integer trampolineOffset = directTargets.get(destAddr);
if (trampolineOffset == null) {
trampolineOffset = currentPos;
directTargets.put(destAddr, trampolineOffset);
currentPos += TRAMPOLINE_JUMP_SIZE;
}
pcDisplacement = trampolineOffset - call.pcOffset;
}
assert pcDisplacement == (int) pcDisplacement;
// Patch a PC-relative call.
patcher.findPatchData(call.pcOffset, (int) pcDisplacement).apply(compiledBytes);
}
}
if (directTargets.size() > 0) {
/*
* Insert trampoline jumps. Note that this is only a fail-safe, because usually the code
* should be within a 32-bit address range.
*/
currentPos = ObjectLayout.roundUp(currentPos, 8);
ByteBuffer codeBuffer = ByteBuffer.wrap(compiledBytes).order(ConfigurationValues.getTarget().arch.getByteOrder());
for (Entry<Long, Integer> entry : directTargets.entrySet()) {
long targetAddress = entry.getKey();
int trampolineOffset = entry.getValue();
// Write the "jmp [rip+offset]" instruction
codeBuffer.put(trampolineOffset + 0, (byte) 0xff);
codeBuffer.put(trampolineOffset + 1, (byte) 0x25);
codeBuffer.putInt(trampolineOffset + 2, currentPos - (trampolineOffset + TRAMPOLINE_JUMP_SIZE));
// Write the target address
codeBuffer.putLong(currentPos, targetAddress);
currentPos += 8;
}
}
return currentPos;
}
use of jdk.vm.ci.code.site.Infopoint in project graal by oracle.
the class HotSpotMonitorValueTest method addMethod.
@Override
protected InstalledCode addMethod(DebugContext debug, ResolvedJavaMethod method, CompilationResult compResult) {
for (Infopoint i : compResult.getInfopoints()) {
if (i instanceof Call) {
Call call = (Call) i;
if (call.target instanceof ResolvedJavaMethod) {
ResolvedJavaMethod target = (ResolvedJavaMethod) call.target;
if (target.equals(lookupObjectWait())) {
BytecodeFrame frame = call.debugInfo.frame();
BytecodeFrame caller = frame.caller();
assertNotNull(caller);
assertNull(caller.caller());
assertDeepEquals(2, frame.numLocks);
assertDeepEquals(2, caller.numLocks);
StackLockValue lock1 = (StackLockValue) frame.getLockValue(0);
StackLockValue lock2 = (StackLockValue) frame.getLockValue(1);
StackLockValue lock3 = (StackLockValue) caller.getLockValue(0);
StackLockValue lock4 = (StackLockValue) caller.getLockValue(1);
List<StackLockValue> locks = Arrays.asList(lock1, lock2, lock3, lock4);
for (StackLockValue lock : locks) {
for (StackLockValue other : locks) {
if (other != lock) {
// Every lock must have a different stack slot
assertThat(lock.getSlot(), not(other.getSlot()));
}
}
}
assertDeepEquals(lock3.getOwner(), lock4.getOwner());
assertThat(lock1.getOwner(), not(lock2.getOwner()));
return super.addMethod(debug, method, compResult);
}
}
}
}
throw new AssertionError("Could not find debug info for call to Object.wait(long)");
}
use of jdk.vm.ci.code.site.Infopoint in project graal by oracle.
the class CollectingObjectReferenceVisitor method addMethod.
public void addMethod(SharedMethod method, CompilationResult compilation, int compilationOffset) {
int totalFrameSize = compilation.getTotalFrameSize();
/* Mark the method start and register the frame size. */
IPData startEntry = makeEntry(compilationOffset);
startEntry.frameSizeEncoding = encodeFrameSize(totalFrameSize, true);
/* Register the frame size for all entries that are starting points for the index. */
long entryIP = CodeInfoDecoder.lookupEntryIP(CodeInfoDecoder.indexGranularity() + compilationOffset);
while (entryIP <= CodeInfoDecoder.lookupEntryIP(compilation.getTargetCodeSize() + compilationOffset)) {
IPData entry = makeEntry(entryIP);
entry.frameSizeEncoding = encodeFrameSize(totalFrameSize, false);
entryIP += CodeInfoDecoder.indexGranularity();
}
/* Make entries for all calls and deoptimization entry points of the method. */
for (Infopoint infopoint : compilation.getInfopoints()) {
final DebugInfo debugInfo = infopoint.debugInfo;
if (debugInfo != null) {
final int offset = getEntryOffset(infopoint);
if (offset >= 0) {
IPData entry = makeEntry(offset + compilationOffset);
assert entry.referenceMap == null && entry.frameData == null;
entry.referenceMap = (ReferenceMapEncoder.Input) debugInfo.getReferenceMap();
entry.frameData = frameInfoEncoder.addDebugInfo(method, infopoint, totalFrameSize);
}
}
}
/* Make entries for all exception handlers. */
for (ExceptionHandler handler : compilation.getExceptionHandlers()) {
final IPData entry = makeEntry(handler.pcOffset + compilationOffset);
assert entry.exceptionOffset == 0;
entry.exceptionOffset = handler.handlerPos - handler.pcOffset;
}
ImageSingletons.lookup(Counters.class).methodCount.inc();
ImageSingletons.lookup(Counters.class).codeSize.add(compilation.getTargetCodeSize());
}
Aggregations