annotate graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotConstantPool.java @ 15193:96bb07a5d667

Spit up and move GraalInternalError.
author Josef Eisl <josef.eisl@jku.at>
date Thu, 17 Apr 2014 15:18:41 +0200
parents db4254246f9a
children affef8631cf4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
1 /*
13259
b16fb0b7479b every HotSpotResolvedJavaMethod needs its own constant pool
twisti
parents: 13254
diff changeset
2 * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
4 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
8 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
13 * accompanied this code).
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
14 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
18 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
21 * questions.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
22 */
5548
8872bc0eebdf Renaming hotspot.ri => hotspot.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5541
diff changeset
23 package com.oracle.graal.hotspot.meta;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
24
12559
ae412befde21 read HotSpotVMConfig fields from HotSpot's vmStructs via annotations
twisti
parents: 12431
diff changeset
25 import static com.oracle.graal.graph.UnsafeAccess.*;
9289
261a43921c5e rename: HotSpotGraalRuntime.getInstance() -> graalRuntime()
Doug Simon <doug.simon@oracle.com>
parents: 9108
diff changeset
26 import static com.oracle.graal.hotspot.HotSpotGraalRuntime.*;
261a43921c5e rename: HotSpotGraalRuntime.getInstance() -> graalRuntime()
Doug Simon <doug.simon@oracle.com>
parents: 9108
diff changeset
27
14093
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
28 import java.lang.invoke.*;
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
29
5507
dc71b06d09f8 Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5278
diff changeset
30 import com.oracle.graal.api.meta.*;
9011
23762f2438b6 support for compiling LambdaForm invocations (invokevirtual instructions that were rewritten to invokehandle instructions)
Doug Simon <doug.simon@oracle.com>
parents: 8945
diff changeset
31 import com.oracle.graal.bytecode.*;
15193
96bb07a5d667 Spit up and move GraalInternalError.
Josef Eisl <josef.eisl@jku.at>
parents: 15018
diff changeset
32 import com.oracle.graal.compiler.common.*;
5060
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
33 import com.oracle.graal.hotspot.*;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
34
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
35 /**
5775
2c088af17e59 Removed left over Ri* prefixed identifiers
Doug Simon <doug.simon@oracle.com>
parents: 5554
diff changeset
36 * Implementation of {@link ConstantPool} for HotSpot.
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
37 */
5541
b4c406861c33 More renamings to drop Ri* prefix completely. Deleted graph.BitMap class and replaced with java.util.BitSet.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5534
diff changeset
38 public class HotSpotConstantPool extends CompilerObject implements ConstantPool {
5278
74dfa6f86879 removed last remaining references to vmEntries and vmExits
Lukas Stadler <lukas.stadler@jku.at>
parents: 5061
diff changeset
39
4142
bc8527f3071c Adjust code base to new level of warnings.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 3733
diff changeset
40 private static final long serialVersionUID = -5443206401485234850L;
5278
74dfa6f86879 removed last remaining references to vmEntries and vmExits
Lukas Stadler <lukas.stadler@jku.at>
parents: 5061
diff changeset
41
13259
b16fb0b7479b every HotSpotResolvedJavaMethod needs its own constant pool
twisti
parents: 13254
diff changeset
42 /**
14529
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
43 * Enum of all {@code JVM_CONSTANT} constants used in the VM. This includes the public and
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
44 * internal ones.
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
45 */
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
46 private enum JVM_CONSTANT {
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
47 // @formatter:off
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
48 Utf8(config().jvmConstantUtf8),
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
49 Integer(config().jvmConstantInteger),
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
50 Long(config().jvmConstantLong),
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
51 Float(config().jvmConstantFloat),
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
52 Double(config().jvmConstantDouble),
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
53 Class(config().jvmConstantClass),
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
54 UnresolvedClass(config().jvmConstantUnresolvedClass),
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
55 UnresolvedClassInError(config().jvmConstantUnresolvedClassInError),
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
56 String(config().jvmConstantString),
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
57 Fieldref(config().jvmConstantFieldref),
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
58 MethodRef(config().jvmConstantMethodref),
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
59 InterfaceMethodref(config().jvmConstantInterfaceMethodref),
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
60 NameAndType(config().jvmConstantNameAndType),
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
61 MethodHandle(config().jvmConstantMethodHandle),
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
62 MethodHandleInError(config().jvmConstantMethodHandleInError),
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
63 MethodType(config().jvmConstantMethodType),
14979
5dfaaa91be37 fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
twisti
parents: 14530
diff changeset
64 MethodTypeInError(config().jvmConstantMethodTypeInError),
5dfaaa91be37 fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
twisti
parents: 14530
diff changeset
65 InvokeDynamic(config().jvmConstantInvokeDynamic);
14529
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
66 // @formatter:on
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
67
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
68 private final int value;
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
69
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
70 private JVM_CONSTANT(int value) {
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
71 this.value = value;
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
72 }
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
73
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
74 private static HotSpotVMConfig config() {
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
75 return runtime().getConfig();
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
76 }
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
77
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
78 public static JVM_CONSTANT getEnum(int value) {
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
79 for (JVM_CONSTANT e : values()) {
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
80 if (e.value == value) {
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
81 return e;
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
82 }
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
83 }
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
84 throw GraalInternalError.shouldNotReachHere("unknown enum value " + value);
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
85 }
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
86 }
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
87
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
88 /**
13259
b16fb0b7479b every HotSpotResolvedJavaMethod needs its own constant pool
twisti
parents: 13254
diff changeset
89 * Reference to the C++ ConstantPool object.
b16fb0b7479b every HotSpotResolvedJavaMethod needs its own constant pool
twisti
parents: 13254
diff changeset
90 */
b16fb0b7479b every HotSpotResolvedJavaMethod needs its own constant pool
twisti
parents: 13254
diff changeset
91 private final long metaspaceConstantPool;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
92
13259
b16fb0b7479b every HotSpotResolvedJavaMethod needs its own constant pool
twisti
parents: 13254
diff changeset
93 public HotSpotConstantPool(long metaspaceConstantPool) {
b16fb0b7479b every HotSpotResolvedJavaMethod needs its own constant pool
twisti
parents: 13254
diff changeset
94 this.metaspaceConstantPool = metaspaceConstantPool;
13254
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
95 }
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
96
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
97 /**
14093
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
98 * Gets the holder for this constant pool as {@link HotSpotResolvedObjectType}.
14979
5dfaaa91be37 fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
twisti
parents: 14530
diff changeset
99 *
14093
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
100 * @return holder for this constant pool
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
101 */
14117
2b2f0022900f removed unnecessary lookupKlassByName method
Doug Simon <doug.simon@oracle.com>
parents: 14093
diff changeset
102 private HotSpotResolvedObjectType getHolder() {
14093
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
103 final long metaspaceKlass = unsafe.getAddress(metaspaceConstantPool + runtime().getConfig().constantPoolHolderOffset);
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
104 return (HotSpotResolvedObjectType) HotSpotResolvedObjectType.fromMetaspaceKlass(metaspaceKlass);
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
105 }
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
106
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
107 /**
14052
361acb279104 moved to-constant-pool-index conversion up to Java
twisti
parents: 13261
diff changeset
108 * Converts a raw index from the bytecodes to a constant pool index by adding a
361acb279104 moved to-constant-pool-index conversion up to Java
twisti
parents: 13261
diff changeset
109 * {@link HotSpotVMConfig#constantPoolCpCacheIndexTag constant}.
14979
5dfaaa91be37 fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
twisti
parents: 14530
diff changeset
110 *
14052
361acb279104 moved to-constant-pool-index conversion up to Java
twisti
parents: 13261
diff changeset
111 * @param rawIndex index from the bytecode
361acb279104 moved to-constant-pool-index conversion up to Java
twisti
parents: 13261
diff changeset
112 * @param opcode bytecode to convert the index for
361acb279104 moved to-constant-pool-index conversion up to Java
twisti
parents: 13261
diff changeset
113 * @return constant pool index
361acb279104 moved to-constant-pool-index conversion up to Java
twisti
parents: 13261
diff changeset
114 */
361acb279104 moved to-constant-pool-index conversion up to Java
twisti
parents: 13261
diff changeset
115 private static int toConstantPoolIndex(int rawIndex, int opcode) {
361acb279104 moved to-constant-pool-index conversion up to Java
twisti
parents: 13261
diff changeset
116 int index;
361acb279104 moved to-constant-pool-index conversion up to Java
twisti
parents: 13261
diff changeset
117 if (opcode == Bytecodes.INVOKEDYNAMIC) {
361acb279104 moved to-constant-pool-index conversion up to Java
twisti
parents: 13261
diff changeset
118 index = rawIndex;
361acb279104 moved to-constant-pool-index conversion up to Java
twisti
parents: 13261
diff changeset
119 // See: ConstantPool::is_invokedynamic_index
361acb279104 moved to-constant-pool-index conversion up to Java
twisti
parents: 13261
diff changeset
120 assert index < 0 : "not an invokedynamic constant pool index " + index;
361acb279104 moved to-constant-pool-index conversion up to Java
twisti
parents: 13261
diff changeset
121 } else {
361acb279104 moved to-constant-pool-index conversion up to Java
twisti
parents: 13261
diff changeset
122 assert opcode == Bytecodes.GETFIELD || opcode == Bytecodes.PUTFIELD || opcode == Bytecodes.GETSTATIC || opcode == Bytecodes.PUTSTATIC || opcode == Bytecodes.INVOKEINTERFACE ||
361acb279104 moved to-constant-pool-index conversion up to Java
twisti
parents: 13261
diff changeset
123 opcode == Bytecodes.INVOKEVIRTUAL || opcode == Bytecodes.INVOKESPECIAL || opcode == Bytecodes.INVOKESTATIC : "unexpected invoke opcode " + Bytecodes.nameOf(opcode);
361acb279104 moved to-constant-pool-index conversion up to Java
twisti
parents: 13261
diff changeset
124 index = rawIndex + runtime().getConfig().constantPoolCpCacheIndexTag;
361acb279104 moved to-constant-pool-index conversion up to Java
twisti
parents: 13261
diff changeset
125 }
361acb279104 moved to-constant-pool-index conversion up to Java
twisti
parents: 13261
diff changeset
126 return index;
361acb279104 moved to-constant-pool-index conversion up to Java
twisti
parents: 13261
diff changeset
127 }
361acb279104 moved to-constant-pool-index conversion up to Java
twisti
parents: 13261
diff changeset
128
361acb279104 moved to-constant-pool-index conversion up to Java
twisti
parents: 13261
diff changeset
129 /**
14979
5dfaaa91be37 fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
twisti
parents: 14530
diff changeset
130 * Decode a constant pool cache index to a constant pool index.
5dfaaa91be37 fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
twisti
parents: 14530
diff changeset
131 *
5dfaaa91be37 fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
twisti
parents: 14530
diff changeset
132 * See {@code ConstantPool::decode_cpcache_index}.
5dfaaa91be37 fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
twisti
parents: 14530
diff changeset
133 *
5dfaaa91be37 fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
twisti
parents: 14530
diff changeset
134 * @param index constant pool cache index
5dfaaa91be37 fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
twisti
parents: 14530
diff changeset
135 * @return decoded index
5dfaaa91be37 fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
twisti
parents: 14530
diff changeset
136 */
5dfaaa91be37 fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
twisti
parents: 14530
diff changeset
137 private static int decodeConstantPoolCacheIndex(int index) {
5dfaaa91be37 fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
twisti
parents: 14530
diff changeset
138 if (isInvokedynamicIndex(index)) {
5dfaaa91be37 fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
twisti
parents: 14530
diff changeset
139 return decodeInvokedynamicIndex(index);
5dfaaa91be37 fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
twisti
parents: 14530
diff changeset
140 } else {
5dfaaa91be37 fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
twisti
parents: 14530
diff changeset
141 return index - runtime().getConfig().constantPoolCpCacheIndexTag;
5dfaaa91be37 fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
twisti
parents: 14530
diff changeset
142 }
5dfaaa91be37 fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
twisti
parents: 14530
diff changeset
143 }
5dfaaa91be37 fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
twisti
parents: 14530
diff changeset
144
5dfaaa91be37 fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
twisti
parents: 14530
diff changeset
145 /**
5dfaaa91be37 fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
twisti
parents: 14530
diff changeset
146 * See {@code ConstantPool::is_invokedynamic_index}.
5dfaaa91be37 fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
twisti
parents: 14530
diff changeset
147 */
5dfaaa91be37 fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
twisti
parents: 14530
diff changeset
148 private static boolean isInvokedynamicIndex(int index) {
5dfaaa91be37 fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
twisti
parents: 14530
diff changeset
149 return index < 0;
5dfaaa91be37 fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
twisti
parents: 14530
diff changeset
150 }
5dfaaa91be37 fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
twisti
parents: 14530
diff changeset
151
5dfaaa91be37 fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
twisti
parents: 14530
diff changeset
152 /**
5dfaaa91be37 fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
twisti
parents: 14530
diff changeset
153 * See {@code ConstantPool::decode_invokedynamic_index}.
5dfaaa91be37 fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
twisti
parents: 14530
diff changeset
154 */
5dfaaa91be37 fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
twisti
parents: 14530
diff changeset
155 private static int decodeInvokedynamicIndex(int i) {
5dfaaa91be37 fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
twisti
parents: 14530
diff changeset
156 assert isInvokedynamicIndex(i) : i;
5dfaaa91be37 fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
twisti
parents: 14530
diff changeset
157 return ~i;
5dfaaa91be37 fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
twisti
parents: 14530
diff changeset
158 }
5dfaaa91be37 fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
twisti
parents: 14530
diff changeset
159
5dfaaa91be37 fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
twisti
parents: 14530
diff changeset
160 /**
14093
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
161 * Gets the constant pool tag at index {@code index}.
14979
5dfaaa91be37 fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
twisti
parents: 14530
diff changeset
162 *
13254
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
163 * @param index constant pool index
14093
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
164 * @return constant pool tag
13254
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
165 */
14529
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
166 private JVM_CONSTANT getTagAt(int index) {
13254
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
167 assertBounds(index);
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
168 HotSpotVMConfig config = runtime().getConfig();
14529
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
169 final long metaspaceConstantPoolTags = unsafe.getAddress(metaspaceConstantPool + config.constantPoolTagsOffset);
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
170 final int tag = unsafe.getByteVolatile(null, metaspaceConstantPoolTags + config.arrayU1DataOffset + index);
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
171 return JVM_CONSTANT.getEnum(tag);
13254
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
172 }
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
173
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
174 /**
14093
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
175 * Gets the constant pool entry at index {@code index}.
14979
5dfaaa91be37 fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
twisti
parents: 14530
diff changeset
176 *
13254
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
177 * @param index constant pool index
14093
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
178 * @return constant pool entry
13254
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
179 */
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
180 private long getEntryAt(int index) {
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
181 assertBounds(index);
14530
d87b84dade7d moved CompilerToVM.loadReferencedTypeInPool logic into Java
twisti
parents: 14529
diff changeset
182 return unsafe.getAddress(metaspaceConstantPool + runtime().getConfig().constantPoolSize + index * runtime().getTarget().wordSize);
13254
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
183 }
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
184
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
185 /**
14093
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
186 * Gets the integer constant pool entry at index {@code index}.
14979
5dfaaa91be37 fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
twisti
parents: 14530
diff changeset
187 *
13254
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
188 * @param index constant pool index
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
189 * @return integer constant pool entry at index
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
190 */
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
191 private int getIntAt(int index) {
14529
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
192 assertTag(index, JVM_CONSTANT.Integer);
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
193 return unsafe.getInt(metaspaceConstantPool + runtime().getConfig().constantPoolSize + index * runtime().getTarget().wordSize);
13254
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
194 }
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
195
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
196 /**
14093
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
197 * Gets the long constant pool entry at index {@code index}.
14979
5dfaaa91be37 fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
twisti
parents: 14530
diff changeset
198 *
13254
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
199 * @param index constant pool index
14093
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
200 * @return long constant pool entry
13254
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
201 */
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
202 private long getLongAt(int index) {
14529
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
203 assertTag(index, JVM_CONSTANT.Long);
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
204 return unsafe.getLong(metaspaceConstantPool + runtime().getConfig().constantPoolSize + index * runtime().getTarget().wordSize);
13254
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
205 }
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
206
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
207 /**
14093
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
208 * Gets the float constant pool entry at index {@code index}.
14979
5dfaaa91be37 fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
twisti
parents: 14530
diff changeset
209 *
13254
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
210 * @param index constant pool index
14093
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
211 * @return float constant pool entry
13254
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
212 */
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
213 private float getFloatAt(int index) {
14529
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
214 assertTag(index, JVM_CONSTANT.Float);
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
215 return unsafe.getFloat(metaspaceConstantPool + runtime().getConfig().constantPoolSize + index * runtime().getTarget().wordSize);
13254
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
216 }
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
217
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
218 /**
14093
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
219 * Gets the double constant pool entry at index {@code index}.
14979
5dfaaa91be37 fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
twisti
parents: 14530
diff changeset
220 *
13254
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
221 * @param index constant pool index
14093
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
222 * @return float constant pool entry
13254
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
223 */
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
224 private double getDoubleAt(int index) {
14529
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
225 assertTag(index, JVM_CONSTANT.Double);
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
226 return unsafe.getDouble(metaspaceConstantPool + runtime().getConfig().constantPoolSize + index * runtime().getTarget().wordSize);
13254
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
227 }
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
228
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
229 /**
14093
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
230 * Gets the {@code JVM_CONSTANT_NameAndType} constant pool entry at index {@code index}.
14979
5dfaaa91be37 fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
twisti
parents: 14530
diff changeset
231 *
14093
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
232 * @param index constant pool index
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
233 * @return {@code JVM_CONSTANT_NameAndType} constant pool entry
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
234 */
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
235 private int getNameAndTypeAt(int index) {
14529
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
236 assertTag(index, JVM_CONSTANT.NameAndType);
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
237 return unsafe.getInt(metaspaceConstantPool + runtime().getConfig().constantPoolSize + index * runtime().getTarget().wordSize);
14093
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
238 }
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
239
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
240 /**
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
241 * Gets the {@code JVM_CONSTANT_NameAndType} reference index constant pool entry at index
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
242 * {@code index}.
14979
5dfaaa91be37 fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
twisti
parents: 14530
diff changeset
243 *
14093
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
244 * @param index constant pool index
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
245 * @return {@code JVM_CONSTANT_NameAndType} reference constant pool entry
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
246 */
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
247 private int getNameAndTypeRefIndexAt(int index) {
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
248 return runtime().getCompilerToVM().lookupNameAndTypeRefIndexInPool(metaspaceConstantPool, index);
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
249 }
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
250
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
251 /**
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
252 * Gets the name of a {@code JVM_CONSTANT_NameAndType} constant pool entry at index
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
253 * {@code index}.
14979
5dfaaa91be37 fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
twisti
parents: 14530
diff changeset
254 *
14093
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
255 * @param index constant pool index
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
256 * @return name as {@link String}
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
257 */
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
258 private String getNameRefAt(int index) {
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
259 final long name = runtime().getCompilerToVM().lookupNameRefInPool(metaspaceConstantPool, index);
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
260 HotSpotSymbol symbol = new HotSpotSymbol(name);
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
261 return symbol.asString();
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
262 }
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
263
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
264 /**
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
265 * Gets the name reference index of a {@code JVM_CONSTANT_NameAndType} constant pool entry at
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
266 * index {@code index}.
14979
5dfaaa91be37 fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
twisti
parents: 14530
diff changeset
267 *
14093
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
268 * @param index constant pool index
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
269 * @return name reference index
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
270 */
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
271 private int getNameRefIndexAt(int index) {
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
272 final int refIndex = getNameAndTypeAt(index);
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
273 // name ref index is in the low 16-bits.
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
274 return refIndex & 0xFFFF;
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
275 }
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
276
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
277 /**
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
278 * Gets the signature of a {@code JVM_CONSTANT_NameAndType} constant pool entry at index
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
279 * {@code index}.
14979
5dfaaa91be37 fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
twisti
parents: 14530
diff changeset
280 *
14093
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
281 * @param index constant pool index
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
282 * @return signature as {@link String}
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
283 */
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
284 private String getSignatureRefAt(int index) {
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
285 final long name = runtime().getCompilerToVM().lookupSignatureRefInPool(metaspaceConstantPool, index);
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
286 HotSpotSymbol symbol = new HotSpotSymbol(name);
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
287 return symbol.asString();
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
288 }
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
289
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
290 /**
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
291 * Gets the signature reference index of a {@code JVM_CONSTANT_NameAndType} constant pool entry
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
292 * at index {@code index}.
14979
5dfaaa91be37 fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
twisti
parents: 14530
diff changeset
293 *
14093
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
294 * @param index constant pool index
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
295 * @return signature reference index
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
296 */
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
297 private int getSignatureRefIndexAt(int index) {
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
298 final int refIndex = getNameAndTypeAt(index);
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
299 // signature ref index is in the high 16-bits.
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
300 return refIndex >>> 16;
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
301 }
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
302
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
303 /**
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
304 * Gets the klass reference index constant pool entry at index {@code index}.
14979
5dfaaa91be37 fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
twisti
parents: 14530
diff changeset
305 *
14093
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
306 * @param index constant pool index
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
307 * @return klass reference index
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
308 */
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
309 private int getKlassRefIndexAt(int index) {
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
310 return runtime().getCompilerToVM().lookupKlassRefIndexInPool(metaspaceConstantPool, index);
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
311 }
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
312
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
313 /**
14530
d87b84dade7d moved CompilerToVM.loadReferencedTypeInPool logic into Java
twisti
parents: 14529
diff changeset
314 * Gets the uncached klass reference index constant pool entry at index {@code index}. See:
d87b84dade7d moved CompilerToVM.loadReferencedTypeInPool logic into Java
twisti
parents: 14529
diff changeset
315 * {@code ConstantPool::uncached_klass_ref_index_at}.
14979
5dfaaa91be37 fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
twisti
parents: 14530
diff changeset
316 *
14530
d87b84dade7d moved CompilerToVM.loadReferencedTypeInPool logic into Java
twisti
parents: 14529
diff changeset
317 * @param index constant pool index
d87b84dade7d moved CompilerToVM.loadReferencedTypeInPool logic into Java
twisti
parents: 14529
diff changeset
318 * @return klass reference index
d87b84dade7d moved CompilerToVM.loadReferencedTypeInPool logic into Java
twisti
parents: 14529
diff changeset
319 */
d87b84dade7d moved CompilerToVM.loadReferencedTypeInPool logic into Java
twisti
parents: 14529
diff changeset
320 private int getUncachedKlassRefIndexAt(int index) {
d87b84dade7d moved CompilerToVM.loadReferencedTypeInPool logic into Java
twisti
parents: 14529
diff changeset
321 assert getTagAt(index) == JVM_CONSTANT.Fieldref || getTagAt(index) == JVM_CONSTANT.MethodRef || getTagAt(index) == JVM_CONSTANT.InterfaceMethodref;
d87b84dade7d moved CompilerToVM.loadReferencedTypeInPool logic into Java
twisti
parents: 14529
diff changeset
322 final int refIndex = unsafe.getInt(metaspaceConstantPool + runtime().getConfig().constantPoolSize + index * runtime().getTarget().wordSize);
d87b84dade7d moved CompilerToVM.loadReferencedTypeInPool logic into Java
twisti
parents: 14529
diff changeset
323 // klass ref index is in the low 16-bits.
d87b84dade7d moved CompilerToVM.loadReferencedTypeInPool logic into Java
twisti
parents: 14529
diff changeset
324 return refIndex & 0xFFFF;
d87b84dade7d moved CompilerToVM.loadReferencedTypeInPool logic into Java
twisti
parents: 14529
diff changeset
325 }
d87b84dade7d moved CompilerToVM.loadReferencedTypeInPool logic into Java
twisti
parents: 14529
diff changeset
326
d87b84dade7d moved CompilerToVM.loadReferencedTypeInPool logic into Java
twisti
parents: 14529
diff changeset
327 /**
13254
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
328 * Asserts that the constant pool index {@code index} is in the bounds of the constant pool.
14979
5dfaaa91be37 fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
twisti
parents: 14530
diff changeset
329 *
13254
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
330 * @param index constant pool index
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
331 */
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
332 private void assertBounds(int index) {
13261
0ffe9e4bb364 don't go through VM to create HotSpotResolvedObjectType (part 1)
twisti
parents: 13259
diff changeset
333 assert 0 <= index && index < length() : "index " + index + " not between 0 and " + length();
13254
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
334 }
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
335
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
336 /**
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
337 * Asserts that the constant pool tag at index {@code index} is equal to {@code tag}.
14979
5dfaaa91be37 fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
twisti
parents: 14530
diff changeset
338 *
13254
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
339 * @param index constant pool index
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
340 * @param tag expected tag
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
341 */
14529
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
342 private void assertTag(int index, JVM_CONSTANT tag) {
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
343 assert getTagAt(index) == tag : "constant pool tag at index " + index + " is " + getTagAt(index) + " but expected " + tag;
13254
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
344 }
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
345
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
346 @Override
9108
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents: 9011
diff changeset
347 public int length() {
14529
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
348 return unsafe.getInt(metaspaceConstantPool + runtime().getConfig().constantPoolLengthOffset);
9108
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents: 9011
diff changeset
349 }
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents: 9011
diff changeset
350
b78686983a75 GRAAL-218: add CompileTheWorld functionality
twisti
parents: 9011
diff changeset
351 @Override
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
352 public Object lookupConstant(int cpi) {
7002
74f0207b82f5 fixed bug in bytecode reconstitution
Doug Simon <doug.simon@oracle.com>
parents: 6588
diff changeset
353 assert cpi != 0;
14529
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
354 final JVM_CONSTANT tag = getTagAt(cpi);
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
355 switch (tag) {
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
356 case Integer:
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
357 return Constant.forInt(getIntAt(cpi));
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
358 case Long:
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
359 return Constant.forLong(getLongAt(cpi));
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
360 case Float:
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
361 return Constant.forFloat(getFloatAt(cpi));
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
362 case Double:
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
363 return Constant.forDouble(getDoubleAt(cpi));
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
364 case Class:
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
365 case UnresolvedClass:
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
366 case UnresolvedClassInError:
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
367 final int opcode = -1; // opcode is not used
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
368 return lookupType(cpi, opcode);
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
369 case String:
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
370 Object string = runtime().getCompilerToVM().resolvePossiblyCachedConstantInPool(metaspaceConstantPool, cpi);
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14979
diff changeset
371 return HotSpotObjectConstant.forObject(string);
14529
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
372 case MethodHandle:
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
373 case MethodHandleInError:
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
374 case MethodType:
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
375 case MethodTypeInError:
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
376 Object obj = runtime().getCompilerToVM().resolveConstantInPool(metaspaceConstantPool, cpi);
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14979
diff changeset
377 return HotSpotObjectConstant.forObject(obj);
14529
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
378 default:
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
379 throw GraalInternalError.shouldNotReachHere("unknown constant pool tag " + tag);
13254
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
380 }
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
381 }
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
382
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
383 @Override
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
384 public String lookupUtf8(int cpi) {
14529
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
385 assertTag(cpi, JVM_CONSTANT.Utf8);
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
386 final long metaspaceSymbol = getEntryAt(cpi);
82c3b54d1f08 added HotSpotConstantPool.JVM_CONSTANT enum
twisti
parents: 14117
diff changeset
387 HotSpotSymbol symbol = new HotSpotSymbol(metaspaceSymbol);
13254
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
388 return symbol.asString();
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
389 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
390
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
391 @Override
5541
b4c406861c33 More renamings to drop Ri* prefix completely. Deleted graph.BitMap class and replaced with java.util.BitSet.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5534
diff changeset
392 public Signature lookupSignature(int cpi) {
13254
42aaf7306707 Teach Graal about Symbol and ConstantPool so we can move more logic into Java. We'll see how that ends...
twisti
parents: 12559
diff changeset
393 return new HotSpotSignature(lookupUtf8(cpi));
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
394 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
395
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
396 @Override
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14979
diff changeset
397 public Constant lookupAppendix(int cpi, int opcode) {
9011
23762f2438b6 support for compiling LambdaForm invocations (invokevirtual instructions that were rewritten to invokehandle instructions)
Doug Simon <doug.simon@oracle.com>
parents: 8945
diff changeset
398 assert Bytecodes.isInvoke(opcode);
14052
361acb279104 moved to-constant-pool-index conversion up to Java
twisti
parents: 13261
diff changeset
399 final int index = toConstantPoolIndex(cpi, opcode);
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14979
diff changeset
400 Object result = runtime().getCompilerToVM().lookupAppendixInPool(metaspaceConstantPool, index);
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14979
diff changeset
401 if (result == null) {
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14979
diff changeset
402 return null;
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14979
diff changeset
403 } else {
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14979
diff changeset
404 return HotSpotObjectConstant.forObject(result);
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 14979
diff changeset
405 }
8945
7ef66078d837 add basic invokedynamic support
Andreas Woess <andreas.woess@jku.at>
parents: 7084
diff changeset
406 }
7ef66078d837 add basic invokedynamic support
Andreas Woess <andreas.woess@jku.at>
parents: 7084
diff changeset
407
14069
2f37b0e442fe removed remaining VMToCompiler calls for allocating Graal API objects
Doug Simon <doug.simon@oracle.com>
parents: 14052
diff changeset
408 /**
14093
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
409 * Gets a {@link JavaType} corresponding a given metaspace Klass or a metaspace Symbol depending
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
410 * on the {@link HotSpotVMConfig#compilerToVMKlassTag tag}.
14979
5dfaaa91be37 fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
twisti
parents: 14530
diff changeset
411 *
14093
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
412 * @param metaspacePointer either a metaspace Klass or a metaspace Symbol
14069
2f37b0e442fe removed remaining VMToCompiler calls for allocating Graal API objects
Doug Simon <doug.simon@oracle.com>
parents: 14052
diff changeset
413 */
14093
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
414 private static JavaType getJavaType(final long metaspacePointer) {
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
415 HotSpotVMConfig config = runtime().getConfig();
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
416 if ((metaspacePointer & config.compilerToVMSymbolTag) != 0) {
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
417 final long metaspaceSymbol = metaspacePointer & ~config.compilerToVMSymbolTag;
14069
2f37b0e442fe removed remaining VMToCompiler calls for allocating Graal API objects
Doug Simon <doug.simon@oracle.com>
parents: 14052
diff changeset
418 String name = new HotSpotSymbol(metaspaceSymbol).asString();
2f37b0e442fe removed remaining VMToCompiler calls for allocating Graal API objects
Doug Simon <doug.simon@oracle.com>
parents: 14052
diff changeset
419 return HotSpotUnresolvedJavaType.create(name);
2f37b0e442fe removed remaining VMToCompiler calls for allocating Graal API objects
Doug Simon <doug.simon@oracle.com>
parents: 14052
diff changeset
420 } else {
14093
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
421 assert (metaspacePointer & config.compilerToVMKlassTag) == 0;
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
422 return HotSpotResolvedObjectType.fromMetaspaceKlass(metaspacePointer);
14069
2f37b0e442fe removed remaining VMToCompiler calls for allocating Graal API objects
Doug Simon <doug.simon@oracle.com>
parents: 14052
diff changeset
423 }
2f37b0e442fe removed remaining VMToCompiler calls for allocating Graal API objects
Doug Simon <doug.simon@oracle.com>
parents: 14052
diff changeset
424 }
2f37b0e442fe removed remaining VMToCompiler calls for allocating Graal API objects
Doug Simon <doug.simon@oracle.com>
parents: 14052
diff changeset
425
8945
7ef66078d837 add basic invokedynamic support
Andreas Woess <andreas.woess@jku.at>
parents: 7084
diff changeset
426 @Override
6588
b89b5038ad7e removed _'s from method names in CompilerToVM
Doug Simon <doug.simon@oracle.com>
parents: 5775
diff changeset
427 public JavaMethod lookupMethod(int cpi, int opcode) {
14052
361acb279104 moved to-constant-pool-index conversion up to Java
twisti
parents: 13261
diff changeset
428 final int index = toConstantPoolIndex(cpi, opcode);
14093
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
429 final long metaspaceMethod = runtime().getCompilerToVM().lookupMethodInPool(metaspaceConstantPool, index, (byte) opcode);
14069
2f37b0e442fe removed remaining VMToCompiler calls for allocating Graal API objects
Doug Simon <doug.simon@oracle.com>
parents: 14052
diff changeset
430 if (metaspaceMethod != 0L) {
2f37b0e442fe removed remaining VMToCompiler calls for allocating Graal API objects
Doug Simon <doug.simon@oracle.com>
parents: 14052
diff changeset
431 return HotSpotResolvedJavaMethod.fromMetaspace(metaspaceMethod);
2f37b0e442fe removed remaining VMToCompiler calls for allocating Graal API objects
Doug Simon <doug.simon@oracle.com>
parents: 14052
diff changeset
432 } else {
14093
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
433 // Get the method's name and signature.
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
434 String name = getNameRefAt(index);
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
435 String signature = getSignatureRefAt(index);
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
436 if (opcode == Bytecodes.INVOKEDYNAMIC) {
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
437 JavaType holder = HotSpotResolvedJavaType.fromClass(MethodHandle.class);
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
438 return new HotSpotMethodUnresolved(name, signature, holder);
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
439 } else {
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
440 final int klassIndex = getKlassRefIndexAt(index);
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
441 final long metaspacePointer = runtime().getCompilerToVM().lookupKlassInPool(metaspaceConstantPool, klassIndex);
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
442 JavaType holder = getJavaType(metaspacePointer);
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
443 return new HotSpotMethodUnresolved(name, signature, holder);
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
444 }
14069
2f37b0e442fe removed remaining VMToCompiler calls for allocating Graal API objects
Doug Simon <doug.simon@oracle.com>
parents: 14052
diff changeset
445 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
446 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
447
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
448 @Override
5541
b4c406861c33 More renamings to drop Ri* prefix completely. Deleted graph.BitMap class and replaced with java.util.BitSet.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5534
diff changeset
449 public JavaType lookupType(int cpi, int opcode) {
14093
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
450 final long metaspacePointer = runtime().getCompilerToVM().lookupKlassInPool(metaspaceConstantPool, cpi);
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
451 return getJavaType(metaspacePointer);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
452 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
453
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
454 @Override
5541
b4c406861c33 More renamings to drop Ri* prefix completely. Deleted graph.BitMap class and replaced with java.util.BitSet.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5534
diff changeset
455 public JavaField lookupField(int cpi, int opcode) {
14052
361acb279104 moved to-constant-pool-index conversion up to Java
twisti
parents: 13261
diff changeset
456 final int index = toConstantPoolIndex(cpi, opcode);
14093
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
457 final int nameAndTypeIndex = getNameAndTypeRefIndexAt(index);
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
458 final int nameIndex = getNameRefIndexAt(nameAndTypeIndex);
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
459 String name = lookupUtf8(nameIndex);
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
460 final int typeIndex = getSignatureRefIndexAt(nameAndTypeIndex);
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
461 String typeName = lookupUtf8(typeIndex);
14117
2b2f0022900f removed unnecessary lookupKlassByName method
Doug Simon <doug.simon@oracle.com>
parents: 14093
diff changeset
462 JavaType type = runtime().lookupType(typeName, getHolder(), false);
14093
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
463
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
464 final int holderIndex = getKlassRefIndexAt(index);
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
465 JavaType holder = lookupType(holderIndex, opcode);
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
466
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
467 if (holder instanceof HotSpotResolvedObjectType) {
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
468 long[] info = new long[2];
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
469 long metaspaceKlass;
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
470 try {
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
471 metaspaceKlass = runtime().getCompilerToVM().resolveField(metaspaceConstantPool, index, (byte) opcode, info);
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
472 } catch (Throwable t) {
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
473 /*
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
474 * If there was an exception resolving the field we give up and return an unresolved
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
475 * field.
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
476 */
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
477 return new HotSpotUnresolvedField(holder, name, type);
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
478 }
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
479 HotSpotResolvedObjectType resolvedHolder = (HotSpotResolvedObjectType) HotSpotResolvedObjectType.fromMetaspaceKlass(metaspaceKlass);
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
480 final int flags = (int) info[0];
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
481 final long offset = info[1];
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
482 return resolvedHolder.createField(name, type, offset, flags);
14069
2f37b0e442fe removed remaining VMToCompiler calls for allocating Graal API objects
Doug Simon <doug.simon@oracle.com>
parents: 14052
diff changeset
483 } else {
2f37b0e442fe removed remaining VMToCompiler calls for allocating Graal API objects
Doug Simon <doug.simon@oracle.com>
parents: 14052
diff changeset
484 return new HotSpotUnresolvedField(holder, name, type);
2f37b0e442fe removed remaining VMToCompiler calls for allocating Graal API objects
Doug Simon <doug.simon@oracle.com>
parents: 14052
diff changeset
485 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
486 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
487
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
488 @Override
6588
b89b5038ad7e removed _'s from method names in CompilerToVM
Doug Simon <doug.simon@oracle.com>
parents: 5775
diff changeset
489 public void loadReferencedType(int cpi, int opcode) {
14052
361acb279104 moved to-constant-pool-index conversion up to Java
twisti
parents: 13261
diff changeset
490 int index;
14093
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
491 switch (opcode) {
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
492 case Bytecodes.CHECKCAST:
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
493 case Bytecodes.INSTANCEOF:
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
494 case Bytecodes.NEW:
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
495 case Bytecodes.ANEWARRAY:
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
496 case Bytecodes.MULTIANEWARRAY:
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
497 case Bytecodes.LDC:
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
498 case Bytecodes.LDC_W:
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
499 case Bytecodes.LDC2_W:
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
500 index = cpi;
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
501 break;
14979
5dfaaa91be37 fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
twisti
parents: 14530
diff changeset
502 case Bytecodes.INVOKEDYNAMIC:
5dfaaa91be37 fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
twisti
parents: 14530
diff changeset
503 // invokedynamic instructions point to a constant pool cache entry.
5dfaaa91be37 fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
twisti
parents: 14530
diff changeset
504 index = decodeConstantPoolCacheIndex(cpi);
5dfaaa91be37 fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
twisti
parents: 14530
diff changeset
505 index = runtime().getCompilerToVM().constantPoolRemapInstructionOperandFromCache(metaspaceConstantPool, index);
5dfaaa91be37 fixed com.oracle.graal.hotspot.meta.HotSpotConstantPool.loadReferencedType(int, int) for invokedynamic
twisti
parents: 14530
diff changeset
506 break;
14093
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
507 default:
dd783f0ecf17 refactor CompilerToVM interface
twisti
parents: 14069
diff changeset
508 index = toConstantPoolIndex(cpi, opcode);
14530
d87b84dade7d moved CompilerToVM.loadReferencedTypeInPool logic into Java
twisti
parents: 14529
diff changeset
509 index = runtime().getCompilerToVM().constantPoolRemapInstructionOperandFromCache(metaspaceConstantPool, index);
14052
361acb279104 moved to-constant-pool-index conversion up to Java
twisti
parents: 13261
diff changeset
510 }
14530
d87b84dade7d moved CompilerToVM.loadReferencedTypeInPool logic into Java
twisti
parents: 14529
diff changeset
511
d87b84dade7d moved CompilerToVM.loadReferencedTypeInPool logic into Java
twisti
parents: 14529
diff changeset
512 JVM_CONSTANT tag = getTagAt(index);
d87b84dade7d moved CompilerToVM.loadReferencedTypeInPool logic into Java
twisti
parents: 14529
diff changeset
513 switch (tag) {
d87b84dade7d moved CompilerToVM.loadReferencedTypeInPool logic into Java
twisti
parents: 14529
diff changeset
514 case Fieldref:
d87b84dade7d moved CompilerToVM.loadReferencedTypeInPool logic into Java
twisti
parents: 14529
diff changeset
515 case MethodRef:
d87b84dade7d moved CompilerToVM.loadReferencedTypeInPool logic into Java
twisti
parents: 14529
diff changeset
516 case InterfaceMethodref:
d87b84dade7d moved CompilerToVM.loadReferencedTypeInPool logic into Java
twisti
parents: 14529
diff changeset
517 index = getUncachedKlassRefIndexAt(index);
d87b84dade7d moved CompilerToVM.loadReferencedTypeInPool logic into Java
twisti
parents: 14529
diff changeset
518 tag = getTagAt(index);
d87b84dade7d moved CompilerToVM.loadReferencedTypeInPool logic into Java
twisti
parents: 14529
diff changeset
519 assert tag == JVM_CONSTANT.Class || tag == JVM_CONSTANT.UnresolvedClass || tag == JVM_CONSTANT.UnresolvedClassInError : tag;
d87b84dade7d moved CompilerToVM.loadReferencedTypeInPool logic into Java
twisti
parents: 14529
diff changeset
520 break;
d87b84dade7d moved CompilerToVM.loadReferencedTypeInPool logic into Java
twisti
parents: 14529
diff changeset
521 default:
d87b84dade7d moved CompilerToVM.loadReferencedTypeInPool logic into Java
twisti
parents: 14529
diff changeset
522 // nothing
d87b84dade7d moved CompilerToVM.loadReferencedTypeInPool logic into Java
twisti
parents: 14529
diff changeset
523 break;
d87b84dade7d moved CompilerToVM.loadReferencedTypeInPool logic into Java
twisti
parents: 14529
diff changeset
524 }
d87b84dade7d moved CompilerToVM.loadReferencedTypeInPool logic into Java
twisti
parents: 14529
diff changeset
525
d87b84dade7d moved CompilerToVM.loadReferencedTypeInPool logic into Java
twisti
parents: 14529
diff changeset
526 switch (tag) {
d87b84dade7d moved CompilerToVM.loadReferencedTypeInPool logic into Java
twisti
parents: 14529
diff changeset
527 case Class:
d87b84dade7d moved CompilerToVM.loadReferencedTypeInPool logic into Java
twisti
parents: 14529
diff changeset
528 case UnresolvedClass:
d87b84dade7d moved CompilerToVM.loadReferencedTypeInPool logic into Java
twisti
parents: 14529
diff changeset
529 case UnresolvedClassInError:
d87b84dade7d moved CompilerToVM.loadReferencedTypeInPool logic into Java
twisti
parents: 14529
diff changeset
530 final long metaspaceKlass = runtime().getCompilerToVM().constantPoolKlassAt(metaspaceConstantPool, index);
d87b84dade7d moved CompilerToVM.loadReferencedTypeInPool logic into Java
twisti
parents: 14529
diff changeset
531 HotSpotResolvedObjectType type = (HotSpotResolvedObjectType) HotSpotResolvedObjectType.fromMetaspaceKlass(metaspaceKlass);
d87b84dade7d moved CompilerToVM.loadReferencedTypeInPool logic into Java
twisti
parents: 14529
diff changeset
532 Class<?> klass = type.mirror();
d87b84dade7d moved CompilerToVM.loadReferencedTypeInPool logic into Java
twisti
parents: 14529
diff changeset
533 if (!klass.isPrimitive() && !klass.isArray()) {
d87b84dade7d moved CompilerToVM.loadReferencedTypeInPool logic into Java
twisti
parents: 14529
diff changeset
534 unsafe.ensureClassInitialized(klass);
d87b84dade7d moved CompilerToVM.loadReferencedTypeInPool logic into Java
twisti
parents: 14529
diff changeset
535 }
d87b84dade7d moved CompilerToVM.loadReferencedTypeInPool logic into Java
twisti
parents: 14529
diff changeset
536 break;
d87b84dade7d moved CompilerToVM.loadReferencedTypeInPool logic into Java
twisti
parents: 14529
diff changeset
537 default:
d87b84dade7d moved CompilerToVM.loadReferencedTypeInPool logic into Java
twisti
parents: 14529
diff changeset
538 // nothing
d87b84dade7d moved CompilerToVM.loadReferencedTypeInPool logic into Java
twisti
parents: 14529
diff changeset
539 break;
d87b84dade7d moved CompilerToVM.loadReferencedTypeInPool logic into Java
twisti
parents: 14529
diff changeset
540 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
541 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
542 }