8244550: Unsafe::allocateInstance does redundant transitions

Reviewed-by: coleenp, mchung, dholmes
This commit is contained in:
Claes Redestad 2020-05-07 14:09:20 +02:00
parent 62bf2d07e7
commit c2780c9556
16 changed files with 40 additions and 31 deletions

View file

@ -30,6 +30,7 @@
#include "c1/c1_LIRAssembler.hpp" #include "c1/c1_LIRAssembler.hpp"
#include "c1/c1_MacroAssembler.hpp" #include "c1/c1_MacroAssembler.hpp"
#include "c1/c1_Runtime1.hpp" #include "c1/c1_Runtime1.hpp"
#include "classfile/javaClasses.inline.hpp"
#include "classfile/systemDictionary.hpp" #include "classfile/systemDictionary.hpp"
#include "classfile/vmSymbols.hpp" #include "classfile/vmSymbols.hpp"
#include "code/codeBlob.hpp" #include "code/codeBlob.hpp"

View file

@ -27,6 +27,7 @@
#include "jimage.hpp" #include "jimage.hpp"
#include "classfile/classListParser.hpp" #include "classfile/classListParser.hpp"
#include "classfile/classLoaderExt.hpp" #include "classfile/classLoaderExt.hpp"
#include "classfile/javaClasses.inline.hpp"
#include "classfile/symbolTable.hpp" #include "classfile/symbolTable.hpp"
#include "classfile/systemDictionary.hpp" #include "classfile/systemDictionary.hpp"
#include "classfile/systemDictionaryShared.hpp" #include "classfile/systemDictionaryShared.hpp"

View file

@ -1495,14 +1495,6 @@ oop java_lang_Class::create_basic_type_mirror(const char* basic_type_name, Basic
} }
Klass* java_lang_Class::as_Klass(oop java_class) {
//%note memory_2
assert(java_lang_Class::is_instance(java_class), "must be a Class object");
Klass* k = ((Klass*)java_class->metadata_field(_klass_offset));
assert(k == NULL || k->is_klass(), "type check");
return k;
}
Klass* java_lang_Class::as_Klass_raw(oop java_class) { Klass* java_lang_Class::as_Klass_raw(oop java_class) {
//%note memory_2 //%note memory_2
assert(java_lang_Class::is_instance(java_class), "must be a Class object"); assert(java_lang_Class::is_instance(java_class), "must be a Class object");

View file

@ -211,6 +211,14 @@ inline bool java_lang_Class::is_instance(oop obj) {
return obj != NULL && obj->klass() == SystemDictionary::Class_klass(); return obj != NULL && obj->klass() == SystemDictionary::Class_klass();
} }
inline Klass* java_lang_Class::as_Klass(oop java_class) {
//%note memory_2
assert(java_lang_Class::is_instance(java_class), "must be a Class object");
Klass* k = ((Klass*)java_class->metadata_field(_klass_offset));
assert(k == NULL || k->is_klass(), "type check");
return k;
}
inline bool java_lang_Class::is_primitive(oop java_class) { inline bool java_lang_Class::is_primitive(oop java_class) {
// should assert: // should assert:
//assert(java_lang_Class::is_instance(java_class), "must be a Class object"); //assert(java_lang_Class::is_instance(java_class), "must be a Class object");

View file

@ -23,7 +23,7 @@
*/ */
#include "precompiled.hpp" #include "precompiled.hpp"
#include "classfile/javaClasses.hpp" #include "classfile/javaClasses.inline.hpp"
#include "jfr/leakprofiler/chains/edge.hpp" #include "jfr/leakprofiler/chains/edge.hpp"
#include "jfr/leakprofiler/chains/edgeStore.hpp" #include "jfr/leakprofiler/chains/edgeStore.hpp"
#include "jfr/leakprofiler/chains/edgeUtils.hpp" #include "jfr/leakprofiler/chains/edgeUtils.hpp"

View file

@ -23,7 +23,7 @@
*/ */
#include "precompiled.hpp" #include "precompiled.hpp"
#include "classfile/javaClasses.hpp" #include "classfile/javaClasses.inline.hpp"
#include "classfile/symbolTable.hpp" #include "classfile/symbolTable.hpp"
#include "classfile/systemDictionary.hpp" #include "classfile/systemDictionary.hpp"
#include "jfr/leakprofiler/checkpoint/objectSampleDescription.hpp" #include "jfr/leakprofiler/checkpoint/objectSampleDescription.hpp"

View file

@ -24,6 +24,7 @@
#include "precompiled.hpp" #include "precompiled.hpp"
#include "classfile/classLoaderData.inline.hpp" #include "classfile/classLoaderData.inline.hpp"
#include "classfile/javaClasses.inline.hpp"
#include "classfile/symbolTable.hpp" #include "classfile/symbolTable.hpp"
#include "jfr/recorder/checkpoint/types/traceid/jfrTraceId.inline.hpp" #include "jfr/recorder/checkpoint/types/traceid/jfrTraceId.inline.hpp"
#include "jfr/utilities/jfrTypes.hpp" #include "jfr/utilities/jfrTypes.hpp"

View file

@ -22,6 +22,7 @@
*/ */
#include "precompiled.hpp" #include "precompiled.hpp"
#include "classfile/javaClasses.inline.hpp"
#include "code/compiledIC.hpp" #include "code/compiledIC.hpp"
#include "compiler/compileBroker.hpp" #include "compiler/compileBroker.hpp"
#include "jvmci/jvmciCodeInstaller.hpp" #include "jvmci/jvmciCodeInstaller.hpp"

View file

@ -22,6 +22,7 @@
*/ */
#include "precompiled.hpp" #include "precompiled.hpp"
#include "classfile/javaClasses.inline.hpp"
#include "classfile/symbolTable.hpp" #include "classfile/symbolTable.hpp"
#include "compiler/compileBroker.hpp" #include "compiler/compileBroker.hpp"
#include "jvmci/jniAccessMark.inline.hpp" #include "jvmci/jniAccessMark.inline.hpp"

View file

@ -958,6 +958,7 @@ public:
} }
// allocation // allocation
instanceOop allocate_instance(TRAPS); instanceOop allocate_instance(TRAPS);
static instanceOop allocate_instance(oop cls, TRAPS);
// additional member function to return a handle // additional member function to return a handle
instanceHandle allocate_instance_handle(TRAPS); instanceHandle allocate_instance_handle(TRAPS);

View file

@ -157,4 +157,16 @@ ALWAYSINLINE void InstanceKlass::oop_oop_iterate_bounded(oop obj, OopClosureType
oop_oop_iterate_oop_maps_bounded<T>(obj, closure, mr); oop_oop_iterate_oop_maps_bounded<T>(obj, closure, mr);
} }
inline instanceOop InstanceKlass::allocate_instance(oop java_class, TRAPS) {
Klass* k = java_lang_Class::as_Klass(java_class);
if (k == NULL) {
ResourceMark rm(THREAD);
THROW_(vmSymbols::java_lang_InstantiationException(), NULL);
}
InstanceKlass* ik = cast(k);
ik->check_valid_for_instantiation(false, CHECK_NULL);
ik->initialize(CHECK_NULL);
return ik->allocate_instance(THREAD);
}
#endif // SHARE_OOPS_INSTANCEKLASS_INLINE_HPP #endif // SHARE_OOPS_INSTANCEKLASS_INLINE_HPP

View file

@ -49,7 +49,7 @@
#include "memory/universe.hpp" #include "memory/universe.hpp"
#include "oops/access.inline.hpp" #include "oops/access.inline.hpp"
#include "oops/arrayOop.inline.hpp" #include "oops/arrayOop.inline.hpp"
#include "oops/instanceKlass.hpp" #include "oops/instanceKlass.inline.hpp"
#include "oops/instanceOop.hpp" #include "oops/instanceOop.hpp"
#include "oops/markWord.hpp" #include "oops/markWord.hpp"
#include "oops/method.hpp" #include "oops/method.hpp"
@ -1064,19 +1064,6 @@ static void jni_invoke_nonstatic(JNIEnv *env, JavaValue* result, jobject receive
} }
} }
static instanceOop alloc_object(jclass clazz, TRAPS) {
Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz));
if (k == NULL) {
ResourceMark rm(THREAD);
THROW_(vmSymbols::java_lang_InstantiationException(), NULL);
}
k->check_valid_for_instantiation(false, CHECK_NULL);
k->initialize(CHECK_NULL);
instanceOop ih = InstanceKlass::cast(k)->allocate_instance(THREAD);
return ih;
}
DT_RETURN_MARK_DECL(AllocObject, jobject DT_RETURN_MARK_DECL(AllocObject, jobject
, HOTSPOT_JNI_ALLOCOBJECT_RETURN(_ret_ref)); , HOTSPOT_JNI_ALLOCOBJECT_RETURN(_ret_ref));
@ -1088,7 +1075,7 @@ JNI_ENTRY(jobject, jni_AllocObject(JNIEnv *env, jclass clazz))
jobject ret = NULL; jobject ret = NULL;
DT_RETURN_MARK(AllocObject, jobject, (const jobject&)ret); DT_RETURN_MARK(AllocObject, jobject, (const jobject&)ret);
instanceOop i = alloc_object(clazz, CHECK_NULL); instanceOop i = InstanceKlass::allocate_instance(JNIHandles::resolve_non_null(clazz), CHECK_NULL);
ret = JNIHandles::make_local(env, i); ret = JNIHandles::make_local(env, i);
return ret; return ret;
JNI_END JNI_END
@ -1104,7 +1091,7 @@ JNI_ENTRY(jobject, jni_NewObjectA(JNIEnv *env, jclass clazz, jmethodID methodID,
jobject obj = NULL; jobject obj = NULL;
DT_RETURN_MARK(NewObjectA, jobject, (const jobject)obj); DT_RETURN_MARK(NewObjectA, jobject, (const jobject)obj);
instanceOop i = alloc_object(clazz, CHECK_NULL); instanceOop i = InstanceKlass::allocate_instance(JNIHandles::resolve_non_null(clazz), CHECK_NULL);
obj = JNIHandles::make_local(env, i); obj = JNIHandles::make_local(env, i);
JavaValue jvalue(T_VOID); JavaValue jvalue(T_VOID);
JNI_ArgumentPusherArray ap(methodID, args); JNI_ArgumentPusherArray ap(methodID, args);
@ -1124,7 +1111,7 @@ JNI_ENTRY(jobject, jni_NewObjectV(JNIEnv *env, jclass clazz, jmethodID methodID,
jobject obj = NULL; jobject obj = NULL;
DT_RETURN_MARK(NewObjectV, jobject, (const jobject&)obj); DT_RETURN_MARK(NewObjectV, jobject, (const jobject&)obj);
instanceOop i = alloc_object(clazz, CHECK_NULL); instanceOop i = InstanceKlass::allocate_instance(JNIHandles::resolve_non_null(clazz), CHECK_NULL);
obj = JNIHandles::make_local(env, i); obj = JNIHandles::make_local(env, i);
JavaValue jvalue(T_VOID); JavaValue jvalue(T_VOID);
JNI_ArgumentPusherVaArg ap(methodID, args); JNI_ArgumentPusherVaArg ap(methodID, args);
@ -1144,7 +1131,7 @@ JNI_ENTRY(jobject, jni_NewObject(JNIEnv *env, jclass clazz, jmethodID methodID,
jobject obj = NULL; jobject obj = NULL;
DT_RETURN_MARK(NewObject, jobject, (const jobject&)obj); DT_RETURN_MARK(NewObject, jobject, (const jobject&)obj);
instanceOop i = alloc_object(clazz, CHECK_NULL); instanceOop i = InstanceKlass::allocate_instance(JNIHandles::resolve_non_null(clazz), CHECK_NULL);
obj = JNIHandles::make_local(env, i); obj = JNIHandles::make_local(env, i);
va_list args; va_list args;
va_start(args, methodID); va_start(args, methodID);

View file

@ -27,12 +27,14 @@
#include "jvm.h" #include "jvm.h"
#include "classfile/classFileStream.hpp" #include "classfile/classFileStream.hpp"
#include "classfile/classLoader.hpp" #include "classfile/classLoader.hpp"
#include "classfile/javaClasses.inline.hpp"
#include "classfile/vmSymbols.hpp" #include "classfile/vmSymbols.hpp"
#include "jfr/jfrEvents.hpp" #include "jfr/jfrEvents.hpp"
#include "memory/allocation.inline.hpp" #include "memory/allocation.inline.hpp"
#include "memory/resourceArea.hpp" #include "memory/resourceArea.hpp"
#include "oops/access.inline.hpp" #include "oops/access.inline.hpp"
#include "oops/fieldStreams.inline.hpp" #include "oops/fieldStreams.inline.hpp"
#include "oops/instanceKlass.inline.hpp"
#include "oops/objArrayOop.inline.hpp" #include "oops/objArrayOop.inline.hpp"
#include "oops/oop.inline.hpp" #include "oops/oop.inline.hpp"
#include "oops/typeArrayOop.inline.hpp" #include "oops/typeArrayOop.inline.hpp"
@ -353,8 +355,8 @@ UNSAFE_LEAF(void, Unsafe_FullFence(JNIEnv *env, jobject unsafe)) {
////// Allocation requests ////// Allocation requests
UNSAFE_ENTRY(jobject, Unsafe_AllocateInstance(JNIEnv *env, jobject unsafe, jclass cls)) { UNSAFE_ENTRY(jobject, Unsafe_AllocateInstance(JNIEnv *env, jobject unsafe, jclass cls)) {
ThreadToNativeFromVM ttnfv(thread); instanceOop i = InstanceKlass::allocate_instance(JNIHandles::resolve_non_null(cls), CHECK_NULL);
return env->AllocObject(cls); return JNIHandles::make_local(env, i);
} UNSAFE_END } UNSAFE_END
UNSAFE_ENTRY(jlong, Unsafe_AllocateMemory0(JNIEnv *env, jobject unsafe, jlong size)) { UNSAFE_ENTRY(jlong, Unsafe_AllocateMemory0(JNIEnv *env, jobject unsafe, jlong size)) {

View file

@ -27,6 +27,7 @@
#include <new> #include <new>
#include "classfile/classLoaderDataGraph.hpp" #include "classfile/classLoaderDataGraph.hpp"
#include "classfile/javaClasses.inline.hpp"
#include "classfile/modules.hpp" #include "classfile/modules.hpp"
#include "classfile/protectionDomainCache.hpp" #include "classfile/protectionDomainCache.hpp"
#include "classfile/stringTable.hpp" #include "classfile/stringTable.hpp"

View file

@ -26,6 +26,7 @@
#include "precompiled.hpp" #include "precompiled.hpp"
#include "jvm.h" #include "jvm.h"
#include "classfile/javaClasses.inline.hpp"
#include "classfile/symbolTable.hpp" #include "classfile/symbolTable.hpp"
#include "classfile/systemDictionary.hpp" #include "classfile/systemDictionary.hpp"
#include "code/codeCache.hpp" #include "code/codeCache.hpp"

View file

@ -23,7 +23,7 @@
*/ */
#include "precompiled.hpp" #include "precompiled.hpp"
#include "classfile/javaClasses.hpp" #include "classfile/javaClasses.inline.hpp"
#include "classfile/systemDictionary.hpp" #include "classfile/systemDictionary.hpp"
#include "classfile/vmSymbols.hpp" #include "classfile/vmSymbols.hpp"
#include "code/codeCache.hpp" #include "code/codeCache.hpp"