# HG changeset patch # User twisti # Date 1394168639 28800 # Node ID a38a54030ea28846c390a780559acc7d07d9bab0 # Parent 9d8aaa3200a3bca3e35a2f66443965be5f302131 pass metaspace pointers instead of object to VM diff -r 9d8aaa3200a3 -r a38a54030ea2 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java Thu Mar 06 18:43:40 2014 -0800 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java Thu Mar 06 21:03:59 2014 -0800 @@ -107,7 +107,7 @@ this.backend = backend; this.method = method; this.entryBCI = entryBCI; - this.id = backend.getRuntime().getCompilerToVM().allocateCompileId(method, entryBCI); + this.id = method.allocateCompileId(entryBCI); this.blocking = blocking; this.taskId = uniqueTaskIds.incrementAndGet(); this.status = new AtomicReference<>(CompilationStatus.Queued); diff -r 9d8aaa3200a3 -r a38a54030ea2 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java Thu Mar 06 18:43:40 2014 -0800 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java Thu Mar 06 21:03:59 2014 -0800 @@ -241,11 +241,11 @@ void initializeConfiguration(HotSpotVMConfig config); - long resolveMethod(HotSpotResolvedObjectType klass, String name, String signature); + long resolveMethod(long metaspaceKlass, String name, String signature); - long getClassInitializer(HotSpotResolvedObjectType klass); + long getClassInitializer(long metaspaceKlass); - boolean hasFinalizableSubclass(HotSpotResolvedObjectType klass); + boolean hasFinalizableSubclass(long metaspaceKlass); /** * Gets the compiled code size for a method. @@ -277,11 +277,11 @@ long[] getDeoptedLeafGraphIds(); - long[] getLineNumberTable(HotSpotResolvedJavaMethod method); + long[] getLineNumberTable(long metaspaceMethod); - long getLocalVariableTableStart(HotSpotResolvedJavaMethod method); + long getLocalVariableTableStart(long metaspaceMethod); - int getLocalVariableTableLength(HotSpotResolvedJavaMethod method); + int getLocalVariableTableLength(long metaspaceMethod); String getFileName(HotSpotResolvedJavaType method); @@ -310,7 +310,7 @@ /** * Generate a unique id to identify the result of the compile. */ - int allocateCompileId(HotSpotResolvedJavaMethod method, int entryBCI); + int allocateCompileId(long metaspaceMethod, int entryBCI); /** * Gets the names of the supported GPU architectures. diff -r 9d8aaa3200a3 -r a38a54030ea2 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java Thu Mar 06 18:43:40 2014 -0800 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java Thu Mar 06 21:03:59 2014 -0800 @@ -97,16 +97,16 @@ public native void initializeConfiguration(HotSpotVMConfig config); @Override - public native long resolveMethod(HotSpotResolvedObjectType klass, String name, String signature); + public native long resolveMethod(long metaspaceKlass, String name, String signature); @Override - public native boolean hasFinalizableSubclass(HotSpotResolvedObjectType klass); + public native boolean hasFinalizableSubclass(long metaspaceKlass); @Override public native void initializeMethod(long metaspaceMethod, HotSpotResolvedJavaMethod method); @Override - public native long getClassInitializer(HotSpotResolvedObjectType klass); + public native long getClassInitializer(long metaspaceKlass); @Override public native int getCompiledCodeSize(long metaspaceMethod); @@ -128,13 +128,13 @@ public native long[] getDeoptedLeafGraphIds(); @Override - public native long[] getLineNumberTable(HotSpotResolvedJavaMethod method); + public native long[] getLineNumberTable(long metaspaceMethod); @Override - public native long getLocalVariableTableStart(HotSpotResolvedJavaMethod method); + public native long getLocalVariableTableStart(long metaspaceMethod); @Override - public native int getLocalVariableTableLength(HotSpotResolvedJavaMethod method); + public native int getLocalVariableTableLength(long metaspaceMethod); @Override public native String getFileName(HotSpotResolvedJavaType method); @@ -179,7 +179,7 @@ public native boolean isMature(long method); - public native int allocateCompileId(HotSpotResolvedJavaMethod method, int entryBCI); + public native int allocateCompileId(long metaspaceMethod, int entryBCI); public native String getGPUs(); diff -r 9d8aaa3200a3 -r a38a54030ea2 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotCodeCacheProvider.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotCodeCacheProvider.java Thu Mar 06 18:43:40 2014 -0800 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotCodeCacheProvider.java Thu Mar 06 21:03:59 2014 -0800 @@ -170,7 +170,7 @@ public HotSpotInstalledCode installMethod(HotSpotResolvedJavaMethod method, CompilationResult compResult) { if (compResult.getId() == -1) { - compResult.setId(runtime.getCompilerToVM().allocateCompileId(method, compResult.getEntryBCI())); + compResult.setId(method.allocateCompileId(compResult.getEntryBCI())); } HotSpotInstalledCode installedCode = new HotSpotNmethod(method, compResult.getName(), true); runtime.getCompilerToVM().installCode(new HotSpotCompiledNmethod(target.arch, method, compResult), installedCode, method.getSpeculationLog()); @@ -181,7 +181,7 @@ public InstalledCode addMethod(ResolvedJavaMethod method, CompilationResult compResult, SpeculationLog log) { HotSpotResolvedJavaMethod hotspotMethod = (HotSpotResolvedJavaMethod) method; if (compResult.getId() == -1) { - compResult.setId(runtime.getCompilerToVM().allocateCompileId(hotspotMethod, compResult.getEntryBCI())); + compResult.setId(hotspotMethod.allocateCompileId(compResult.getEntryBCI())); } HotSpotInstalledCode code = new HotSpotNmethod(hotspotMethod, compResult.getName(), false); CodeInstallResult result = runtime.getCompilerToVM().installCode(new HotSpotCompiledNmethod(target.arch, hotspotMethod, compResult), code, log); @@ -200,7 +200,7 @@ public HotSpotNmethod addExternalMethod(ResolvedJavaMethod method, CompilationResult compResult) { HotSpotResolvedJavaMethod javaMethod = (HotSpotResolvedJavaMethod) method; if (compResult.getId() == -1) { - compResult.setId(runtime.getCompilerToVM().allocateCompileId(javaMethod, compResult.getEntryBCI())); + compResult.setId(javaMethod.allocateCompileId(compResult.getEntryBCI())); } HotSpotNmethod code = new HotSpotNmethod(javaMethod, compResult.getName(), false, true); HotSpotCompiledNmethod compiled = new HotSpotCompiledNmethod(target.arch, javaMethod, compResult); diff -r 9d8aaa3200a3 -r a38a54030ea2 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaMethod.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaMethod.java Thu Mar 06 18:43:40 2014 -0800 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaMethod.java Thu Mar 06 21:03:59 2014 -0800 @@ -483,7 +483,7 @@ @Override public LineNumberTable getLineNumberTable() { - long[] values = runtime().getCompilerToVM().getLineNumberTable(this); + long[] values = runtime().getCompilerToVM().getLineNumberTable(metaspaceMethod); if (values == null) { return null; } @@ -515,8 +515,8 @@ } HotSpotVMConfig config = runtime().getConfig(); - long localVariableTableElement = runtime().getCompilerToVM().getLocalVariableTableStart(this); - final int localVariableTableLength = runtime().getCompilerToVM().getLocalVariableTableLength(this); + long localVariableTableElement = runtime().getCompilerToVM().getLocalVariableTableStart(metaspaceMethod); + final int localVariableTableLength = runtime().getCompilerToVM().getLocalVariableTableLength(metaspaceMethod); Local[] locals = new Local[localVariableTableLength]; for (int i = 0; i < localVariableTableLength; i++) { @@ -630,6 +630,16 @@ } } + /** + * Allocates a compile id for this method by asking the VM for one. + * + * @param entryBCI entry bci + * @return compile id + */ + public int allocateCompileId(int entryBCI) { + return runtime().getCompilerToVM().allocateCompileId(metaspaceMethod, entryBCI); + } + public boolean tryToQueueForCompilation() { // other threads may update certain bits of the access flags field concurrently. So, the // loop ensures that this method only returns false when another thread has set the diff -r 9d8aaa3200a3 -r a38a54030ea2 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedObjectType.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedObjectType.java Thu Mar 06 18:43:40 2014 -0800 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedObjectType.java Thu Mar 06 21:03:59 2014 -0800 @@ -278,7 +278,7 @@ @Override public boolean hasFinalizableSubclass() { assert !isArray(); - return runtime().getCompilerToVM().hasFinalizableSubclass(this); + return runtime().getCompilerToVM().hasFinalizableSubclass(metaspaceKlass()); } @Override @@ -363,7 +363,7 @@ @Override public ResolvedJavaMethod resolveMethod(ResolvedJavaMethod method) { assert method instanceof HotSpotMethod; - final long resolvedMetaspaceMethod = runtime().getCompilerToVM().resolveMethod(this, method.getName(), ((HotSpotSignature) method.getSignature()).getMethodDescriptor()); + final long resolvedMetaspaceMethod = runtime().getCompilerToVM().resolveMethod(metaspaceKlass(), method.getName(), ((HotSpotSignature) method.getSignature()).getMethodDescriptor()); if (resolvedMetaspaceMethod == 0) { return null; } @@ -736,7 +736,8 @@ } public ResolvedJavaMethod getClassInitializer() { - long metaspaceMethod = runtime().getCompilerToVM().getClassInitializer(this); + System.out.println(this); + final long metaspaceMethod = runtime().getCompilerToVM().getClassInitializer(metaspaceKlass()); if (metaspaceMethod != 0L) { return createMethod(metaspaceMethod); } diff -r 9d8aaa3200a3 -r a38a54030ea2 src/share/vm/graal/graalCodeInstaller.cpp --- a/src/share/vm/graal/graalCodeInstaller.cpp Thu Mar 06 18:43:40 2014 -0800 +++ b/src/share/vm/graal/graalCodeInstaller.cpp Thu Mar 06 21:03:59 2014 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2014, 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 @@ -51,6 +51,11 @@ # include "vmreg_ppc.inline.hpp" #endif +Method* getMethodFromHotSpotMethod(oop hotspot_method) { + assert(hotspot_method != NULL && hotspot_method->is_a(HotSpotResolvedJavaMethod::klass()), "sanity"); + return asMethod(HotSpotResolvedJavaMethod::metaspaceMethod(hotspot_method)); +} + // convert Graal register indices (as used in oop maps) to HotSpot registers VMReg get_hotspot_reg(jint graal_reg) { if (graal_reg < RegisterImpl::number_of_registers) { diff -r 9d8aaa3200a3 -r a38a54030ea2 src/share/vm/graal/graalCodeInstaller.hpp --- a/src/share/vm/graal/graalCodeInstaller.hpp Thu Mar 06 18:43:40 2014 -0800 +++ b/src/share/vm/graal/graalCodeInstaller.hpp Thu Mar 06 21:03:59 2014 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2014, 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 @@ -120,6 +120,11 @@ }; +/** + * Gets the Method metaspace object from a HotSpotResolvedJavaMethod Java object. + */ +Method* getMethodFromHotSpotMethod(oop hotspot_method); + #ifdef TARGET_ARCH_x86 # include "graalCodeInstaller_x86.hpp" #endif diff -r 9d8aaa3200a3 -r a38a54030ea2 src/share/vm/graal/graalCompilerToVM.cpp --- a/src/share/vm/graal/graalCompilerToVM.cpp Thu Mar 06 18:43:40 2014 -0800 +++ b/src/share/vm/graal/graalCompilerToVM.cpp Thu Mar 06 21:03:59 2014 -0800 @@ -43,11 +43,6 @@ #include "runtime/gpu.hpp" -Method* getMethodFromHotSpotMethod(oop hotspot_method) { - assert(hotspot_method != NULL && hotspot_method->is_a(HotSpotResolvedJavaMethod::klass()), "sanity"); - return asMethod(HotSpotResolvedJavaMethod::metaspaceMethod(hotspot_method)); -} - // Entry to native method implementation that transitions current thread to '_thread_in_vm'. #define C2V_VMENTRY(result_type, name, signature) \ JNIEXPORT result_type JNICALL c2v_ ## name signature { \ @@ -357,24 +352,22 @@ return (jlong) (address) result.field_holder(); C2V_END -C2V_VMENTRY(jlong, resolveMethod, (JNIEnv *, jobject, jobject resolved_type, jstring name, jstring signature)) - assert(JNIHandles::resolve(resolved_type) != NULL, ""); - Klass* klass = java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaClass(resolved_type)); +C2V_VMENTRY(jlong, resolveMethod, (JNIEnv *, jobject, jlong metaspace_klass, jstring name, jstring signature)) + Klass* klass = (Klass*) metaspace_klass; Symbol* name_symbol = java_lang_String::as_symbol(JNIHandles::resolve(name), THREAD); Symbol* signature_symbol = java_lang_String::as_symbol(JNIHandles::resolve(signature), THREAD); return (jlong) (address) klass->lookup_method(name_symbol, signature_symbol); C2V_END -C2V_VMENTRY(jboolean, hasFinalizableSubclass,(JNIEnv *, jobject, jobject hotspot_klass)) - Klass* klass = java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaClass(hotspot_klass)); +C2V_VMENTRY(jboolean, hasFinalizableSubclass,(JNIEnv *, jobject, jlong metaspace_klass)) + Klass* klass = (Klass*) metaspace_klass; assert(klass != NULL, "method must not be called for primitive types"); return Dependencies::find_finalizable_subclass(klass) != NULL; C2V_END -C2V_VMENTRY(jlong, getClassInitializer, (JNIEnv *, jobject, jobject klass)) - instanceKlassHandle k(THREAD, java_lang_Class::as_Klass(HotSpotResolvedObjectType::javaClass(klass))); - Method* clinit = k->class_initializer(); - return (jlong) (address) clinit; +C2V_VMENTRY(jlong, getClassInitializer, (JNIEnv *, jobject, jlong metaspace_klass)) + InstanceKlass* klass = (InstanceKlass*) metaspace_klass; + return (jlong) (address) klass->class_initializer(); C2V_END C2V_VMENTRY(jlong, getMaxCallTargetOffset, (JNIEnv *env, jobject, jlong addr)) @@ -708,8 +701,8 @@ return JNIHandles::make_local(array); C2V_END -C2V_ENTRY(jlongArray, getLineNumberTable, (JNIEnv *env, jobject, jobject hotspot_method)) - Method* method = getMethodFromHotSpotMethod(JNIHandles::resolve(hotspot_method)); +C2V_ENTRY(jlongArray, getLineNumberTable, (JNIEnv *env, jobject, jlong metaspace_method)) + Method* method = (Method*) metaspace_method; if (!method->has_linenumber_table()) { return NULL; } @@ -735,18 +728,18 @@ return result; C2V_END -C2V_VMENTRY(jlong, getLocalVariableTableStart, (JNIEnv *, jobject, jobject hotspot_method)) +C2V_VMENTRY(jlong, getLocalVariableTableStart, (JNIEnv *, jobject, jlong metaspace_method)) ResourceMark rm; - Method* method = getMethodFromHotSpotMethod(JNIHandles::resolve(hotspot_method)); + Method* method = (Method*) metaspace_method; if (!method->has_localvariable_table()) { return 0; } return (jlong) (address) method->localvariable_table_start(); C2V_END -C2V_VMENTRY(jint, getLocalVariableTableLength, (JNIEnv *, jobject, jobject hotspot_method)) +C2V_VMENTRY(jint, getLocalVariableTableLength, (JNIEnv *, jobject, jlong metaspace_method)) ResourceMark rm; - Method* method = getMethodFromHotSpotMethod(JNIHandles::resolve(hotspot_method)); + Method* method = (Method*) metaspace_method; return method->localvariable_table_length(); C2V_END @@ -812,10 +805,10 @@ #endif C2V_END -C2V_VMENTRY(int, allocateCompileId, (JNIEnv *env, jobject, jobject hotspot_method, int entry_bci)) +C2V_VMENTRY(int, allocateCompileId, (JNIEnv *env, jobject, jlong metaspace_method, int entry_bci)) HandleMark hm; ResourceMark rm; - Method* method = getMethodFromHotSpotMethod(JNIHandles::resolve(hotspot_method)); + Method* method = (Method*) metaspace_method; return CompileBroker::assign_compile_id_unlocked(THREAD, method, entry_bci); C2V_END @@ -836,7 +829,6 @@ #define OBJECT "Ljava/lang/Object;" #define CLASS "Ljava/lang/Class;" #define STACK_TRACE_ELEMENT "Ljava/lang/StackTraceElement;" -#define HS_RESOLVED_TYPE "Lcom/oracle/graal/hotspot/meta/HotSpotResolvedObjectType;" #define HS_RESOLVED_METHOD "Lcom/oracle/graal/hotspot/meta/HotSpotResolvedJavaMethod;" #define HS_COMPILED_CODE "Lcom/oracle/graal/hotspot/HotSpotCompiledCode;" #define HS_CONFIG "Lcom/oracle/graal/hotspot/HotSpotVMConfig;" @@ -871,9 +863,9 @@ {CC"lookupMethodInPool", CC"("METASPACE_CONSTANT_POOL"IB)"METASPACE_METHOD, FN_PTR(lookupMethodInPool)}, {CC"loadReferencedTypeInPool", CC"("METASPACE_CONSTANT_POOL"IB)V", FN_PTR(loadReferencedTypeInPool)}, {CC"resolveField", CC"("METASPACE_CONSTANT_POOL"IB[J)"METASPACE_KLASS, FN_PTR(resolveField)}, - {CC"resolveMethod", CC"("HS_RESOLVED_TYPE STRING STRING")"METASPACE_METHOD, FN_PTR(resolveMethod)}, - {CC"getClassInitializer", CC"("HS_RESOLVED_TYPE")"METASPACE_METHOD, FN_PTR(getClassInitializer)}, - {CC"hasFinalizableSubclass", CC"("HS_RESOLVED_TYPE")Z", FN_PTR(hasFinalizableSubclass)}, + {CC"resolveMethod", CC"("METASPACE_KLASS STRING STRING")"METASPACE_METHOD, FN_PTR(resolveMethod)}, + {CC"getClassInitializer", CC"("METASPACE_KLASS")"METASPACE_METHOD, FN_PTR(getClassInitializer)}, + {CC"hasFinalizableSubclass", CC"("METASPACE_KLASS")Z", FN_PTR(hasFinalizableSubclass)}, {CC"getMaxCallTargetOffset", CC"(J)J", FN_PTR(getMaxCallTargetOffset)}, {CC"getMetaspaceMethod", CC"("CLASS"I)"METASPACE_METHOD, FN_PTR(getMetaspaceMethod)}, {CC"initializeConfiguration", CC"("HS_CONFIG")V", FN_PTR(initializeConfiguration)}, @@ -884,16 +876,16 @@ {CC"disassembleCodeBlob", CC"(J)"STRING, FN_PTR(disassembleCodeBlob)}, {CC"executeCompiledMethodVarargs", CC"(["OBJECT HS_INSTALLED_CODE")"OBJECT, FN_PTR(executeCompiledMethodVarargs)}, {CC"getDeoptedLeafGraphIds", CC"()[J", FN_PTR(getDeoptedLeafGraphIds)}, - {CC"getLineNumberTable", CC"("HS_RESOLVED_METHOD")[J", FN_PTR(getLineNumberTable)}, - {CC"getLocalVariableTableStart", CC"("HS_RESOLVED_METHOD")J", FN_PTR(getLocalVariableTableStart)}, - {CC"getLocalVariableTableLength", CC"("HS_RESOLVED_METHOD")I", FN_PTR(getLocalVariableTableLength)}, + {CC"getLineNumberTable", CC"("METASPACE_METHOD")[J", FN_PTR(getLineNumberTable)}, + {CC"getLocalVariableTableStart", CC"("METASPACE_METHOD")J", FN_PTR(getLocalVariableTableStart)}, + {CC"getLocalVariableTableLength", CC"("METASPACE_METHOD")I", FN_PTR(getLocalVariableTableLength)}, {CC"reprofile", CC"("METASPACE_METHOD")V", FN_PTR(reprofile)}, {CC"invalidateInstalledCode", CC"("HS_INSTALLED_CODE")V", FN_PTR(invalidateInstalledCode)}, {CC"readUnsafeUncompressedPointer", CC"("OBJECT"J)"OBJECT, FN_PTR(readUnsafeUncompressedPointer)}, {CC"readUnsafeKlassPointer", CC"("OBJECT")J", FN_PTR(readUnsafeKlassPointer)}, {CC"collectCounters", CC"()[J", FN_PTR(collectCounters)}, {CC"getGPUs", CC"()"STRING, FN_PTR(getGPUs)}, - {CC"allocateCompileId", CC"("HS_RESOLVED_METHOD"I)I", FN_PTR(allocateCompileId)}, + {CC"allocateCompileId", CC"("METASPACE_METHOD"I)I", FN_PTR(allocateCompileId)}, {CC"isMature", CC"("METASPACE_METHOD_DATA")Z", FN_PTR(isMature)}, }; diff -r 9d8aaa3200a3 -r a38a54030ea2 src/share/vm/graal/graalCompilerToVM.hpp --- a/src/share/vm/graal/graalCompilerToVM.hpp Thu Mar 06 18:43:40 2014 -0800 +++ b/src/share/vm/graal/graalCompilerToVM.hpp Thu Mar 06 21:03:59 2014 -0800 @@ -63,11 +63,6 @@ return (Klass*) (address) metaspaceKlass; } -/** - * Gets the Method metaspace object from a HotSpotResolvedJavaMethod Java object. - */ -Method* getMethodFromHotSpotMethod(oop hotspot_method); - class JavaArgumentUnboxer : public SignatureIterator { protected: JavaCallArguments* _jca;