changeset 12605:9e0a7b1cbdef

8171173: EXCEPTION_ACCESS_VIOLATION running VirtualObjectDebugInfoTest.java Reviewed-by: kvn
author never
date Tue, 24 Jan 2017 08:51:07 +0000
parents f7c895cf8b14
children 84632483ee9d
files test/compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/DebugInfoTest.java test/compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/TestAssembler.java test/compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/VirtualObjectDebugInfoTest.java
diffstat 3 files changed, 60 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/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/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<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);
--- a/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/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) {
--- a/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/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<VirtualObject> 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);
+    }
 }