29
30 import java.lang.annotation.Annotation;
31 import java.lang.reflect.Executable;
32 import java.lang.reflect.InvocationTargetException;
33 import java.lang.reflect.Method;
34 import java.lang.reflect.Modifier;
35 import java.lang.reflect.Type;
36 import java.util.HashMap;
37 import java.util.Map;
38
39 import jdk.vm.ci.common.JVMCIError;
40 import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.Option;
41 import jdk.vm.ci.meta.Constant;
42 import jdk.vm.ci.meta.ConstantPool;
43 import jdk.vm.ci.meta.DefaultProfilingInfo;
44 import jdk.vm.ci.meta.ExceptionHandler;
45 import jdk.vm.ci.meta.JavaConstant;
46 import jdk.vm.ci.meta.JavaMethod;
47 import jdk.vm.ci.meta.JavaType;
48 import jdk.vm.ci.meta.LineNumberTable;
49 import jdk.vm.ci.meta.LineNumberTableImpl;
50 import jdk.vm.ci.meta.Local;
51 import jdk.vm.ci.meta.LocalImpl;
52 import jdk.vm.ci.meta.LocalVariableTable;
53 import jdk.vm.ci.meta.LocalVariableTableImpl;
54 import jdk.vm.ci.meta.ModifiersProvider;
55 import jdk.vm.ci.meta.ProfilingInfo;
56 import jdk.vm.ci.meta.ResolvedJavaMethod;
57 import jdk.vm.ci.meta.ResolvedJavaType;
58 import jdk.vm.ci.meta.Signature;
59 import jdk.vm.ci.meta.SpeculationLog;
60 import jdk.vm.ci.meta.TriState;
61
62 /**
63 * Implementation of {@link JavaMethod} for resolved HotSpot methods.
64 */
65 final class HotSpotResolvedJavaMethodImpl extends HotSpotMethod implements HotSpotResolvedJavaMethod, HotSpotProxified, MetaspaceWrapperObject {
66
67 /**
68 * Reference to metaspace Method object.
69 */
70 private final long metaspaceMethod;
71
72 private final HotSpotResolvedObjectTypeImpl holder;
73 private final HotSpotConstantPool constantPool;
74 private final HotSpotSignature signature;
75 private HotSpotMethodData methodData;
76 private byte[] code;
77 private Executable toJavaCache;
78
79 /**
80 * Gets the holder of a HotSpot metaspace method native object.
81 *
82 * @param metaspaceMethod a metaspace Method object
83 * @return the {@link ResolvedJavaType} corresponding to the holder of the
84 * {@code metaspaceMethod}
85 */
554 public LineNumberTable getLineNumberTable() {
555 final boolean hasLineNumberTable = (getConstMethodFlags() & config().constMethodHasLineNumberTable) != 0;
556 if (!hasLineNumberTable) {
557 return null;
558 }
559
560 long[] values = compilerToVM().getLineNumberTable(this);
561 if (values == null || values.length == 0) {
562 // Empty table so treat is as non-existent
563 return null;
564 }
565 assert values.length % 2 == 0;
566 int[] bci = new int[values.length / 2];
567 int[] line = new int[values.length / 2];
568
569 for (int i = 0; i < values.length / 2; i++) {
570 bci[i] = (int) values[i * 2];
571 line[i] = (int) values[i * 2 + 1];
572 }
573
574 return new LineNumberTableImpl(line, bci);
575 }
576
577 @Override
578 public LocalVariableTable getLocalVariableTable() {
579 final boolean hasLocalVariableTable = (getConstMethodFlags() & config().constMethodHasLocalVariableTable) != 0;
580 if (!hasLocalVariableTable) {
581 return null;
582 }
583
584 HotSpotVMConfig config = config();
585 long localVariableTableElement = compilerToVM().getLocalVariableTableStart(this);
586 final int localVariableTableLength = compilerToVM().getLocalVariableTableLength(this);
587 Local[] locals = new Local[localVariableTableLength];
588
589 for (int i = 0; i < localVariableTableLength; i++) {
590 final int startBci = UNSAFE.getChar(localVariableTableElement + config.localVariableTableElementStartBciOffset);
591 final int endBci = startBci + UNSAFE.getChar(localVariableTableElement + config.localVariableTableElementLengthOffset);
592 final int nameCpIndex = UNSAFE.getChar(localVariableTableElement + config.localVariableTableElementNameCpIndexOffset);
593 final int typeCpIndex = UNSAFE.getChar(localVariableTableElement + config.localVariableTableElementDescriptorCpIndexOffset);
594 final int slot = UNSAFE.getChar(localVariableTableElement + config.localVariableTableElementSlotOffset);
595
596 String localName = getConstantPool().lookupUtf8(nameCpIndex);
597 String localType = getConstantPool().lookupUtf8(typeCpIndex);
598
599 locals[i] = new LocalImpl(localName, runtime().lookupType(localType, holder, false), startBci, endBci, slot);
600
601 // Go to the next LocalVariableTableElement
602 localVariableTableElement += config.localVariableTableElementSize;
603 }
604
605 return new LocalVariableTableImpl(locals);
606 }
607
608 /**
609 * Returns the offset of this method into the v-table. The method must have a v-table entry as
610 * indicated by {@link #isInVirtualMethodTable(ResolvedJavaType)}, otherwise an exception is
611 * thrown.
612 *
613 * @return the offset of this method into the v-table
614 */
615 public int vtableEntryOffset(ResolvedJavaType resolved) {
616 if (!isInVirtualMethodTable(resolved)) {
617 throw new JVMCIError("%s does not have a vtable entry in type %s", this, resolved);
618 }
619 HotSpotVMConfig config = config();
620 final int vtableIndex = getVtableIndex((HotSpotResolvedObjectTypeImpl) resolved);
621 return config.klassVtableStartOffset + vtableIndex * config.vtableEntrySize + config.vtableEntryMethodOffset;
622 }
623
624 @Override
625 public boolean isInVirtualMethodTable(ResolvedJavaType resolved) {
|
29
30 import java.lang.annotation.Annotation;
31 import java.lang.reflect.Executable;
32 import java.lang.reflect.InvocationTargetException;
33 import java.lang.reflect.Method;
34 import java.lang.reflect.Modifier;
35 import java.lang.reflect.Type;
36 import java.util.HashMap;
37 import java.util.Map;
38
39 import jdk.vm.ci.common.JVMCIError;
40 import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.Option;
41 import jdk.vm.ci.meta.Constant;
42 import jdk.vm.ci.meta.ConstantPool;
43 import jdk.vm.ci.meta.DefaultProfilingInfo;
44 import jdk.vm.ci.meta.ExceptionHandler;
45 import jdk.vm.ci.meta.JavaConstant;
46 import jdk.vm.ci.meta.JavaMethod;
47 import jdk.vm.ci.meta.JavaType;
48 import jdk.vm.ci.meta.LineNumberTable;
49 import jdk.vm.ci.meta.Local;
50 import jdk.vm.ci.meta.LocalVariableTable;
51 import jdk.vm.ci.meta.ModifiersProvider;
52 import jdk.vm.ci.meta.ProfilingInfo;
53 import jdk.vm.ci.meta.ResolvedJavaMethod;
54 import jdk.vm.ci.meta.ResolvedJavaType;
55 import jdk.vm.ci.meta.Signature;
56 import jdk.vm.ci.meta.SpeculationLog;
57 import jdk.vm.ci.meta.TriState;
58
59 /**
60 * Implementation of {@link JavaMethod} for resolved HotSpot methods.
61 */
62 final class HotSpotResolvedJavaMethodImpl extends HotSpotMethod implements HotSpotResolvedJavaMethod, MetaspaceWrapperObject {
63
64 /**
65 * Reference to metaspace Method object.
66 */
67 private final long metaspaceMethod;
68
69 private final HotSpotResolvedObjectTypeImpl holder;
70 private final HotSpotConstantPool constantPool;
71 private final HotSpotSignature signature;
72 private HotSpotMethodData methodData;
73 private byte[] code;
74 private Executable toJavaCache;
75
76 /**
77 * Gets the holder of a HotSpot metaspace method native object.
78 *
79 * @param metaspaceMethod a metaspace Method object
80 * @return the {@link ResolvedJavaType} corresponding to the holder of the
81 * {@code metaspaceMethod}
82 */
551 public LineNumberTable getLineNumberTable() {
552 final boolean hasLineNumberTable = (getConstMethodFlags() & config().constMethodHasLineNumberTable) != 0;
553 if (!hasLineNumberTable) {
554 return null;
555 }
556
557 long[] values = compilerToVM().getLineNumberTable(this);
558 if (values == null || values.length == 0) {
559 // Empty table so treat is as non-existent
560 return null;
561 }
562 assert values.length % 2 == 0;
563 int[] bci = new int[values.length / 2];
564 int[] line = new int[values.length / 2];
565
566 for (int i = 0; i < values.length / 2; i++) {
567 bci[i] = (int) values[i * 2];
568 line[i] = (int) values[i * 2 + 1];
569 }
570
571 return new LineNumberTable(line, bci);
572 }
573
574 @Override
575 public LocalVariableTable getLocalVariableTable() {
576 final boolean hasLocalVariableTable = (getConstMethodFlags() & config().constMethodHasLocalVariableTable) != 0;
577 if (!hasLocalVariableTable) {
578 return null;
579 }
580
581 HotSpotVMConfig config = config();
582 long localVariableTableElement = compilerToVM().getLocalVariableTableStart(this);
583 final int localVariableTableLength = compilerToVM().getLocalVariableTableLength(this);
584 Local[] locals = new Local[localVariableTableLength];
585
586 for (int i = 0; i < localVariableTableLength; i++) {
587 final int startBci = UNSAFE.getChar(localVariableTableElement + config.localVariableTableElementStartBciOffset);
588 final int endBci = startBci + UNSAFE.getChar(localVariableTableElement + config.localVariableTableElementLengthOffset);
589 final int nameCpIndex = UNSAFE.getChar(localVariableTableElement + config.localVariableTableElementNameCpIndexOffset);
590 final int typeCpIndex = UNSAFE.getChar(localVariableTableElement + config.localVariableTableElementDescriptorCpIndexOffset);
591 final int slot = UNSAFE.getChar(localVariableTableElement + config.localVariableTableElementSlotOffset);
592
593 String localName = getConstantPool().lookupUtf8(nameCpIndex);
594 String localType = getConstantPool().lookupUtf8(typeCpIndex);
595
596 locals[i] = new Local(localName, runtime().lookupType(localType, holder, false), startBci, endBci, slot);
597
598 // Go to the next LocalVariableTableElement
599 localVariableTableElement += config.localVariableTableElementSize;
600 }
601
602 return new LocalVariableTable(locals);
603 }
604
605 /**
606 * Returns the offset of this method into the v-table. The method must have a v-table entry as
607 * indicated by {@link #isInVirtualMethodTable(ResolvedJavaType)}, otherwise an exception is
608 * thrown.
609 *
610 * @return the offset of this method into the v-table
611 */
612 public int vtableEntryOffset(ResolvedJavaType resolved) {
613 if (!isInVirtualMethodTable(resolved)) {
614 throw new JVMCIError("%s does not have a vtable entry in type %s", this, resolved);
615 }
616 HotSpotVMConfig config = config();
617 final int vtableIndex = getVtableIndex((HotSpotResolvedObjectTypeImpl) resolved);
618 return config.klassVtableStartOffset + vtableIndex * config.vtableEntrySize + config.vtableEntryMethodOffset;
619 }
620
621 @Override
622 public boolean isInVirtualMethodTable(ResolvedJavaType resolved) {
|