test/hotspot/jtreg/compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/DebugInfoTest.java
changeset 47216 71c04702a3d5
parent 43478 72039e58b2a8
child 58851 f1e6442241ca
equal deleted inserted replaced
47215:4ebc2e2fb97c 47216:71c04702a3d5
       
     1 /*
       
     2  * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  */
       
    23 package jdk.vm.ci.code.test;
       
    24 
       
    25 import jdk.vm.ci.code.BytecodeFrame;
       
    26 import jdk.vm.ci.code.DebugInfo;
       
    27 import jdk.vm.ci.code.Location;
       
    28 import jdk.vm.ci.code.RegisterValue;
       
    29 import jdk.vm.ci.code.StackSlot;
       
    30 import jdk.vm.ci.code.VirtualObject;
       
    31 import jdk.vm.ci.hotspot.HotSpotReferenceMap;
       
    32 import jdk.vm.ci.meta.JavaKind;
       
    33 import jdk.vm.ci.meta.JavaValue;
       
    34 import jdk.vm.ci.meta.ResolvedJavaMethod;
       
    35 
       
    36 import java.lang.reflect.Method;
       
    37 import java.util.ArrayList;
       
    38 import java.util.Arrays;
       
    39 import java.util.List;
       
    40 
       
    41 /**
       
    42  * Test code installation with debug information.
       
    43  */
       
    44 public class DebugInfoTest extends CodeInstallationTest {
       
    45 
       
    46     protected interface DebugInfoCompiler {
       
    47 
       
    48         VirtualObject[] compile(TestAssembler asm, JavaValue[] frameValues);
       
    49     }
       
    50 
       
    51     protected void test(DebugInfoCompiler compiler, Method method, int bci, JavaKind... slotKinds) {
       
    52         test(compiler, method, bci, new Location[0], new Location[0], new int[0], slotKinds);
       
    53     }
       
    54 
       
    55     protected void test(DebugInfoCompiler compiler, Method method, int bci, Location[] objects, Location[] derivedBase, int[] sizeInBytes, JavaKind... slotKinds) {
       
    56         ResolvedJavaMethod resolvedMethod = metaAccess.lookupJavaMethod(method);
       
    57 
       
    58         int numLocals = resolvedMethod.getMaxLocals();
       
    59         int numStack = slotKinds.length - numLocals;
       
    60         JavaValue[] values = new JavaValue[slotKinds.length];
       
    61         test(asm -> {
       
    62             /*
       
    63              * Ensure that any objects mentioned in the VirtualObjects are also in the OopMap.
       
    64              */
       
    65             List<Location> newLocations = new ArrayList<Location>(Arrays.asList(objects));
       
    66             List<Location> newDerived = new ArrayList<Location>(Arrays.asList(derivedBase));
       
    67             int[] newSizeInBytes = sizeInBytes;
       
    68             VirtualObject[] vobjs = compiler.compile(asm, values);
       
    69             if (vobjs != null) {
       
    70                 for (VirtualObject obj : vobjs) {
       
    71                     JavaValue[] objValues = obj.getValues();
       
    72                     for (int i = 0; i < objValues.length; i++) {
       
    73                             if (obj.getSlotKind(i) == JavaKind.Object) {
       
    74                                     Location oopLocation = null;
       
    75                                     int bytes = -1;
       
    76                                     if (objValues[i] instanceof RegisterValue) {
       
    77                                             RegisterValue reg = (RegisterValue) objValues[i];
       
    78                                             oopLocation = Location.register(reg.getRegister());
       
    79                                             bytes = reg.getValueKind().getPlatformKind().getSizeInBytes();
       
    80                                     } else if (objValues[i] instanceof StackSlot) {
       
    81                                             StackSlot slot = (StackSlot) objValues[i];
       
    82                                             oopLocation = Location.stack(asm.getOffset(slot));
       
    83                                             bytes = slot.getValueKind().getPlatformKind().getSizeInBytes();
       
    84                                     }
       
    85                                     if (oopLocation != null && !newLocations.contains(oopLocation)) {
       
    86                                             newLocations.add(oopLocation);
       
    87                                             newDerived.add(null);
       
    88                                             newSizeInBytes = Arrays.copyOf(newSizeInBytes, newSizeInBytes.length + 1);
       
    89                                         newSizeInBytes[newSizeInBytes.length - 1] = bytes;
       
    90                                 }
       
    91                         }
       
    92                     }
       
    93                 }
       
    94             }
       
    95 
       
    96             BytecodeFrame frame = new BytecodeFrame(null, resolvedMethod, bci, false, false, values, slotKinds, numLocals, numStack, 0);
       
    97             DebugInfo info = new DebugInfo(frame, vobjs);
       
    98             info.setReferenceMap(new HotSpotReferenceMap(newLocations.toArray(new Location[0]), newDerived.toArray(new Location[0]), newSizeInBytes, 8));
       
    99 
       
   100             asm.emitTrap(info);
       
   101         }, method);
       
   102     }
       
   103 }