mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-26 22:34:27 +02:00
8331187: Optimize MethodTypeDesc and ClassDesc.ofDescriptor for primitive types
Reviewed-by: jvernee, liach
This commit is contained in:
parent
5e2ced4b9e
commit
8bbd7251a5
6 changed files with 121 additions and 53 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 2024, 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
|
||||
|
@ -25,25 +25,27 @@
|
|||
|
||||
package sun.invoke.util;
|
||||
|
||||
import java.util.Map;
|
||||
import static sun.invoke.util.Wrapper.NumericClasses.*;
|
||||
import jdk.internal.vm.annotation.DontInline;
|
||||
|
||||
import java.lang.constant.ClassDesc;
|
||||
import java.lang.constant.ConstantDescs;
|
||||
|
||||
public enum Wrapper {
|
||||
// wrapperType simple primitiveType simple char emptyArray format numericClass superClass
|
||||
BOOLEAN( Boolean.class, "Boolean", boolean.class, "boolean", 'Z', new boolean[0], Format.unsigned( 1), 0, 0),
|
||||
BOOLEAN( Boolean.class, "Boolean", boolean.class, "boolean", 'Z', new boolean[0], Format.unsigned( 1), 0, 0, ConstantDescs.CD_boolean),
|
||||
// These must be in the order defined for widening primitive conversions in JLS 5.1.2
|
||||
// Avoid boxing integral types here to defer initialization of internal caches
|
||||
BYTE ( Byte.class, "Byte", byte.class, "byte", 'B', new byte[0], Format.signed( 8), BYTE_CLASS, BYTE_SUPERCLASSES),
|
||||
SHORT ( Short.class, "Short", short.class, "short", 'S', new short[0], Format.signed( 16), SHORT_CLASS, SHORT_SUPERCLASSES),
|
||||
CHAR (Character.class, "Character", char.class, "char", 'C', new char[0], Format.unsigned(16), CHAR_CLASS, CHAR_SUPERCLASSES),
|
||||
INT ( Integer.class, "Integer", int.class, "int", 'I', new int[0], Format.signed( 32), INT_CLASS, INT_SUPERCLASSES),
|
||||
LONG ( Long.class, "Long", long.class, "long", 'J', new long[0], Format.signed( 64), LONG_CLASS, LONG_SUPERCLASSES),
|
||||
FLOAT ( Float.class, "Float", float.class, "float", 'F', new float[0], Format.floating(32), FLOAT_CLASS, FLOAT_SUPERCLASSES),
|
||||
DOUBLE ( Double.class, "Double", double.class, "double", 'D', new double[0], Format.floating(64), DOUBLE_CLASS, DOUBLE_CLASS),
|
||||
OBJECT ( Object.class, "Object", Object.class, "Object", 'L', new Object[0], Format.other( 1), 0, 0),
|
||||
BYTE ( Byte.class, "Byte", byte.class, "byte", 'B', new byte[0], Format.signed( 8), BYTE_CLASS, BYTE_SUPERCLASSES, ConstantDescs.CD_byte),
|
||||
SHORT ( Short.class, "Short", short.class, "short", 'S', new short[0], Format.signed( 16), SHORT_CLASS, SHORT_SUPERCLASSES, ConstantDescs.CD_short),
|
||||
CHAR (Character.class, "Character", char.class, "char", 'C', new char[0], Format.unsigned(16), CHAR_CLASS, CHAR_SUPERCLASSES, ConstantDescs.CD_char),
|
||||
INT ( Integer.class, "Integer", int.class, "int", 'I', new int[0], Format.signed( 32), INT_CLASS, INT_SUPERCLASSES, ConstantDescs.CD_int),
|
||||
LONG ( Long.class, "Long", long.class, "long", 'J', new long[0], Format.signed( 64), LONG_CLASS, LONG_SUPERCLASSES, ConstantDescs.CD_long),
|
||||
FLOAT ( Float.class, "Float", float.class, "float", 'F', new float[0], Format.floating(32), FLOAT_CLASS, FLOAT_SUPERCLASSES, ConstantDescs.CD_float),
|
||||
DOUBLE ( Double.class, "Double", double.class, "double", 'D', new double[0], Format.floating(64), DOUBLE_CLASS, DOUBLE_CLASS, ConstantDescs.CD_double),
|
||||
OBJECT ( Object.class, "Object", Object.class, "Object", 'L', new Object[0], Format.other( 1), 0, 0, ConstantDescs.CD_Object),
|
||||
// VOID must be the last type, since it is "assignable" from any other type:
|
||||
VOID ( Void.class, "Void", void.class, "void", 'V', null, Format.other( 0), 0, 0),
|
||||
VOID ( Void.class, "Void", void.class, "void", 'V', null, Format.other( 0), 0, 0, ConstantDescs.CD_void),
|
||||
;
|
||||
|
||||
public static final int COUNT = 10;
|
||||
|
@ -58,8 +60,9 @@ public enum Wrapper {
|
|||
private final int superClasses;
|
||||
private final String wrapperSimpleName;
|
||||
private final String primitiveSimpleName;
|
||||
private final ClassDesc primitiveTypeDesc;
|
||||
|
||||
private Wrapper(Class<?> wtype, String wtypeName, Class<?> ptype, String ptypeName, char tchar, Object emptyArray, int format, int numericClass, int superClasses) {
|
||||
private Wrapper(Class<?> wtype, String wtypeName, Class<?> ptype, String ptypeName, char tchar, Object emptyArray, int format, int numericClass, int superClasses, ClassDesc primitiveTypeDesc) {
|
||||
this.wrapperType = wtype;
|
||||
this.primitiveType = ptype;
|
||||
this.basicTypeChar = tchar;
|
||||
|
@ -70,6 +73,7 @@ public enum Wrapper {
|
|||
this.superClasses = superClasses;
|
||||
this.wrapperSimpleName = wtypeName;
|
||||
this.primitiveSimpleName = ptypeName;
|
||||
this.primitiveTypeDesc = primitiveTypeDesc;
|
||||
}
|
||||
|
||||
/** For debugging, give the details of this wrapper. */
|
||||
|
@ -376,6 +380,9 @@ public enum Wrapper {
|
|||
}
|
||||
}
|
||||
|
||||
/** A nominal descriptor of the primitive type */
|
||||
public ClassDesc primitiveClassDescriptor() { return primitiveTypeDesc; }
|
||||
|
||||
/** What is the primitive type wrapped by this wrapper? */
|
||||
public Class<?> primitiveType() { return primitiveType; }
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue