private void addDirectRelocationWithoutAddend(RelocatableBuffer buffer, int index, int size, Object target) { assert !spawnIsolates() || index >= readOnlyRelocatable.offsetInSection() && index < readOnlyRelocatable.offsetInSection(readOnlyRelocatable.getSize()); buffer.addDirectRelocationWithoutAddend(index, size, target); if (firstRelocatablePointerOffsetInSection == -1) { firstRelocatablePointerOffsetInSection = index; } }
@Override public void relocate(Reference ref, RelocatableBuffer relocs, int compStart) { /* * The relocation site is some offset into the instruction, which is some offset into the * method, which is some offset into the text section (a.k.a. code cache). The offset we get * out of the RelocationSiteInfo accounts for the first two, since we pass it the whole * method. We add the method start to get the section-relative offset. */ long siteOffset = compStart + annotation.operandPosition; if (ref instanceof DataSectionReference || ref instanceof CGlobalDataReference) { /* * Do we have an addend? Yes; it's constStart. BUT x86/x86-64 PC-relative references are * relative to the *next* instruction. So, if the next instruction starts n bytes from * the relocation site, we want to subtract n bytes from our addend. */ long addend = (annotation.nextInstructionPosition - annotation.operandPosition); relocs.addPCRelativeRelocationWithAddend((int) siteOffset, annotation.operandSize, addend, ref); } else if (ref instanceof ConstantReference) { assert SubstrateOptions.SpawnIsolates.getValue() : "Inlined object references must be base-relative"; relocs.addDirectRelocationWithoutAddend((int) siteOffset, annotation.operandSize, ref); } else { throw VMError.shouldNotReachHere("Unknown type of reference in code"); } } }