8171173: EXCEPTION_ACCESS_VIOLATION running VirtualObjectDebugInfoTest.java

Reviewed-by: kvn
This commit is contained in:
Tom Rodriguez 2017-01-24 08:51:07 +00:00
parent 4684856924
commit 56be1a28df
3 changed files with 60 additions and 2 deletions

View File

@ -25,6 +25,8 @@ package jdk.vm.ci.code.test;
import jdk.vm.ci.code.BytecodeFrame;
import jdk.vm.ci.code.DebugInfo;
import jdk.vm.ci.code.Location;
import jdk.vm.ci.code.RegisterValue;
import jdk.vm.ci.code.StackSlot;
import jdk.vm.ci.code.VirtualObject;
import jdk.vm.ci.hotspot.HotSpotReferenceMap;
import jdk.vm.ci.meta.JavaKind;
@ -32,6 +34,9 @@ import jdk.vm.ci.meta.JavaValue;
import jdk.vm.ci.meta.ResolvedJavaMethod;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* Test code installation with debug information.
@ -54,11 +59,43 @@ public class DebugInfoTest extends CodeInstallationTest {
int numStack = slotKinds.length - numLocals;
JavaValue[] values = new JavaValue[slotKinds.length];
test(asm -> {
/*
* Ensure that any objects mentioned in the VirtualObjects are also in the OopMap.
*/
List<Location> newLocations = new ArrayList<Location>(Arrays.asList(objects));
List<Location> newDerived = new ArrayList<Location>(Arrays.asList(derivedBase));
int[] newSizeInBytes = sizeInBytes;
VirtualObject[] vobjs = compiler.compile(asm, values);
if (vobjs != null) {
for (VirtualObject obj : vobjs) {
JavaValue[] objValues = obj.getValues();
for (int i = 0; i < objValues.length; i++) {
if (obj.getSlotKind(i) == JavaKind.Object) {
Location oopLocation = null;
int bytes = -1;
if (objValues[i] instanceof RegisterValue) {
RegisterValue reg = (RegisterValue) objValues[i];
oopLocation = Location.register(reg.getRegister());
bytes = reg.getValueKind().getPlatformKind().getSizeInBytes();
} else if (objValues[i] instanceof StackSlot) {
StackSlot slot = (StackSlot) objValues[i];
oopLocation = Location.stack(asm.getOffset(slot));
bytes = slot.getValueKind().getPlatformKind().getSizeInBytes();
}
if (oopLocation != null && !newLocations.contains(oopLocation)) {
newLocations.add(oopLocation);
newDerived.add(null);
newSizeInBytes = Arrays.copyOf(newSizeInBytes, newSizeInBytes.length + 1);
newSizeInBytes[newSizeInBytes.length - 1] = bytes;
}
}
}
}
}
BytecodeFrame frame = new BytecodeFrame(null, resolvedMethod, bci, false, false, values, slotKinds, numLocals, numStack, 0);
DebugInfo info = new DebugInfo(frame, vobjs);
info.setReferenceMap(new HotSpotReferenceMap(objects, derivedBase, sizeInBytes, 8));
info.setReferenceMap(new HotSpotReferenceMap(newLocations.toArray(new Location[0]), newDerived.toArray(new Location[0]), newSizeInBytes, 8));
asm.emitTrap(info);
}, method);

View File

@ -256,6 +256,10 @@ public abstract class TestAssembler {
return StackSlot.get(new TestValueKind(kind), -curStackSlot, true);
}
public int getOffset(StackSlot slot) {
return slot.getOffset(frameSize);
}
protected void growFrame(int sizeInBytes) {
curStackSlot += sizeInBytes;
if (curStackSlot > frameSize) {

View File

@ -103,6 +103,12 @@ public class VirtualObjectDebugInfoTest extends DebugInfoTest {
return new TestClass();
}
public static TestClass buildObjectStack() {
return new TestClass();
}
boolean storeToStack;
private VirtualObject[] compileBuildObject(TestAssembler asm, JavaValue[] values) {
TestClass template = new TestClass();
ArrayList<VirtualObject> vobjs = new ArrayList<>();
@ -135,7 +141,11 @@ public class VirtualObjectDebugInfoTest extends DebugInfoTest {
} else if (template.arrayField[i] instanceof String) {
String value = (String) template.arrayField[i];
Register reg = asm.emitLoadPointer((HotSpotConstant) constantReflection.forString(value));
arrayContent[i] = reg.asValue(asm.getValueKind(JavaKind.Object));
if (storeToStack) {
arrayContent[i] = asm.emitPointerToStack(reg);
} else {
arrayContent[i] = reg.asValue(asm.getValueKind(JavaKind.Object));
}
} else {
Assert.fail("unexpected value");
}
@ -174,6 +184,13 @@ public class VirtualObjectDebugInfoTest extends DebugInfoTest {
@Test
public void testBuildObject() {
storeToStack = false;
test(this::compileBuildObject, getMethod("buildObject"), 7, JavaKind.Object);
}
@Test
public void testBuildObjectStack() {
storeToStack = true;
test(this::compileBuildObject, getMethod("buildObjectStack"), 7, JavaKind.Object);
}
}