mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8331114: Further improve performance of MethodTypeDesc::descriptorString
Reviewed-by: mchung, liach
This commit is contained in:
parent
e3eb652c25
commit
a078b5e611
5 changed files with 33 additions and 15 deletions
|
@ -160,7 +160,7 @@ public sealed interface ClassDesc
|
||||||
static ClassDesc ofDescriptor(String descriptor) {
|
static ClassDesc ofDescriptor(String descriptor) {
|
||||||
// implicit null-check
|
// implicit null-check
|
||||||
return (descriptor.length() == 1)
|
return (descriptor.length() == 1)
|
||||||
? Wrapper.forPrimitiveType(descriptor.charAt(0)).primitiveClassDescriptor()
|
? Wrapper.forPrimitiveType(descriptor.charAt(0)).classDescriptor()
|
||||||
// will throw IAE on descriptor.length == 0 or if array dimensions too long
|
// will throw IAE on descriptor.length == 0 or if array dimensions too long
|
||||||
: new ReferenceClassDescImpl(descriptor);
|
: new ReferenceClassDescImpl(descriptor);
|
||||||
}
|
}
|
||||||
|
|
|
@ -226,7 +226,7 @@ class ConstantUtils {
|
||||||
|
|
||||||
private static ClassDesc resolveClassDesc(String descriptor, int start, int len) {
|
private static ClassDesc resolveClassDesc(String descriptor, int start, int len) {
|
||||||
if (len == 1) {
|
if (len == 1) {
|
||||||
return Wrapper.forBasicType(descriptor.charAt(start)).primitiveClassDescriptor();
|
return Wrapper.forPrimitiveType(descriptor.charAt(start)).classDescriptor();
|
||||||
}
|
}
|
||||||
return ClassDesc.ofDescriptor(descriptor.substring(start, start + len));
|
return ClassDesc.ofDescriptor(descriptor.substring(start, start + len));
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,6 @@ import java.security.PrivilegedAction;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.StringJoiner;
|
|
||||||
|
|
||||||
import static java.util.Objects.requireNonNull;
|
import static java.util.Objects.requireNonNull;
|
||||||
|
|
||||||
|
@ -168,11 +167,17 @@ final class MethodTypeDescImpl implements MethodTypeDesc {
|
||||||
if (desc != null)
|
if (desc != null)
|
||||||
return desc;
|
return desc;
|
||||||
|
|
||||||
var sj = new StringJoiner("", "(", ")" + returnType().descriptorString());
|
int len = 2 + returnType.descriptorString().length();
|
||||||
for (int i = 0; i < parameterCount(); i++) {
|
for (ClassDesc argType : argTypes) {
|
||||||
sj.add(parameterType(i).descriptorString());
|
len += argType.descriptorString().length();
|
||||||
}
|
}
|
||||||
return cachedDescriptorString = sj.toString();
|
StringBuilder sb = new StringBuilder(len).append('(');
|
||||||
|
for (ClassDesc argType : argTypes) {
|
||||||
|
sb.append(argType.descriptorString());
|
||||||
|
}
|
||||||
|
desc = sb.append(')').append(returnType.descriptorString()).toString();
|
||||||
|
cachedDescriptorString = desc;
|
||||||
|
return desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -32,7 +32,7 @@ import java.lang.constant.ClassDesc;
|
||||||
import java.lang.constant.ConstantDescs;
|
import java.lang.constant.ConstantDescs;
|
||||||
|
|
||||||
public enum Wrapper {
|
public enum Wrapper {
|
||||||
// wrapperType simple primitiveType simple char emptyArray format numericClass superClass
|
// wrapperType simple primitiveType simple char emptyArray format numericClass superClass classDescriptor
|
||||||
BOOLEAN( Boolean.class, "Boolean", boolean.class, "boolean", 'Z', new boolean[0], Format.unsigned( 1), 0, 0, ConstantDescs.CD_boolean),
|
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
|
// 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
|
// Avoid boxing integral types here to defer initialization of internal caches
|
||||||
|
@ -60,9 +60,18 @@ public enum Wrapper {
|
||||||
private final int superClasses;
|
private final int superClasses;
|
||||||
private final String wrapperSimpleName;
|
private final String wrapperSimpleName;
|
||||||
private final String primitiveSimpleName;
|
private final String primitiveSimpleName;
|
||||||
private final ClassDesc primitiveTypeDesc;
|
private final ClassDesc classDesc;
|
||||||
|
|
||||||
private Wrapper(Class<?> wtype, String wtypeName, Class<?> ptype, String ptypeName, char tchar, Object emptyArray, int format, int numericClass, int superClasses, ClassDesc primitiveTypeDesc) {
|
private Wrapper(Class<?> wtype,
|
||||||
|
String wtypeName,
|
||||||
|
Class<?> ptype,
|
||||||
|
String ptypeName,
|
||||||
|
char tchar,
|
||||||
|
Object emptyArray,
|
||||||
|
int format,
|
||||||
|
int numericClass,
|
||||||
|
int superClasses,
|
||||||
|
ClassDesc classDesc) {
|
||||||
this.wrapperType = wtype;
|
this.wrapperType = wtype;
|
||||||
this.primitiveType = ptype;
|
this.primitiveType = ptype;
|
||||||
this.basicTypeChar = tchar;
|
this.basicTypeChar = tchar;
|
||||||
|
@ -73,7 +82,7 @@ public enum Wrapper {
|
||||||
this.superClasses = superClasses;
|
this.superClasses = superClasses;
|
||||||
this.wrapperSimpleName = wtypeName;
|
this.wrapperSimpleName = wtypeName;
|
||||||
this.primitiveSimpleName = ptypeName;
|
this.primitiveSimpleName = ptypeName;
|
||||||
this.primitiveTypeDesc = primitiveTypeDesc;
|
this.classDesc = classDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** For debugging, give the details of this wrapper. */
|
/** For debugging, give the details of this wrapper. */
|
||||||
|
@ -380,8 +389,8 @@ public enum Wrapper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** A nominal descriptor of the primitive type */
|
/** A nominal descriptor of the wrapped type */
|
||||||
public ClassDesc primitiveClassDescriptor() { return primitiveTypeDesc; }
|
public ClassDesc classDescriptor() { return classDesc; }
|
||||||
|
|
||||||
/** What is the primitive type wrapped by this wrapper? */
|
/** What is the primitive type wrapped by this wrapper? */
|
||||||
public Class<?> primitiveType() { return primitiveType; }
|
public Class<?> primitiveType() { return primitiveType; }
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -54,11 +54,14 @@ public class MethodTypeDescFactories {
|
||||||
|
|
||||||
private static final ClassDesc DUMMY_CD = ClassDesc.of("Dummy_invalid");
|
private static final ClassDesc DUMMY_CD = ClassDesc.of("Dummy_invalid");
|
||||||
|
|
||||||
|
/** Dots will be replaced by the descriptor of this benchmark class. */
|
||||||
@Param({
|
@Param({
|
||||||
"(Ljava/lang/Object;Ljava/lang/String;)I",
|
"(Ljava/lang/Object;Ljava/lang/String;)I",
|
||||||
"()V",
|
"()V",
|
||||||
"([IJLjava/lang/String;Z)Ljava/util/List;",
|
"([IJLjava/lang/String;Z)Ljava/util/List;",
|
||||||
"()[Ljava/lang/String;"
|
"()[Ljava/lang/String;",
|
||||||
|
"(..IIJ)V",
|
||||||
|
"(.....................)."
|
||||||
})
|
})
|
||||||
public String descString;
|
public String descString;
|
||||||
public MethodTypeDesc desc;
|
public MethodTypeDesc desc;
|
||||||
|
@ -68,6 +71,7 @@ public class MethodTypeDescFactories {
|
||||||
|
|
||||||
@Setup
|
@Setup
|
||||||
public void setup() {
|
public void setup() {
|
||||||
|
descString = descString.replaceAll("\\.", MethodTypeDescFactories.class.descriptorString());
|
||||||
desc = MethodTypeDesc.ofDescriptor(descString);
|
desc = MethodTypeDesc.ofDescriptor(descString);
|
||||||
ret = desc.returnType();
|
ret = desc.returnType();
|
||||||
args = desc.parameterArray();
|
args = desc.parameterArray();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue