changeset 13259:b16fb0b7479b

every HotSpotResolvedJavaMethod needs its own constant pool
author twisti
date Sun, 08 Dec 2013 11:13:26 -0800
parents fdd6ef90d66d
children f795de8d8b71
files graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotConstantPool.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotMethod.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotMethodData.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaMethod.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedObjectType.java src/share/vm/graal/graalCompilerToVM.cpp
diffstat 8 files changed, 95 insertions(+), 92 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java	Sat Dec 07 17:11:49 2013 -0800
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java	Sun Dec 08 11:13:26 2013 -0800
@@ -111,17 +111,17 @@
      */
     JavaType lookupType(String name, HotSpotResolvedObjectType accessingClass, boolean eagerResolve);
 
-    Object lookupConstantInPool(HotSpotResolvedObjectType pool, int cpi);
+    Object lookupConstantInPool(long metaspaceConstantPool, int cpi);
 
-    JavaMethod lookupMethodInPool(HotSpotResolvedObjectType pool, int cpi, byte opcode);
+    JavaMethod lookupMethodInPool(long metaspaceConstantPool, int cpi, byte opcode);
 
-    JavaType lookupTypeInPool(HotSpotResolvedObjectType pool, int cpi);
+    JavaType lookupTypeInPool(long metaspaceConstantPool, int cpi);
 
-    JavaField lookupFieldInPool(HotSpotResolvedObjectType pool, int cpi, byte opcode);
+    JavaField lookupFieldInPool(long metaspaceConstantPool, int cpi, byte opcode);
 
-    void lookupReferencedTypeInPool(HotSpotResolvedObjectType pool, int cpi, byte opcode);
+    void lookupReferencedTypeInPool(long metaspaceConstantPool, int cpi, byte opcode);
 
-    Object lookupAppendixInPool(HotSpotResolvedObjectType pool, int cpi, byte opcode);
+    Object lookupAppendixInPool(long metaspaceConstantPool, int cpi, byte opcode);
 
     public enum CodeInstallResult {
         OK("ok"), DEPENDENCIES_FAILED("dependencies failed"), CACHE_FULL("code cache is full"), CODE_TOO_LARGE("code is too large");
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java	Sat Dec 07 17:11:49 2013 -0800
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java	Sun Dec 08 11:13:26 2013 -0800
@@ -73,19 +73,22 @@
     public native JavaType lookupType(String name, HotSpotResolvedObjectType accessingClass, boolean eagerResolve);
 
     @Override
-    public native Object lookupConstantInPool(HotSpotResolvedObjectType pool, int cpi);
+    public native Object lookupConstantInPool(long metaspaceConstantPool, int cpi);
 
     @Override
-    public native JavaMethod lookupMethodInPool(HotSpotResolvedObjectType pool, int cpi, byte opcode);
+    public native JavaMethod lookupMethodInPool(long metaspaceConstantPool, int cpi, byte opcode);
 
     @Override
-    public native JavaType lookupTypeInPool(HotSpotResolvedObjectType pool, int cpi);
+    public native JavaType lookupTypeInPool(long metaspaceConstantPool, int cpi);
 
     @Override
-    public native void lookupReferencedTypeInPool(HotSpotResolvedObjectType pool, int cpi, byte opcode);
+    public native JavaField lookupFieldInPool(long metaspaceConstantPool, int cpi, byte opcode);
 
     @Override
-    public native JavaField lookupFieldInPool(HotSpotResolvedObjectType pool, int cpi, byte opcode);
+    public native void lookupReferencedTypeInPool(long metaspaceConstantPool, int cpi, byte opcode);
+
+    @Override
+    public native Object lookupAppendixInPool(long metaspaceConstantPool, int cpi, byte opcode);
 
     @Override
     public native void initializeConfiguration(HotSpotVMConfig config);
@@ -143,9 +146,6 @@
     public native void reprofile(long metaspaceMethod);
 
     @Override
-    public native Object lookupAppendixInPool(HotSpotResolvedObjectType pool, int cpi, byte opcode);
-
-    @Override
     public native void invalidateInstalledCode(HotSpotInstalledCode hotspotInstalledCode);
 
     @Override
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotConstantPool.java	Sat Dec 07 17:11:49 2013 -0800
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotConstantPool.java	Sun Dec 08 11:13:26 2013 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -37,20 +37,13 @@
 
     private static final long serialVersionUID = -5443206401485234850L;
 
-    private final HotSpotResolvedObjectType type;
-
-    public HotSpotConstantPool(HotSpotResolvedObjectType type) {
-        this.type = type;
-    }
+    /**
+     * Reference to the C++ ConstantPool object.
+     */
+    private final long metaspaceConstantPool;
 
-    /**
-     * Returns the address of this type's constant pool ({@code InstanceKlass::_constants}).
-     * 
-     * @return native address of this type's constant pool
-     */
-    private long getAddress() {
-        HotSpotVMConfig config = runtime().getConfig();
-        return unsafe.getAddress(type.metaspaceKlass() + config.instanceKlassConstantsOffset);
+    public HotSpotConstantPool(long metaspaceConstantPool) {
+        this.metaspaceConstantPool = metaspaceConstantPool;
     }
 
     /**
@@ -62,7 +55,7 @@
     private int getTagAt(int index) {
         assertBounds(index);
         HotSpotVMConfig config = runtime().getConfig();
-        long tags = unsafe.getAddress(getAddress() + config.constantPoolTagsOffset);
+        long tags = unsafe.getAddress(metaspaceConstantPool + config.constantPoolTagsOffset);
         return unsafe.getByteVolatile(null, tags + config.arrayU1DataOffset + index);
     }
 
@@ -75,7 +68,7 @@
     private long getEntryAt(int index) {
         assertBounds(index);
         HotSpotVMConfig config = runtime().getConfig();
-        return unsafe.getAddress(getAddress() + config.constantPoolSize + index * runtime().getTarget().wordSize);
+        return unsafe.getAddress(metaspaceConstantPool + config.constantPoolSize + index * runtime().getTarget().wordSize);
     }
 
     /**
@@ -87,7 +80,7 @@
     private int getIntAt(int index) {
         HotSpotVMConfig config = runtime().getConfig();
         assertTag(index, config.jvmConstantInteger);
-        return unsafe.getInt(getAddress() + config.constantPoolSize + index * runtime().getTarget().wordSize);
+        return unsafe.getInt(metaspaceConstantPool + config.constantPoolSize + index * runtime().getTarget().wordSize);
     }
 
     /**
@@ -99,7 +92,7 @@
     private long getLongAt(int index) {
         HotSpotVMConfig config = runtime().getConfig();
         assertTag(index, config.jvmConstantLong);
-        return unsafe.getLong(getAddress() + config.constantPoolSize + index * runtime().getTarget().wordSize);
+        return unsafe.getLong(metaspaceConstantPool + config.constantPoolSize + index * runtime().getTarget().wordSize);
     }
 
     /**
@@ -111,7 +104,7 @@
     private float getFloatAt(int index) {
         HotSpotVMConfig config = runtime().getConfig();
         assertTag(index, config.jvmConstantFloat);
-        return unsafe.getFloat(getAddress() + config.constantPoolSize + index * runtime().getTarget().wordSize);
+        return unsafe.getFloat(metaspaceConstantPool + config.constantPoolSize + index * runtime().getTarget().wordSize);
     }
 
     /**
@@ -123,7 +116,7 @@
     private double getDoubleAt(int index) {
         HotSpotVMConfig config = runtime().getConfig();
         assertTag(index, config.jvmConstantDouble);
-        return unsafe.getDouble(getAddress() + config.constantPoolSize + index * runtime().getTarget().wordSize);
+        return unsafe.getDouble(metaspaceConstantPool + config.constantPoolSize + index * runtime().getTarget().wordSize);
     }
 
     /**
@@ -148,7 +141,7 @@
     @Override
     public int length() {
         HotSpotVMConfig config = runtime().getConfig();
-        return unsafe.getInt(getAddress() + config.constantPoolLengthOffset);
+        return unsafe.getInt(metaspaceConstantPool + config.constantPoolLengthOffset);
     }
 
     @Override
@@ -178,11 +171,11 @@
             return lookupType(cpi, opcode);
         }
         if (tag == config.jvmConstantString) {
-            Object string = runtime().getCompilerToVM().lookupConstantInPool(type, cpi);
+            Object string = runtime().getCompilerToVM().lookupConstantInPool(metaspaceConstantPool, cpi);
             return Constant.forObject(string);
         }
         if (tag == config.jvmConstantMethodHandle || tag == config.jvmConstantMethodHandleInError || tag == config.jvmConstantMethodType || tag == config.jvmConstantMethodTypeInError) {
-            Object obj = runtime().getCompilerToVM().lookupConstantInPool(type, cpi);
+            Object obj = runtime().getCompilerToVM().lookupConstantInPool(metaspaceConstantPool, cpi);
             return Constant.forObject(obj);
         }
 
@@ -205,26 +198,26 @@
     @Override
     public Object lookupAppendix(int cpi, int opcode) {
         assert Bytecodes.isInvoke(opcode);
-        return runtime().getCompilerToVM().lookupAppendixInPool(type, cpi, (byte) opcode);
+        return runtime().getCompilerToVM().lookupAppendixInPool(metaspaceConstantPool, cpi, (byte) opcode);
     }
 
     @Override
     public JavaMethod lookupMethod(int cpi, int opcode) {
-        return runtime().getCompilerToVM().lookupMethodInPool(type, cpi, (byte) opcode);
+        return runtime().getCompilerToVM().lookupMethodInPool(metaspaceConstantPool, cpi, (byte) opcode);
     }
 
     @Override
     public JavaType lookupType(int cpi, int opcode) {
-        return runtime().getCompilerToVM().lookupTypeInPool(type, cpi);
+        return runtime().getCompilerToVM().lookupTypeInPool(metaspaceConstantPool, cpi);
     }
 
     @Override
     public JavaField lookupField(int cpi, int opcode) {
-        return runtime().getCompilerToVM().lookupFieldInPool(type, cpi, (byte) opcode);
+        return runtime().getCompilerToVM().lookupFieldInPool(metaspaceConstantPool, cpi, (byte) opcode);
     }
 
     @Override
     public void loadReferencedType(int cpi, int opcode) {
-        runtime().getCompilerToVM().lookupReferencedTypeInPool(type, cpi, (byte) opcode);
+        runtime().getCompilerToVM().lookupReferencedTypeInPool(metaspaceConstantPool, cpi, (byte) opcode);
     }
 }
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotMethod.java	Sat Dec 07 17:11:49 2013 -0800
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotMethod.java	Sun Dec 08 11:13:26 2013 -0800
@@ -30,7 +30,7 @@
 public abstract class HotSpotMethod extends CompilerObject implements JavaMethod {
 
     private static final long serialVersionUID = 7167491397941960839L;
-    protected final String name;
+    protected String name;
 
     /**
      * Controls whether {@link #toString()} includes the qualified or simple name of the class in
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotMethodData.java	Sat Dec 07 17:11:49 2013 -0800
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotMethodData.java	Sun Dec 08 11:13:26 2013 -0800
@@ -147,7 +147,7 @@
     private HotSpotMethodDataAccessor getData(int position) {
         assert position >= 0 : "out of bounds";
         int tag = AbstractMethodData.readTag(this, position);
-        assert tag >= 0 && tag < PROFILE_DATA_ACCESSORS.length : "illegal tag";
+        assert tag >= 0 && tag < PROFILE_DATA_ACCESSORS.length : "illegal tag " + tag;
         return PROFILE_DATA_ACCESSORS[tag];
     }
 
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaMethod.java	Sat Dec 07 17:11:49 2013 -0800
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaMethod.java	Sun Dec 08 11:13:26 2013 -0800
@@ -49,9 +49,10 @@
     /**
      * Reference to metaspace Method object.
      */
-    final long metaspaceMethod;
+    private final long metaspaceMethod;
 
     private final HotSpotResolvedObjectType holder;
+    private final HotSpotConstantPool constantPool;
     private final HotSpotSignature signature;
     private final int codeSize;
     private/* final */int exceptionHandlerCount;
@@ -96,13 +97,25 @@
     }
 
     HotSpotResolvedJavaMethod(HotSpotResolvedObjectType holder, long metaspaceMethod) {
-        super(createName(holder, metaspaceMethod));
+        // It would be too much work to get the method name here so we fill it in later.
+        super(null);
         this.metaspaceMethod = metaspaceMethod;
         this.holder = holder;
 
         HotSpotVMConfig config = runtime().getConfig();
-        ConstantPool constantPool = holder.constantPool();
         final long constMethod = getConstMethod();
+
+        /*
+         * Get the constant pool from the metaspace method. Some methods (e.g. intrinsics for
+         * signature-polymorphic method handle methods) have their own constant pool instead of the
+         * one from their holder.
+         */
+        final long metaspaceConstantPool = unsafe.getAddress(constMethod + config.constMethodConstantsOffset);
+        this.constantPool = new HotSpotConstantPool(metaspaceConstantPool);
+
+        final int nameIndex = unsafe.getChar(constMethod + config.constMethodNameIndexOffset);
+        this.name = constantPool.lookupUtf8(nameIndex);
+
         final int signatureIndex = unsafe.getChar(constMethod + config.constMethodSignatureIndexOffset);
         this.signature = (HotSpotSignature) constantPool.lookupSignature(signatureIndex);
         this.codeSize = unsafe.getChar(constMethod + config.constMethodCodeSizeOffset);
@@ -111,25 +124,14 @@
     }
 
     /**
-     * Helper method to construct the method's name and pass it to the super constructor.
-     */
-    private static String createName(HotSpotResolvedObjectType holder, long metaspaceMethod) {
-        HotSpotVMConfig config = runtime().getConfig();
-        ConstantPool constantPool = holder.constantPool();
-        final long constMethod = unsafe.getAddress(metaspaceMethod + config.methodConstMethodOffset);
-        final int nameIndex = unsafe.getChar(constMethod + config.constMethodNameIndexOffset);
-        return constantPool.lookupUtf8(nameIndex);
-    }
-
-    /**
      * Returns a pointer to this method's constant method data structure (
      * {@code Method::_constMethod}).
      * 
      * @return pointer to this method's ConstMethod
      */
     private long getConstMethod() {
-        HotSpotVMConfig config = runtime().getConfig();
-        return unsafe.getAddress(metaspaceMethod + config.methodConstMethodOffset);
+        assert metaspaceMethod != 0;
+        return unsafe.getAddress(metaspaceMethod + runtime().getConfig().methodConstMethodOffset);
     }
 
     @Override
@@ -137,10 +139,6 @@
         return holder;
     }
 
-    public long getMetaspaceMethod() {
-        return metaspaceMethod;
-    }
-
     /**
      * Gets the address of the C++ Method object for this method.
      */
@@ -359,7 +357,7 @@
 
     @Override
     public ConstantPool getConstantPool() {
-        return ((HotSpotResolvedObjectType) getDeclaringClass()).constantPool();
+        return constantPool;
     }
 
     @Override
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedObjectType.java	Sat Dec 07 17:11:49 2013 -0800
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedObjectType.java	Sun Dec 08 11:13:26 2013 -0800
@@ -286,16 +286,24 @@
 
     @Override
     public boolean isInitialized() {
-        HotSpotVMConfig config = runtime().getConfig();
-        byte state = unsafe.getByte(metaspaceKlass + config.klassStateOffset);
-        return state == config.klassStateFullyInitialized;
+        final int state = getState();
+        return state == runtime().getConfig().klassStateFullyInitialized;
     }
 
     @Override
     public boolean isLinked() {
-        HotSpotVMConfig config = runtime().getConfig();
-        byte state = unsafe.getByte(metaspaceKlass + config.klassStateOffset);
-        return state >= config.klassStateLinked;
+        final int state = getState();
+        return state >= runtime().getConfig().klassStateLinked;
+    }
+
+    /**
+     * Returns the value of the state field {@code InstanceKlass::_init_state} of the metaspace
+     * klass.
+     * 
+     * @return state field value of this type
+     */
+    private int getState() {
+        return unsafe.getByte(metaspaceKlass + runtime().getConfig().klassStateOffset) & 0xFF;
     }
 
     @Override
@@ -356,7 +364,8 @@
 
     public ConstantPool constantPool() {
         if (constantPool == null) {
-            constantPool = new HotSpotConstantPool(this);
+            final long metaspaceConstantPool = unsafe.getAddress(metaspaceKlass() + runtime().getConfig().instanceKlassConstantsOffset);
+            constantPool = new HotSpotConstantPool(metaspaceConstantPool);
         }
         return constantPool;
     }
@@ -493,7 +502,7 @@
     /**
      * Gets the address of the C++ Klass object for this type.
      */
-    public long metaspaceKlass() {
+    private long metaspaceKlass() {
         return metaspaceKlass;
     }
 
--- a/src/share/vm/graal/graalCompilerToVM.cpp	Sat Dec 07 17:11:49 2013 -0800
+++ b/src/share/vm/graal/graalCompilerToVM.cpp	Sun Dec 08 11:13:26 2013 -0800
@@ -194,6 +194,7 @@
   return true;
 C2V_END
 
+// XXX getMetaspaceMethodBySlot
 C2V_VMENTRY(jlong, getMetaspaceMethod, (JNIEnv *, jobject, jobject reflection_method_handle, jobject resultHolder))
   oop reflection_method = JNIHandles::resolve(reflection_method_handle);
   oop reflection_holder = java_lang_reflect_Method::clazz(reflection_method);
@@ -205,6 +206,7 @@
   return (jlong) (address) method();
 }
 
+// XXX getMetaspaceConstructorBySlot
 C2V_VMENTRY(jlong, getMetaspaceConstructor, (JNIEnv *, jobject, jobject reflection_ctor_handle, jobject resultHolder))
   oop reflection_ctor = JNIHandles::resolve(reflection_ctor_handle);
   oop reflection_holder = java_lang_reflect_Constructor::clazz(reflection_ctor);
@@ -331,8 +333,8 @@
   return JNIHandles::make_local(THREAD, result);
 C2V_END
 
-C2V_VMENTRY(jobject, lookupConstantInPool, (JNIEnv *env, jobject, jobject type, jint index))
-  ConstantPool* cp = InstanceKlass::cast(java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaMirror(type)))->constants();
+C2V_VMENTRY(jobject, lookupConstantInPool, (JNIEnv *env, jobject, jlong metaspace_constant_pool, jint index))
+  ConstantPool* cp = (ConstantPool*) metaspace_constant_pool;
   oop result = NULL;
   constantTag tag = cp->tag_at(index);
   switch (tag.value()) {
@@ -351,16 +353,16 @@
   return JNIHandles::make_local(THREAD, result);
 C2V_END
 
-C2V_VMENTRY(jobject, lookupAppendixInPool, (JNIEnv *env, jobject, jobject type, jint index, jbyte opcode))
+C2V_VMENTRY(jobject, lookupAppendixInPool, (JNIEnv *env, jobject, jlong metaspace_constant_pool, jint index, jbyte opcode))
   Bytecodes::Code bc = (Bytecodes::Code) (((int) opcode) & 0xFF);
   index = GraalCompiler::to_cp_index(index, bc);
-  constantPoolHandle cpool(InstanceKlass::cast(java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaMirror(type)))->constants());
-  oop appendix_oop = ConstantPool::appendix_at_if_loaded(cpool, index);
+  constantPoolHandle cp = (ConstantPool*) metaspace_constant_pool;
+  oop appendix_oop = ConstantPool::appendix_at_if_loaded(cp, index);
   return JNIHandles::make_local(THREAD, appendix_oop);
 C2V_END
 
-C2V_VMENTRY(jobject, lookupMethodInPool, (JNIEnv *env, jobject, jobject type, jint index, jbyte opcode))
-  constantPoolHandle cp = InstanceKlass::cast(java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaMirror(type)))->constants();
+C2V_VMENTRY(jobject, lookupMethodInPool, (JNIEnv *env, jobject, jlong metaspace_constant_pool, jint index, jbyte opcode))
+  constantPoolHandle cp = (ConstantPool*) metaspace_constant_pool;
   instanceKlassHandle pool_holder(cp->pool_holder());
 
   Bytecodes::Code bc = (Bytecodes::Code) (((int) opcode) & 0xFF);
@@ -385,14 +387,14 @@
   }
 C2V_END
 
-C2V_VMENTRY(jobject, lookupTypeInPool, (JNIEnv *env, jobject, jobject type, jint index))
-  ConstantPool* cp = InstanceKlass::cast(java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaMirror(type)))->constants();
+C2V_VMENTRY(jobject, lookupTypeInPool, (JNIEnv *env, jobject, jlong metaspace_constant_pool, jint index))
+  ConstantPool* cp = (ConstantPool*) metaspace_constant_pool;
   Handle result = GraalCompiler::get_JavaType(cp, index, cp->pool_holder(), CHECK_NULL);
   return JNIHandles::make_local(THREAD, result());
 C2V_END
 
-C2V_VMENTRY(void, lookupReferencedTypeInPool, (JNIEnv *env, jobject, jobject type, jint index, jbyte op))
-  ConstantPool* cp = InstanceKlass::cast(java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaMirror(type)))->constants();
+C2V_VMENTRY(void, lookupReferencedTypeInPool, (JNIEnv *env, jobject, jlong metaspace_constant_pool, jint index, jbyte op))
+  ConstantPool* cp = (ConstantPool*) metaspace_constant_pool;
   Bytecodes::Code bc = (Bytecodes::Code) (((int) op) & 0xFF);
   if (bc != Bytecodes::_checkcast && bc != Bytecodes::_instanceof && bc != Bytecodes::_new && bc != Bytecodes::_anewarray
       && bc != Bytecodes::_multianewarray && bc != Bytecodes::_ldc && bc != Bytecodes::_ldc_w && bc != Bytecodes::_ldc2_w)
@@ -413,11 +415,11 @@
   }
 C2V_END
 
-C2V_VMENTRY(jobject, lookupFieldInPool, (JNIEnv *env, jobject, jobject constantPoolHolder, jint index, jbyte opcode))
+C2V_VMENTRY(jobject, lookupFieldInPool, (JNIEnv *env, jobject, jlong metaspace_constant_pool, jint index, jbyte opcode))
   ResourceMark rm;
 
   int cp_index = GraalCompiler::to_cp_index_u2(index);
-  constantPoolHandle cp = InstanceKlass::cast(java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaMirror(constantPoolHolder)))->constants();
+  constantPoolHandle cp = (ConstantPool*) metaspace_constant_pool;
 
   int nt_index = cp->name_and_type_ref_index_at(cp_index);
   int sig_index = cp->signature_ref_index_at(nt_index);
@@ -989,6 +991,7 @@
 #define HS_METHOD             "Lcom/oracle/graal/hotspot/meta/HotSpotMethod;"
 #define HS_INSTALLED_CODE     "Lcom/oracle/graal/hotspot/meta/HotSpotInstalledCode;"
 #define METASPACE_METHOD      "J"
+#define METASPACE_CONSTANT_POOL "J"
 
 JNINativeMethod CompilerToVM_methods[] = {
   {CC"initializeBytecode",            CC"("METASPACE_METHOD"[B)[B",                                     FN_PTR(initializeBytecode)},
@@ -1002,12 +1005,12 @@
   {CC"isMethodCompilable",            CC"("METASPACE_METHOD")Z",                                        FN_PTR(isMethodCompilable)},
   {CC"getCompiledCodeSize",           CC"("METASPACE_METHOD")I",                                        FN_PTR(getCompiledCodeSize)},
   {CC"lookupType",                    CC"("STRING HS_RESOLVED_TYPE"Z)"TYPE,                             FN_PTR(lookupType)},
-  {CC"lookupConstantInPool",          CC"("HS_RESOLVED_TYPE"I)"OBJECT,                                  FN_PTR(lookupConstantInPool)},
-  {CC"lookupAppendixInPool",          CC"("HS_RESOLVED_TYPE"IB)"OBJECT,                                 FN_PTR(lookupAppendixInPool)},
-  {CC"lookupMethodInPool",            CC"("HS_RESOLVED_TYPE"IB)"METHOD,                                 FN_PTR(lookupMethodInPool)},
-  {CC"lookupTypeInPool",              CC"("HS_RESOLVED_TYPE"I)"TYPE,                                    FN_PTR(lookupTypeInPool)},
-  {CC"lookupReferencedTypeInPool",    CC"("HS_RESOLVED_TYPE"IB)V",                                      FN_PTR(lookupReferencedTypeInPool)},
-  {CC"lookupFieldInPool",             CC"("HS_RESOLVED_TYPE"IB)"FIELD,                                  FN_PTR(lookupFieldInPool)},
+  {CC"lookupConstantInPool",          CC"("METASPACE_CONSTANT_POOL"I)"OBJECT,                           FN_PTR(lookupConstantInPool)},
+  {CC"lookupAppendixInPool",          CC"("METASPACE_CONSTANT_POOL"IB)"OBJECT,                          FN_PTR(lookupAppendixInPool)},
+  {CC"lookupMethodInPool",            CC"("METASPACE_CONSTANT_POOL"IB)"METHOD,                          FN_PTR(lookupMethodInPool)},
+  {CC"lookupTypeInPool",              CC"("METASPACE_CONSTANT_POOL"I)"TYPE,                             FN_PTR(lookupTypeInPool)},
+  {CC"lookupReferencedTypeInPool",    CC"("METASPACE_CONSTANT_POOL"IB)V",                               FN_PTR(lookupReferencedTypeInPool)},
+  {CC"lookupFieldInPool",             CC"("METASPACE_CONSTANT_POOL"IB)"FIELD,                           FN_PTR(lookupFieldInPool)},
   {CC"resolveMethod",                 CC"("HS_RESOLVED_TYPE STRING STRING")"METHOD,                     FN_PTR(resolveMethod)},
   {CC"getInstanceFields",             CC"("HS_RESOLVED_TYPE")["HS_RESOLVED_FIELD,                       FN_PTR(getInstanceFields)},
   {CC"getMethods",                    CC"("HS_RESOLVED_TYPE")["HS_RESOLVED_METHOD,                      FN_PTR(getMethods)},