8241958: Slow ClassLoaderReferenceImpl.findType

Optimize ClassLoaderReferenceImpl.findType

Reviewed-by: cjplummer, sspitsyn
This commit is contained in:
Egor Ushakov 2020-04-07 07:24:09 +00:00
parent f5a728af03
commit 76b1119f61
2 changed files with 21 additions and 11 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2020, 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
@ -103,16 +103,22 @@ public class ClassLoaderReferenceImpl extends ObjectReferenceImpl
Type findType(String signature) throws ClassNotLoadedException {
List<ReferenceType> types = visibleClasses();
Iterator<ReferenceType> iter = types.iterator();
while (iter.hasNext()) {
ReferenceType type = iter.next();
// first check already loaded classes and possibly avoid massive signature retrieval later
for (ReferenceType type : vm.classesBySignature(signature)) {
if (types.contains(type)) {
return type;
}
}
for (ReferenceType type : types) {
if (type.signature().equals(signature)) {
return type;
}
}
JNITypeParser parser = new JNITypeParser(signature);
throw new ClassNotLoadedException(parser.typeName(),
"Class " + parser.typeName() + " not loaded");
String typeName = new JNITypeParser(signature).typeName();
throw new ClassNotLoadedException(typeName, "Class " + typeName + " not loaded");
}
byte typeValueKey() {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2020, 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
@ -317,12 +317,16 @@ class VirtualMachineImpl extends MirrorImpl
public List<ReferenceType> classesByName(String className) {
validateVM();
String signature = JNITypeParser.typeNameToSignature(className);
return classesBySignature(JNITypeParser.typeNameToSignature(className));
}
List<ReferenceType> classesBySignature(String signature) {
validateVM();
List<ReferenceType> list;
if (retrievedAllTypes) {
list = findReferenceTypes(signature);
list = findReferenceTypes(signature);
} else {
list = retrieveClassesBySignature(signature);
list = retrieveClassesBySignature(signature);
}
return Collections.unmodifiableList(list);
}