Skip to content
Permalink
Browse files
8271380: [lworld] Intrinsify j.l.Class::asPrimaryType/asValueType
  • Loading branch information
TobiHartmann committed Jul 28, 2021
1 parent 2276111 commit bebb40f5dc00b40f1fcdb68f9cebbd7bb597095d
Showing 9 changed files with 128 additions and 43 deletions.
@@ -155,6 +155,10 @@ InlineKlass* ciInlineKlass::get_InlineKlass() const {
GUARDED_VM_ENTRY(return to_InlineKlass();)
}

ciInstance* ciInlineKlass::ref_mirror() {
GUARDED_VM_ENTRY(return CURRENT_ENV->get_instance(to_InlineKlass()->ref_mirror());)
}

ciInstance* ciInlineKlass::val_mirror() {
GUARDED_VM_ENTRY(return CURRENT_ENV->get_instance(to_InlineKlass()->val_mirror());)
}
@@ -92,6 +92,7 @@ class ciInlineKlass : public ciInstanceKlass {
address pack_handler() const;
address unpack_handler() const;
InlineKlass* get_InlineKlass() const;
ciInstance* ref_mirror();
ciInstance* val_mirror();
};

@@ -235,6 +235,8 @@ bool vmIntrinsics::disabled_by_jvm_flags(vmIntrinsics::ID id) {
}

switch (id) {
case vmIntrinsics::_asPrimaryType:
case vmIntrinsics::_asValueType:
case vmIntrinsics::_isInstance:
case vmIntrinsics::_isAssignableFrom:
case vmIntrinsics::_getModifiers:
@@ -237,6 +237,10 @@ class methodHandle;
do_signature(currentThread_signature, "()Ljava/lang/Thread;") \
\
/* reflective intrinsics, for java/lang/Class, etc. */ \
do_intrinsic(_asPrimaryType, java_lang_Class, asPrimaryType_name, void_class_signature, F_R) \
do_name( asPrimaryType_name, "asPrimaryType") \
do_intrinsic(_asValueType, java_lang_Class, asValueType_name, void_class_signature, F_R) \
do_name( asValueType_name, "asValueType") \
do_intrinsic(_isAssignableFrom, java_lang_Class, isAssignableFrom_name, class_boolean_signature, F_RN) \
do_name( isAssignableFrom_name, "isAssignableFrom") \
do_intrinsic(_isInstance, java_lang_Class, isInstance_name, object_boolean_signature, F_RN) \
@@ -618,6 +618,8 @@ bool C2Compiler::is_intrinsic_supported(const methodHandle& method, bool is_virt
case vmIntrinsics::_copyOf:
case vmIntrinsics::_copyOfRange:
case vmIntrinsics::_clone:
case vmIntrinsics::_asPrimaryType:
case vmIntrinsics::_asValueType:
case vmIntrinsics::_isAssignableFrom:
case vmIntrinsics::_isInstance:
case vmIntrinsics::_getModifiers:
@@ -512,6 +512,9 @@ bool LibraryCallKit::try_to_inline(int predicate) {
case vmIntrinsics::_getSuperclass:
case vmIntrinsics::_getClassAccessFlags: return inline_native_Class_query(intrinsic_id());

case vmIntrinsics::_asPrimaryType:
case vmIntrinsics::_asValueType: return inline_primitive_Class_conversion(intrinsic_id());

case vmIntrinsics::_floatToRawIntBits:
case vmIntrinsics::_floatToIntBits:
case vmIntrinsics::_intBitsToFloat:
@@ -3341,6 +3344,35 @@ bool LibraryCallKit::inline_native_Class_query(vmIntrinsics::ID id) {
return true;
}

//-------------------------inline_primitive_Class_conversion-------------------
// public Class<T> java.lang.Class.asPrimaryType();
// public Class<T> java.lang.Class.asValueType()
bool LibraryCallKit::inline_primitive_Class_conversion(vmIntrinsics::ID id) {
Node* mirror = argument(0); // Receiver Class
const TypeInstPtr* mirror_con = _gvn.type(mirror)->isa_instptr();
if (mirror_con == NULL) {
return false;
}

bool is_val_mirror = true;
ciType* tm = mirror_con->java_mirror_type(&is_val_mirror);
if (tm != NULL) {
Node* result = mirror;
if (id == vmIntrinsics::_asPrimaryType && is_val_mirror) {
result = _gvn.makecon(TypeInstPtr::make(tm->as_inline_klass()->ref_mirror()));
} else if (id == vmIntrinsics::_asValueType) {
if (!tm->is_inlinetype()) {
return false; // Throw UnsupportedOperationException
} else if (!is_val_mirror) {
result = _gvn.makecon(TypeInstPtr::make(tm->as_inline_klass()->val_mirror()));
}
}
set_result(result);
return true;
}
return false;
}

//-------------------------inline_Class_cast-------------------
bool LibraryCallKit::inline_Class_cast() {
Node* mirror = argument(0); // Class
@@ -270,6 +270,7 @@ class LibraryCallKit : public GraphKit {
bool inline_native_getEventWriter();
#endif
bool inline_native_Class_query(vmIntrinsics::ID id);
bool inline_primitive_Class_conversion(vmIntrinsics::ID id);
bool inline_native_subtype_check();
bool inline_native_getLength();
bool inline_array_copyOf(bool is_copyOfRange);
@@ -596,6 +596,7 @@ public boolean isPrimitiveClass() {
* this class or interface
* @since Valhalla
*/
@IntrinsicCandidate
public Class<?> asPrimaryType() {
return isPrimitiveClass() ? primaryType : this;
}
@@ -613,6 +614,7 @@ public Class<?> asPrimaryType() {
* is not a primitive class
* @since Valhalla
*/
@IntrinsicCandidate
public Class<?> asValueType() {
if (isPrimitiveClass())
return secondaryType;

0 comments on commit bebb40f

Please sign in to comment.