Permalink
Show file tree
Hide file tree
1 comment
on commit
sign in to comment.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
8261941: Use ClassLoader for unregistered classes during -Xshare:dump
Reviewed-by: iklam, minqi
- Loading branch information
1 parent
7e92abe
commit 12fa7073c58eb9f204bb60ab6192738f8aece626
Showing
10 changed files
with
171 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,115 @@ | ||
/* | ||
* Copyright (c) 2021, 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 | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
* | ||
*/ | ||
|
||
#include "precompiled.hpp" | ||
#include "cds/unregisteredClasses.hpp" | ||
#include "classfile/classFileStream.hpp" | ||
#include "classfile/classLoader.inline.hpp" | ||
#include "classfile/classLoaderExt.hpp" | ||
#include "classfile/javaClasses.inline.hpp" | ||
#include "classfile/symbolTable.hpp" | ||
#include "classfile/systemDictionaryShared.hpp" | ||
#include "classfile/vmSymbols.hpp" | ||
#include "memory/oopFactory.hpp" | ||
#include "memory/resourceArea.hpp" | ||
#include "oops/instanceKlass.hpp" | ||
#include "runtime/handles.hpp" | ||
#include "runtime/javaCalls.hpp" | ||
#include "services/threadService.hpp" | ||
|
||
// Load the class of the given name from the location given by path. The path is specified by | ||
// the "source:" in the class list file (see classListParser.cpp), and can be a directory or | ||
// a JAR file. | ||
InstanceKlass* UnregisteredClasses::load_class(Symbol* name, const char* path, TRAPS) { | ||
assert(name != NULL, "invariant"); | ||
assert(DumpSharedSpaces, "this function is only used with -Xshare:dump"); | ||
|
||
{ | ||
PerfClassTraceTime vmtimer(ClassLoader::perf_sys_class_lookup_time(), | ||
THREAD->get_thread_stat()->perf_timers_addr(), | ||
PerfClassTraceTime::CLASS_LOAD); | ||
} | ||
|
||
Symbol* path_symbol = SymbolTable::new_symbol(path); | ||
Handle url_classloader = get_url_classloader(path_symbol, CHECK_NULL); | ||
Handle ext_class_name = java_lang_String::externalize_classname(name, CHECK_NULL); | ||
|
||
JavaValue result(T_OBJECT); | ||
JavaCallArguments args(2); | ||
args.set_receiver(url_classloader); | ||
args.push_oop(ext_class_name); | ||
args.push_int(JNI_FALSE); | ||
JavaCalls::call_virtual(&result, | ||
vmClasses::URLClassLoader_klass(), | ||
vmSymbols::loadClass_name(), | ||
vmSymbols::string_boolean_class_signature(), | ||
&args, | ||
CHECK_NULL); | ||
assert(result.get_type() == T_OBJECT, "just checking"); | ||
oop obj = result.get_oop(); | ||
return InstanceKlass::cast(java_lang_Class::as_Klass(obj)); | ||
} | ||
|
||
class URLClassLoaderTable : public ResourceHashtable< | ||
Symbol*, Handle, | ||
137, // prime number | ||
ResourceObj::C_HEAP> {}; | ||
|
||
static URLClassLoaderTable* _url_classloader_table = NULL; | ||
|
||
Handle UnregisteredClasses::create_url_classloader(Symbol* path, TRAPS) { | ||
ResourceMark rm(THREAD); | ||
JavaValue result(T_OBJECT); | ||
Handle path_string = java_lang_String::create_from_str(path->as_C_string(), CHECK_NH); | ||
JavaCalls::call_static(&result, | ||
vmClasses::jdk_internal_loader_ClassLoaders_klass(), | ||
vmSymbols::toFileURL_name(), | ||
vmSymbols::toFileURL_signature(), | ||
path_string, CHECK_NH); | ||
assert(result.get_type() == T_OBJECT, "just checking"); | ||
oop url_h = result.get_oop(); | ||
objArrayHandle urls = oopFactory::new_objArray_handle(vmClasses::URL_klass(), 1, CHECK_NH); | ||
urls->obj_at_put(0, url_h); | ||
|
||
Handle url_classloader = JavaCalls::construct_new_instance( | ||
vmClasses::URLClassLoader_klass(), | ||
vmSymbols::url_array_classloader_void_signature(), | ||
urls, Handle(), CHECK_NH); | ||
return url_classloader; | ||
} | ||
|
||
Handle UnregisteredClasses::get_url_classloader(Symbol* path, TRAPS) { | ||
if (_url_classloader_table == NULL) { | ||
_url_classloader_table = new (ResourceObj::C_HEAP, mtClass)URLClassLoaderTable(); | ||
} | ||
Handle* url_classloader_ptr = _url_classloader_table->get(path); | ||
if (url_classloader_ptr != NULL) { | ||
return *url_classloader_ptr; | ||
} else { | ||
Handle url_classloader = create_url_classloader(path, CHECK_NH); | ||
_url_classloader_table->put(path, url_classloader); | ||
path->increment_refcount(); | ||
return url_classloader; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright (c) 2021, 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 | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
* | ||
*/ | ||
|
||
#ifndef SHARE_CDS_UNREGISTEREDCLASSES_HPP | ||
#define SHARE_CDS_UNREGISTEREDCLASSES_HPP | ||
|
||
#include "runtime/handles.hpp" | ||
|
||
class UnregisteredClasses: AllStatic { | ||
public: | ||
static InstanceKlass* load_class(Symbol* h_name, const char* path, TRAPS); | ||
|
||
private: | ||
static Handle create_url_classloader(Symbol* path, TRAPS); | ||
static Handle get_url_classloader(Symbol* path, TRAPS); | ||
}; | ||
|
||
#endif // SHARE_CDS_UNREGISTEREDCLASSES_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
12fa707
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review
Issues