Skip to content
Permalink
Browse files

8241958: Slow ClassLoaderReferenceImpl.findType

Optimize ClassLoaderReferenceImpl.findType

Reviewed-by: cjplummer, sspitsyn
  • Loading branch information
Egor Ushakov committed Apr 7, 2020
1 parent f5a728a commit 76b1119f61536a1b53fd445a1a9c60add1940ae1
@@ -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 @@ protected String description() {

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() {
@@ -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 @@ public int hashCode() {

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);
}

0 comments on commit 76b1119

Please sign in to comment.