# HG changeset patch # User never # Date 1485247867 0 # Node ID 72039e58b2a849a81394327a3e529d0a171aed70 # Parent 492dd6b958a28f4830c3ceb65eb35faf6d562aba 8171173: EXCEPTION_ACCESS_VIOLATION running VirtualObjectDebugInfoTest.java Reviewed-by: kvn diff -r 492dd6b958a2 -r 72039e58b2a8 hotspot/test/compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/DebugInfoTest.java --- a/hotspot/test/compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/DebugInfoTest.java Mon Jan 23 23:01:32 2017 +0000 +++ b/hotspot/test/compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/DebugInfoTest.java Tue Jan 24 08:51:07 2017 +0000 @@ -25,6 +25,8 @@ 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.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 @@ 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 newLocations = new ArrayList(Arrays.asList(objects)); + List newDerived = new ArrayList(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); diff -r 492dd6b958a2 -r 72039e58b2a8 hotspot/test/compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/TestAssembler.java --- a/hotspot/test/compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/TestAssembler.java Mon Jan 23 23:01:32 2017 +0000 +++ b/hotspot/test/compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/TestAssembler.java Tue Jan 24 08:51:07 2017 +0000 @@ -256,6 +256,10 @@ 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) { diff -r 492dd6b958a2 -r 72039e58b2a8 hotspot/test/compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/VirtualObjectDebugInfoTest.java --- a/hotspot/test/compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/VirtualObjectDebugInfoTest.java Mon Jan 23 23:01:32 2017 +0000 +++ b/hotspot/test/compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/VirtualObjectDebugInfoTest.java Tue Jan 24 08:51:07 2017 +0000 @@ -103,6 +103,12 @@ return new TestClass(); } + public static TestClass buildObjectStack() { + return new TestClass(); + } + + boolean storeToStack; + private VirtualObject[] compileBuildObject(TestAssembler asm, JavaValue[] values) { TestClass template = new TestClass(); ArrayList vobjs = new ArrayList<>(); @@ -135,7 +141,11 @@ } 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 @@ @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); + } }