2007-12-01 00:00:00 +00:00
|
|
|
/*
|
2018-02-21 11:18:52 -05:00
|
|
|
* Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
|
2007-12-01 00:00:00 +00:00
|
|
|
* 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.
|
|
|
|
*
|
2010-05-27 19:08:38 -07:00
|
|
|
* 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.
|
2007-12-01 00:00:00 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "precompiled.hpp"
|
2017-10-31 11:55:09 -04:00
|
|
|
#include "jvm.h"
|
2016-12-11 19:07:04 -08:00
|
|
|
#include "aot/aotLoader.hpp"
|
2015-12-08 20:04:03 +01:00
|
|
|
#include "classfile/classFileParser.hpp"
|
|
|
|
#include "classfile/classFileStream.hpp"
|
|
|
|
#include "classfile/classLoader.hpp"
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
#include "classfile/classLoaderData.inline.hpp"
|
2018-09-28 16:07:39 -04:00
|
|
|
#include "classfile/classLoaderDataGraph.inline.hpp"
|
2015-12-08 20:04:03 +01:00
|
|
|
#include "classfile/classLoaderExt.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "classfile/dictionary.hpp"
|
2015-02-13 14:37:35 +01:00
|
|
|
#include "classfile/javaClasses.inline.hpp"
|
2015-12-08 20:04:03 +01:00
|
|
|
#include "classfile/klassFactory.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "classfile/loaderConstraints.hpp"
|
8142968: Module System implementation
Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282
Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Mark Reinhold <mark.reinhold@oracle.com>
Co-authored-by: Harold Seigel <harold.seigel@oracle.com>
Co-authored-by: Lois Foltan <lois.foltan@oracle.com>
Co-authored-by: Calvin Cheung <calvin.cheung@oracle.com>
Co-authored-by: Christian Tornqvist <christian.tornqvist@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Co-authored-by: George Triantafillou <george.triantafillou@oracle.com>
Co-authored-by: Igor Ignatyev <igor.ignatyev@oracle.com>
Co-authored-by: Ioi Lam <ioi.lam@oracle.com>
Co-authored-by: James Laskey <james.laskey@oracle.com>
Co-authored-by: Jean-Francois Denise <jean-francois.denise@oracle.com>
Co-authored-by: Jiangli Zhou <jiangli.zhou@oracle.com>
Co-authored-by: Markus Gronlund <markus.gronlund@oracle.com>
Co-authored-by: Serguei Spitsyn <serguei.spitsyn@oracle.com>
Co-authored-by: Staffan Larsen <staffan.larsen@oracle.com>
Co-authored-by: Sundararajan Athijegannathan <sundararajan.athijegannathan@oracle.com>
Reviewed-by: acorn, ccheung, coleenp, ctornqvi, dholmes, dsimms, gtriantafill, iklam, jiangli, mgronlun, mseledtsov, cjplummer, sspitsyn, stefank, twisti, hseigel, lfoltan, alanb, mchung, dfazunen
2016-03-17 19:04:01 +00:00
|
|
|
#include "classfile/packageEntry.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "classfile/placeholders.hpp"
|
2017-07-28 10:48:35 -04:00
|
|
|
#include "classfile/protectionDomainCache.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "classfile/resolutionErrors.hpp"
|
2014-05-07 14:16:45 -05:00
|
|
|
#include "classfile/stringTable.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "classfile/systemDictionary.hpp"
|
|
|
|
#include "classfile/vmSymbols.hpp"
|
2015-01-06 19:30:28 -05:00
|
|
|
#include "code/codeCache.hpp"
|
2012-07-24 10:51:00 -07:00
|
|
|
#include "compiler/compileBroker.hpp"
|
2017-05-27 09:21:01 -04:00
|
|
|
#include "gc/shared/gcTraceTime.inline.hpp"
|
2018-04-10 10:06:42 -04:00
|
|
|
#include "gc/shared/oopStorage.inline.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "interpreter/bytecodeStream.hpp"
|
|
|
|
#include "interpreter/interpreter.hpp"
|
2018-05-15 20:24:34 +02:00
|
|
|
#include "jfr/jfrEvents.hpp"
|
2017-05-27 09:21:01 -04:00
|
|
|
#include "logging/log.hpp"
|
2017-07-21 09:50:12 +02:00
|
|
|
#include "logging/logStream.hpp"
|
2014-08-12 17:29:00 -07:00
|
|
|
#include "memory/filemap.hpp"
|
2018-10-09 15:58:07 -04:00
|
|
|
#include "memory/heapShared.hpp"
|
2017-08-02 18:06:38 -07:00
|
|
|
#include "memory/metaspaceClosure.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "memory/oopFactory.hpp"
|
2016-04-04 12:57:48 -04:00
|
|
|
#include "memory/resourceArea.hpp"
|
2018-03-15 21:24:10 +01:00
|
|
|
#include "oops/access.inline.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "oops/instanceKlass.hpp"
|
|
|
|
#include "oops/instanceRefKlass.hpp"
|
|
|
|
#include "oops/klass.inline.hpp"
|
2018-03-05 10:29:23 -05:00
|
|
|
#include "oops/method.inline.hpp"
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
#include "oops/methodData.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "oops/objArrayKlass.hpp"
|
2015-02-13 14:37:35 +01:00
|
|
|
#include "oops/objArrayOop.inline.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "oops/oop.inline.hpp"
|
8142968: Module System implementation
Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282
Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Mark Reinhold <mark.reinhold@oracle.com>
Co-authored-by: Harold Seigel <harold.seigel@oracle.com>
Co-authored-by: Lois Foltan <lois.foltan@oracle.com>
Co-authored-by: Calvin Cheung <calvin.cheung@oracle.com>
Co-authored-by: Christian Tornqvist <christian.tornqvist@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Co-authored-by: George Triantafillou <george.triantafillou@oracle.com>
Co-authored-by: Igor Ignatyev <igor.ignatyev@oracle.com>
Co-authored-by: Ioi Lam <ioi.lam@oracle.com>
Co-authored-by: James Laskey <james.laskey@oracle.com>
Co-authored-by: Jean-Francois Denise <jean-francois.denise@oracle.com>
Co-authored-by: Jiangli Zhou <jiangli.zhou@oracle.com>
Co-authored-by: Markus Gronlund <markus.gronlund@oracle.com>
Co-authored-by: Serguei Spitsyn <serguei.spitsyn@oracle.com>
Co-authored-by: Staffan Larsen <staffan.larsen@oracle.com>
Co-authored-by: Sundararajan Athijegannathan <sundararajan.athijegannathan@oracle.com>
Reviewed-by: acorn, ccheung, coleenp, ctornqvi, dholmes, dsimms, gtriantafill, iklam, jiangli, mgronlun, mseledtsov, cjplummer, sspitsyn, stefank, twisti, hseigel, lfoltan, alanb, mchung, dfazunen
2016-03-17 19:04:01 +00:00
|
|
|
#include "oops/symbol.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "oops/typeArrayKlass.hpp"
|
2018-10-17 15:57:10 -07:00
|
|
|
#include "prims/jvmtiExport.hpp"
|
2017-05-27 09:21:01 -04:00
|
|
|
#include "prims/resolvedMethodTable.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "prims/methodHandles.hpp"
|
2014-09-10 19:08:17 -07:00
|
|
|
#include "runtime/arguments.hpp"
|
2017-08-28 15:34:04 -07:00
|
|
|
#include "runtime/arguments_ext.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "runtime/biasedLocking.hpp"
|
|
|
|
#include "runtime/fieldType.hpp"
|
|
|
|
#include "runtime/handles.inline.hpp"
|
|
|
|
#include "runtime/java.hpp"
|
|
|
|
#include "runtime/javaCalls.hpp"
|
|
|
|
#include "runtime/mutexLocker.hpp"
|
2018-06-06 10:45:40 -04:00
|
|
|
#include "runtime/orderAccess.hpp"
|
2018-03-15 21:29:36 +01:00
|
|
|
#include "runtime/sharedRuntime.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "runtime/signature.hpp"
|
|
|
|
#include "services/classLoadingService.hpp"
|
2017-08-02 10:52:50 -04:00
|
|
|
#include "services/diagnosticCommand.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "services/threadService.hpp"
|
2013-11-23 12:25:13 +01:00
|
|
|
#include "utilities/macros.hpp"
|
2014-11-11 17:05:33 +01:00
|
|
|
#if INCLUDE_CDS
|
|
|
|
#include "classfile/systemDictionaryShared.hpp"
|
|
|
|
#endif
|
2015-10-08 12:49:30 -10:00
|
|
|
#if INCLUDE_JVMCI
|
|
|
|
#include "jvmci/jvmciRuntime.hpp"
|
|
|
|
#endif
|
2018-08-28 10:10:11 -04:00
|
|
|
#if INCLUDE_JFR
|
|
|
|
#include "jfr/jfr.hpp"
|
|
|
|
#endif
|
2013-06-10 11:30:51 +02:00
|
|
|
|
2010-10-19 02:52:57 -07:00
|
|
|
PlaceholderTable* SystemDictionary::_placeholders = NULL;
|
|
|
|
LoaderConstraintTable* SystemDictionary::_loader_constraints = NULL;
|
|
|
|
ResolutionErrorTable* SystemDictionary::_resolution_errors = NULL;
|
|
|
|
SymbolPropertyTable* SystemDictionary::_invoke_method_table = NULL;
|
2017-07-28 10:48:35 -04:00
|
|
|
ProtectionDomainCacheTable* SystemDictionary::_pd_cache_table = NULL;
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
int SystemDictionary::_number_of_modifications = 0;
|
|
|
|
oop SystemDictionary::_system_loader_lock_obj = NULL;
|
|
|
|
|
2015-10-26 13:11:36 -04:00
|
|
|
InstanceKlass* SystemDictionary::_well_known_klasses[SystemDictionary::WKID_LIMIT]
|
2008-04-29 19:45:22 -07:00
|
|
|
= { NULL /*, NULL...*/ };
|
|
|
|
|
2015-10-26 13:11:36 -04:00
|
|
|
InstanceKlass* SystemDictionary::_box_klasses[T_VOID+1] = { NULL /*, NULL...*/ };
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
oop SystemDictionary::_java_system_loader = NULL;
|
2017-10-10 14:38:56 -07:00
|
|
|
oop SystemDictionary::_java_platform_loader = NULL;
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
bool SystemDictionary::_has_checkPackageAccess = false;
|
|
|
|
|
2017-07-28 10:48:35 -04:00
|
|
|
// Default ProtectionDomainCacheSize value
|
|
|
|
|
|
|
|
const int defaultProtectionDomainCacheSize = 1009;
|
|
|
|
|
2018-04-10 10:06:42 -04:00
|
|
|
OopStorage* SystemDictionary::_vm_weak_oop_storage = NULL;
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2017-10-10 14:38:56 -07:00
|
|
|
// Java-level SystemLoader and PlatformLoader
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
oop SystemDictionary::java_system_loader() {
|
|
|
|
return _java_system_loader;
|
|
|
|
}
|
|
|
|
|
2017-10-10 14:38:56 -07:00
|
|
|
oop SystemDictionary::java_platform_loader() {
|
|
|
|
return _java_platform_loader;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SystemDictionary::compute_java_loaders(TRAPS) {
|
2007-12-01 00:00:00 +00:00
|
|
|
JavaValue result(T_OBJECT);
|
2017-10-10 14:38:56 -07:00
|
|
|
InstanceKlass* class_loader_klass = SystemDictionary::ClassLoader_klass();
|
2007-12-01 00:00:00 +00:00
|
|
|
JavaCalls::call_static(&result,
|
2017-10-10 14:38:56 -07:00
|
|
|
class_loader_klass,
|
2011-01-27 16:11:27 -08:00
|
|
|
vmSymbols::getSystemClassLoader_name(),
|
|
|
|
vmSymbols::void_classloader_signature(),
|
2007-12-01 00:00:00 +00:00
|
|
|
CHECK);
|
|
|
|
|
|
|
|
_java_system_loader = (oop)result.get_jobject();
|
2014-08-12 17:29:00 -07:00
|
|
|
|
2017-10-10 14:38:56 -07:00
|
|
|
JavaCalls::call_static(&result,
|
|
|
|
class_loader_klass,
|
|
|
|
vmSymbols::getPlatformClassLoader_name(),
|
|
|
|
vmSymbols::void_classloader_signature(),
|
|
|
|
CHECK);
|
|
|
|
|
|
|
|
_java_platform_loader = (oop)result.get_jobject();
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2018-03-06 17:15:16 -05:00
|
|
|
ClassLoaderData* SystemDictionary::register_loader(Handle class_loader) {
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
if (class_loader() == NULL) return ClassLoaderData::the_null_class_loader_data();
|
2018-03-06 17:15:16 -05:00
|
|
|
return ClassLoaderDataGraph::find_or_create(class_loader);
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
}
|
|
|
|
|
2009-01-05 13:44:03 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Parallel class loading check
|
|
|
|
|
|
|
|
bool SystemDictionary::is_parallelCapable(Handle class_loader) {
|
2018-02-21 11:18:52 -05:00
|
|
|
if (class_loader.is_null()) return true;
|
2009-01-05 13:44:03 -05:00
|
|
|
if (AlwaysLockClassLoader) return false;
|
2011-09-10 17:29:02 -07:00
|
|
|
return java_lang_ClassLoader::parallelCapable(class_loader());
|
2009-01-05 13:44:03 -05:00
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
2009-11-11 15:49:38 -05:00
|
|
|
// ParallelDefineClass flag does not apply to bootclass loader
|
|
|
|
bool SystemDictionary::is_parallelDefine(Handle class_loader) {
|
|
|
|
if (class_loader.is_null()) return false;
|
2011-09-10 17:29:02 -07:00
|
|
|
if (AllowParallelDefineClass && java_lang_ClassLoader::parallelCapable(class_loader())) {
|
2009-11-11 15:49:38 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2013-03-25 17:13:26 -07:00
|
|
|
|
2016-06-28 10:11:01 -04:00
|
|
|
// Returns true if the passed class loader is the builtin application class loader
|
|
|
|
// or a custom system class loader. A customer system class loader can be
|
|
|
|
// specified via -Djava.system.class.loader.
|
2017-02-15 22:59:57 -05:00
|
|
|
bool SystemDictionary::is_system_class_loader(oop class_loader) {
|
|
|
|
if (class_loader == NULL) {
|
2016-06-28 10:11:01 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return (class_loader->klass() == SystemDictionary::jdk_internal_loader_ClassLoaders_AppClassLoader_klass() ||
|
2018-04-03 13:15:27 +02:00
|
|
|
oopDesc::equals(class_loader, _java_system_loader));
|
2016-06-28 10:11:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Returns true if the passed class loader is the platform class loader.
|
2017-02-15 22:59:57 -05:00
|
|
|
bool SystemDictionary::is_platform_class_loader(oop class_loader) {
|
|
|
|
if (class_loader == NULL) {
|
2013-03-25 17:13:26 -07:00
|
|
|
return false;
|
|
|
|
}
|
8142968: Module System implementation
Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282
Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Mark Reinhold <mark.reinhold@oracle.com>
Co-authored-by: Harold Seigel <harold.seigel@oracle.com>
Co-authored-by: Lois Foltan <lois.foltan@oracle.com>
Co-authored-by: Calvin Cheung <calvin.cheung@oracle.com>
Co-authored-by: Christian Tornqvist <christian.tornqvist@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Co-authored-by: George Triantafillou <george.triantafillou@oracle.com>
Co-authored-by: Igor Ignatyev <igor.ignatyev@oracle.com>
Co-authored-by: Ioi Lam <ioi.lam@oracle.com>
Co-authored-by: James Laskey <james.laskey@oracle.com>
Co-authored-by: Jean-Francois Denise <jean-francois.denise@oracle.com>
Co-authored-by: Jiangli Zhou <jiangli.zhou@oracle.com>
Co-authored-by: Markus Gronlund <markus.gronlund@oracle.com>
Co-authored-by: Serguei Spitsyn <serguei.spitsyn@oracle.com>
Co-authored-by: Staffan Larsen <staffan.larsen@oracle.com>
Co-authored-by: Sundararajan Athijegannathan <sundararajan.athijegannathan@oracle.com>
Reviewed-by: acorn, ccheung, coleenp, ctornqvi, dholmes, dsimms, gtriantafill, iklam, jiangli, mgronlun, mseledtsov, cjplummer, sspitsyn, stefank, twisti, hseigel, lfoltan, alanb, mchung, dfazunen
2016-03-17 19:04:01 +00:00
|
|
|
return (class_loader->klass() == SystemDictionary::jdk_internal_loader_ClassLoaders_PlatformClassLoader_klass());
|
2013-03-25 17:13:26 -07:00
|
|
|
}
|
|
|
|
|
2009-11-11 15:49:38 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
2007-12-01 00:00:00 +00:00
|
|
|
// Resolving of classes
|
|
|
|
|
|
|
|
// Forwards to resolve_or_null
|
|
|
|
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
Klass* SystemDictionary::resolve_or_fail(Symbol* class_name, Handle class_loader, Handle protection_domain, bool throw_error, TRAPS) {
|
|
|
|
Klass* klass = resolve_or_null(class_name, class_loader, protection_domain, THREAD);
|
2007-12-01 00:00:00 +00:00
|
|
|
if (HAS_PENDING_EXCEPTION || klass == NULL) {
|
|
|
|
// can return a null klass
|
2017-03-15 10:25:37 -04:00
|
|
|
klass = handle_resolution_exception(class_name, throw_error, klass, THREAD);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
return klass;
|
|
|
|
}
|
|
|
|
|
2014-05-05 19:53:00 -04:00
|
|
|
Klass* SystemDictionary::handle_resolution_exception(Symbol* class_name,
|
|
|
|
bool throw_error,
|
2017-03-15 10:25:37 -04:00
|
|
|
Klass* klass, TRAPS) {
|
2007-12-01 00:00:00 +00:00
|
|
|
if (HAS_PENDING_EXCEPTION) {
|
|
|
|
// If we have a pending exception we forward it to the caller, unless throw_error is true,
|
|
|
|
// in which case we have to check whether the pending exception is a ClassNotFoundException,
|
|
|
|
// and if so convert it to a NoClassDefFoundError
|
|
|
|
// And chain the original ClassNotFoundException
|
2010-01-06 14:22:39 -08:00
|
|
|
if (throw_error && PENDING_EXCEPTION->is_a(SystemDictionary::ClassNotFoundException_klass())) {
|
2007-12-01 00:00:00 +00:00
|
|
|
ResourceMark rm(THREAD);
|
2017-03-15 10:25:37 -04:00
|
|
|
assert(klass == NULL, "Should not have result with exception pending");
|
2007-12-01 00:00:00 +00:00
|
|
|
Handle e(THREAD, PENDING_EXCEPTION);
|
|
|
|
CLEAR_PENDING_EXCEPTION;
|
2013-01-10 17:38:20 -05:00
|
|
|
THROW_MSG_CAUSE_NULL(vmSymbols::java_lang_NoClassDefFoundError(), class_name->as_C_string(), e);
|
2007-12-01 00:00:00 +00:00
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Class not found, throw appropriate error or exception depending on value of throw_error
|
2017-03-15 10:25:37 -04:00
|
|
|
if (klass == NULL) {
|
2007-12-01 00:00:00 +00:00
|
|
|
ResourceMark rm(THREAD);
|
|
|
|
if (throw_error) {
|
2013-01-10 17:38:20 -05:00
|
|
|
THROW_MSG_NULL(vmSymbols::java_lang_NoClassDefFoundError(), class_name->as_C_string());
|
2007-12-01 00:00:00 +00:00
|
|
|
} else {
|
2013-01-10 17:38:20 -05:00
|
|
|
THROW_MSG_NULL(vmSymbols::java_lang_ClassNotFoundException(), class_name->as_C_string());
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-15 10:25:37 -04:00
|
|
|
return klass;
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
Klass* SystemDictionary::resolve_or_fail(Symbol* class_name,
|
2007-12-01 00:00:00 +00:00
|
|
|
bool throw_error, TRAPS)
|
|
|
|
{
|
|
|
|
return resolve_or_fail(class_name, Handle(), Handle(), throw_error, THREAD);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-07 15:45:07 -07:00
|
|
|
// Forwards to resolve_array_class_or_null or resolve_instance_class_or_null
|
2007-12-01 00:00:00 +00:00
|
|
|
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
Klass* SystemDictionary::resolve_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS) {
|
2011-01-27 16:11:27 -08:00
|
|
|
if (FieldType::is_array(class_name)) {
|
2014-11-12 13:55:59 +01:00
|
|
|
return resolve_array_class_or_null(class_name, class_loader, protection_domain, THREAD);
|
2018-08-07 15:45:07 -07:00
|
|
|
} else {
|
|
|
|
return resolve_instance_class_or_null_helper(class_name, class_loader, protection_domain, THREAD);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// name may be in the form of "java/lang/Object" or "Ljava/lang/Object;"
|
|
|
|
InstanceKlass* SystemDictionary::resolve_instance_class_or_null_helper(Symbol* class_name,
|
|
|
|
Handle class_loader,
|
|
|
|
Handle protection_domain,
|
|
|
|
TRAPS) {
|
|
|
|
assert(class_name != NULL && !FieldType::is_array(class_name), "must be");
|
|
|
|
if (FieldType::is_obj(class_name)) {
|
2011-01-27 16:11:27 -08:00
|
|
|
ResourceMark rm(THREAD);
|
|
|
|
// Ignore wrapping L and ;.
|
|
|
|
TempNewSymbol name = SymbolTable::new_symbol(class_name->as_C_string() + 1,
|
|
|
|
class_name->utf8_length() - 2, CHECK_NULL);
|
2014-11-12 13:55:59 +01:00
|
|
|
return resolve_instance_class_or_null(name, class_loader, protection_domain, THREAD);
|
2007-12-01 00:00:00 +00:00
|
|
|
} else {
|
2014-11-12 13:55:59 +01:00
|
|
|
return resolve_instance_class_or_null(class_name, class_loader, protection_domain, THREAD);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
Klass* SystemDictionary::resolve_or_null(Symbol* class_name, TRAPS) {
|
2007-12-01 00:00:00 +00:00
|
|
|
return resolve_or_null(class_name, Handle(), Handle(), THREAD);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Forwards to resolve_instance_class_or_null
|
|
|
|
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
Klass* SystemDictionary::resolve_array_class_or_null(Symbol* class_name,
|
2017-03-15 10:25:37 -04:00
|
|
|
Handle class_loader,
|
|
|
|
Handle protection_domain,
|
|
|
|
TRAPS) {
|
2011-01-27 16:11:27 -08:00
|
|
|
assert(FieldType::is_array(class_name), "must be array");
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
Klass* k = NULL;
|
2011-01-27 16:11:27 -08:00
|
|
|
FieldArrayInfo fd;
|
|
|
|
// dimension and object_key in FieldArrayInfo are assigned as a side-effect
|
|
|
|
// of this call
|
|
|
|
BasicType t = FieldType::get_array_info(class_name, fd, CHECK_NULL);
|
2007-12-01 00:00:00 +00:00
|
|
|
if (t == T_OBJECT) {
|
|
|
|
// naked oop "k" is OK here -- we assign back into it
|
2011-01-27 16:11:27 -08:00
|
|
|
k = SystemDictionary::resolve_instance_class_or_null(fd.object_key(),
|
2007-12-01 00:00:00 +00:00
|
|
|
class_loader,
|
|
|
|
protection_domain,
|
|
|
|
CHECK_NULL);
|
|
|
|
if (k != NULL) {
|
2012-11-12 16:15:05 -05:00
|
|
|
k = k->array_klass(fd.dimension(), CHECK_NULL);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
k = Universe::typeArrayKlassObj(t);
|
2012-09-29 06:40:00 -04:00
|
|
|
k = TypeArrayKlass::cast(k)->array_klass(fd.dimension(), CHECK_NULL);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
return k;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Must be called for any super-class or super-interface resolution
|
|
|
|
// during class definition to allow class circularity checking
|
|
|
|
// super-interface callers:
|
|
|
|
// parse_interfaces - for defineClass & jvmtiRedefineClasses
|
|
|
|
// super-class callers:
|
|
|
|
// ClassFileParser - for defineClass & jvmtiRedefineClasses
|
|
|
|
// load_shared_class - while loading a class from shared archive
|
2009-01-05 13:44:03 -05:00
|
|
|
// resolve_instance_class_or_null:
|
|
|
|
// via: handle_parallel_super_load
|
2007-12-01 00:00:00 +00:00
|
|
|
// when resolving a class that has an existing placeholder with
|
|
|
|
// a saved superclass [i.e. a defineClass is currently in progress]
|
|
|
|
// if another thread is trying to resolve the class, it must do
|
|
|
|
// super-class checks on its own thread to catch class circularity
|
|
|
|
// This last call is critical in class circularity checking for cases
|
|
|
|
// where classloading is delegated to different threads and the
|
|
|
|
// classloader lock is released.
|
|
|
|
// Take the case: Base->Super->Base
|
|
|
|
// 1. If thread T1 tries to do a defineClass of class Base
|
|
|
|
// resolve_super_or_fail creates placeholder: T1, Base (super Super)
|
|
|
|
// 2. resolve_instance_class_or_null does not find SD or placeholder for Super
|
|
|
|
// so it tries to load Super
|
|
|
|
// 3. If we load the class internally, or user classloader uses same thread
|
|
|
|
// loadClassFromxxx or defineClass via parseClassFile Super ...
|
|
|
|
// 3.1 resolve_super_or_fail creates placeholder: T1, Super (super Base)
|
|
|
|
// 3.3 resolve_instance_class_or_null Base, finds placeholder for Base
|
|
|
|
// 3.4 calls resolve_super_or_fail Base
|
|
|
|
// 3.5 finds T1,Base -> throws class circularity
|
|
|
|
//OR 4. If T2 tries to resolve Super via defineClass Super ...
|
|
|
|
// 4.1 resolve_super_or_fail creates placeholder: T2, Super (super Base)
|
|
|
|
// 4.2 resolve_instance_class_or_null Base, finds placeholder for Base (super Super)
|
|
|
|
// 4.3 calls resolve_super_or_fail Super in parallel on own thread T2
|
|
|
|
// 4.4 finds T2, Super -> throws class circularity
|
|
|
|
// Must be called, even if superclass is null, since this is
|
|
|
|
// where the placeholder entry is created which claims this
|
|
|
|
// thread is loading this class/classloader.
|
2016-07-27 08:31:48 -04:00
|
|
|
// Be careful when modifying this code: once you have run
|
|
|
|
// placeholders()->find_and_add(PlaceholderTable::LOAD_SUPER),
|
|
|
|
// you need to find_and_remove it before returning.
|
|
|
|
// So be careful to not exit with a CHECK_ macro betweeen these calls.
|
2018-08-07 15:45:07 -07:00
|
|
|
InstanceKlass* SystemDictionary::resolve_super_or_fail(Symbol* child_name,
|
|
|
|
Symbol* super_name,
|
|
|
|
Handle class_loader,
|
|
|
|
Handle protection_domain,
|
|
|
|
bool is_superclass,
|
|
|
|
TRAPS) {
|
|
|
|
assert(!FieldType::is_array(super_name), "invalid super class name");
|
2015-08-18 11:27:23 -07:00
|
|
|
#if INCLUDE_CDS
|
|
|
|
if (DumpSharedSpaces) {
|
2018-11-07 19:40:27 -08:00
|
|
|
// Special processing for handling UNREGISTERED shared classes.
|
2018-08-07 15:45:07 -07:00
|
|
|
InstanceKlass* k = SystemDictionaryShared::dump_time_resolve_super_or_fail(child_name,
|
|
|
|
super_name, class_loader, protection_domain, is_superclass, CHECK_NULL);
|
2015-08-18 11:27:23 -07:00
|
|
|
if (k) {
|
|
|
|
return k;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // INCLUDE_CDS
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
// Double-check, if child class is already loaded, just return super-class,interface
|
2017-07-28 10:48:35 -04:00
|
|
|
// Don't add a placedholder if already loaded, i.e. already in appropriate class loader
|
|
|
|
// dictionary.
|
2007-12-01 00:00:00 +00:00
|
|
|
// Make sure there's a placeholder for the *child* before resolving.
|
|
|
|
// Used as a claim that this thread is currently loading superclass/classloader
|
|
|
|
// Used here for ClassCircularity checks and also for heap verification
|
2017-07-28 10:48:35 -04:00
|
|
|
// (every InstanceKlass needs to be in its class loader dictionary or have a placeholder).
|
|
|
|
// Must check ClassCircularity before checking if super class is already loaded.
|
2007-12-01 00:00:00 +00:00
|
|
|
//
|
|
|
|
// We might not already have a placeholder if this child_name was
|
|
|
|
// first seen via resolve_from_stream (jni_DefineClass or JVM_DefineClass);
|
|
|
|
// the name of the class might not be known until the stream is actually
|
|
|
|
// parsed.
|
|
|
|
// Bugs 4643874, 4715493
|
|
|
|
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
ClassLoaderData* loader_data = class_loader_data(class_loader);
|
2017-07-28 10:48:35 -04:00
|
|
|
Dictionary* dictionary = loader_data->dictionary();
|
|
|
|
unsigned int d_hash = dictionary->compute_hash(child_name);
|
|
|
|
unsigned int p_hash = placeholders()->compute_hash(child_name);
|
2007-12-01 00:00:00 +00:00
|
|
|
int p_index = placeholders()->hash_to_index(p_hash);
|
|
|
|
// can't throw error holding a lock
|
|
|
|
bool child_already_loaded = false;
|
|
|
|
bool throw_circularity_error = false;
|
|
|
|
{
|
|
|
|
MutexLocker mu(SystemDictionary_lock, THREAD);
|
2018-08-07 15:45:07 -07:00
|
|
|
InstanceKlass* childk = find_class(d_hash, child_name, dictionary);
|
|
|
|
InstanceKlass* quicksuperk;
|
2007-12-01 00:00:00 +00:00
|
|
|
// to support // loading: if child done loading, just return superclass
|
2018-08-07 15:45:07 -07:00
|
|
|
// if super_name, & class_loader don't match:
|
2007-12-01 00:00:00 +00:00
|
|
|
// if initial define, SD update will give LinkageError
|
|
|
|
// if redefine: compare_class_versions will give HIERARCHY_CHANGED
|
|
|
|
// so we don't throw an exception here.
|
|
|
|
// see: nsk redefclass014 & java.lang.instrument Instrument032
|
|
|
|
if ((childk != NULL ) && (is_superclass) &&
|
2018-08-07 15:45:07 -07:00
|
|
|
((quicksuperk = childk->java_super()) != NULL) &&
|
|
|
|
((quicksuperk->name() == super_name) &&
|
2018-04-03 13:15:27 +02:00
|
|
|
(oopDesc::equals(quicksuperk->class_loader(), class_loader())))) {
|
2007-12-01 00:00:00 +00:00
|
|
|
return quicksuperk;
|
|
|
|
} else {
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
PlaceholderEntry* probe = placeholders()->get_entry(p_index, p_hash, child_name, loader_data);
|
2007-12-01 00:00:00 +00:00
|
|
|
if (probe && probe->check_seen_thread(THREAD, PlaceholderTable::LOAD_SUPER)) {
|
|
|
|
throw_circularity_error = true;
|
|
|
|
}
|
2009-01-05 13:44:03 -05:00
|
|
|
}
|
|
|
|
if (!throw_circularity_error) {
|
2016-07-27 08:31:48 -04:00
|
|
|
// Be careful not to exit resolve_super
|
2018-08-07 15:45:07 -07:00
|
|
|
PlaceholderEntry* newprobe = placeholders()->find_and_add(p_index, p_hash, child_name, loader_data, PlaceholderTable::LOAD_SUPER, super_name, THREAD);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (throw_circularity_error) {
|
|
|
|
ResourceMark rm(THREAD);
|
2013-01-10 17:38:20 -05:00
|
|
|
THROW_MSG_NULL(vmSymbols::java_lang_ClassCircularityError(), child_name->as_C_string());
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// java.lang.Object should have been found above
|
2018-08-07 15:45:07 -07:00
|
|
|
assert(super_name != NULL, "null super class for resolving");
|
2007-12-01 00:00:00 +00:00
|
|
|
// Resolve the super class or interface, check results on return
|
2018-08-07 15:45:07 -07:00
|
|
|
InstanceKlass* superk =
|
|
|
|
SystemDictionary::resolve_instance_class_or_null_helper(super_name,
|
|
|
|
class_loader,
|
|
|
|
protection_domain,
|
|
|
|
THREAD);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2013-01-10 17:38:20 -05:00
|
|
|
// Clean up of placeholders moved so that each classloadAction registrar self-cleans up
|
|
|
|
// It is no longer necessary to keep the placeholder table alive until update_dictionary
|
|
|
|
// or error. GC used to walk the placeholder table as strong roots.
|
|
|
|
// The instanceKlass is kept alive because the class loader is on the stack,
|
|
|
|
// which keeps the loader_data alive, as well as all instanceKlasses in
|
|
|
|
// the loader_data. parseClassFile adds the instanceKlass to loader_data.
|
2007-12-01 00:00:00 +00:00
|
|
|
{
|
2013-01-10 17:38:20 -05:00
|
|
|
MutexLocker mu(SystemDictionary_lock, THREAD);
|
|
|
|
placeholders()->find_and_remove(p_index, p_hash, child_name, loader_data, PlaceholderTable::LOAD_SUPER, THREAD);
|
|
|
|
SystemDictionary_lock->notify_all();
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
2017-03-15 10:25:37 -04:00
|
|
|
if (HAS_PENDING_EXCEPTION || superk == NULL) {
|
2007-12-01 00:00:00 +00:00
|
|
|
// can null superk
|
2018-08-07 15:45:07 -07:00
|
|
|
Klass* k = handle_resolution_exception(super_name, true, superk, THREAD);
|
|
|
|
assert(k == NULL || k == superk, "must be");
|
|
|
|
if (k == NULL) {
|
|
|
|
superk = NULL;
|
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2017-03-15 10:25:37 -04:00
|
|
|
return superk;
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2017-03-15 10:25:37 -04:00
|
|
|
void SystemDictionary::validate_protection_domain(InstanceKlass* klass,
|
2007-12-01 00:00:00 +00:00
|
|
|
Handle class_loader,
|
|
|
|
Handle protection_domain,
|
|
|
|
TRAPS) {
|
|
|
|
if(!has_checkPackageAccess()) return;
|
|
|
|
|
|
|
|
// Now we have to call back to java to check if the initating class has access
|
|
|
|
JavaValue result(T_VOID);
|
2017-07-21 09:50:12 +02:00
|
|
|
LogTarget(Debug, protectiondomain) lt;
|
|
|
|
if (lt.is_enabled()) {
|
2016-02-29 16:58:09 -05:00
|
|
|
ResourceMark rm;
|
2007-12-01 00:00:00 +00:00
|
|
|
// Print out trace information
|
2017-07-21 09:50:12 +02:00
|
|
|
LogStream ls(lt);
|
|
|
|
ls.print_cr("Checking package access");
|
2018-07-31 14:24:10 -04:00
|
|
|
if (class_loader() != NULL) {
|
|
|
|
ls.print("class loader: ");
|
|
|
|
class_loader()->print_value_on(&ls);
|
|
|
|
} else {
|
|
|
|
ls.print_cr("class loader: NULL");
|
|
|
|
}
|
|
|
|
if (protection_domain() != NULL) {
|
|
|
|
ls.print(" protection domain: ");
|
|
|
|
protection_domain()->print_value_on(&ls);
|
|
|
|
} else {
|
|
|
|
ls.print_cr(" protection domain: NULL");
|
|
|
|
}
|
2017-07-21 09:50:12 +02:00
|
|
|
ls.print(" loading: "); klass->print_value_on(&ls);
|
|
|
|
ls.cr();
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2017-07-28 10:48:35 -04:00
|
|
|
// This handle and the class_loader handle passed in keeps this class from
|
|
|
|
// being unloaded through several GC points.
|
|
|
|
// The class_loader handle passed in is the initiating loader.
|
|
|
|
Handle mirror(THREAD, klass->java_mirror());
|
|
|
|
|
2017-03-15 10:25:37 -04:00
|
|
|
InstanceKlass* system_loader = SystemDictionary::ClassLoader_klass();
|
2007-12-01 00:00:00 +00:00
|
|
|
JavaCalls::call_special(&result,
|
|
|
|
class_loader,
|
|
|
|
system_loader,
|
2011-01-27 16:11:27 -08:00
|
|
|
vmSymbols::checkPackageAccess_name(),
|
|
|
|
vmSymbols::class_protectiondomain_signature(),
|
2017-07-28 10:48:35 -04:00
|
|
|
mirror,
|
2007-12-01 00:00:00 +00:00
|
|
|
protection_domain,
|
|
|
|
THREAD);
|
|
|
|
|
2016-02-29 16:58:09 -05:00
|
|
|
if (HAS_PENDING_EXCEPTION) {
|
|
|
|
log_debug(protectiondomain)("DENIED !!!!!!!!!!!!!!!!!!!!!");
|
|
|
|
} else {
|
|
|
|
log_debug(protectiondomain)("granted");
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (HAS_PENDING_EXCEPTION) return;
|
|
|
|
|
|
|
|
// If no exception has been thrown, we have validated the protection domain
|
|
|
|
// Insert the protection domain of the initiating class into the set.
|
|
|
|
{
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
ClassLoaderData* loader_data = class_loader_data(class_loader);
|
2017-07-28 10:48:35 -04:00
|
|
|
Dictionary* dictionary = loader_data->dictionary();
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
|
2011-01-27 16:11:27 -08:00
|
|
|
Symbol* kn = klass->name();
|
2017-07-28 10:48:35 -04:00
|
|
|
unsigned int d_hash = dictionary->compute_hash(kn);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
MutexLocker mu(SystemDictionary_lock, THREAD);
|
2017-11-02 11:00:34 -05:00
|
|
|
int d_index = dictionary->hash_to_index(d_hash);
|
2017-07-28 10:48:35 -04:00
|
|
|
dictionary->add_protection_domain(d_index, d_hash, klass,
|
|
|
|
protection_domain, THREAD);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We only get here if this thread finds that another thread
|
|
|
|
// has already claimed the placeholder token for the current operation,
|
|
|
|
// but that other thread either never owned or gave up the
|
|
|
|
// object lock
|
|
|
|
// Waits on SystemDictionary_lock to indicate placeholder table updated
|
|
|
|
// On return, caller must recheck placeholder table state
|
|
|
|
//
|
|
|
|
// We only get here if
|
|
|
|
// 1) custom classLoader, i.e. not bootstrap classloader
|
2018-02-21 11:18:52 -05:00
|
|
|
// 2) custom classLoader has broken the class loader objectLock
|
2007-12-01 00:00:00 +00:00
|
|
|
// so another thread got here in parallel
|
|
|
|
//
|
|
|
|
// lockObject must be held.
|
|
|
|
// Complicated dance due to lock ordering:
|
|
|
|
// Must first release the classloader object lock to
|
|
|
|
// allow initial definer to complete the class definition
|
|
|
|
// and to avoid deadlock
|
|
|
|
// Reclaim classloader lock object with same original recursion count
|
|
|
|
// Must release SystemDictionary_lock after notify, since
|
|
|
|
// class loader lock must be claimed before SystemDictionary_lock
|
|
|
|
// to prevent deadlocks
|
|
|
|
//
|
|
|
|
// The notify allows applications that did an untimed wait() on
|
|
|
|
// the classloader object lock to not hang.
|
|
|
|
void SystemDictionary::double_lock_wait(Handle lockObject, TRAPS) {
|
|
|
|
assert_lock_strong(SystemDictionary_lock);
|
|
|
|
|
|
|
|
bool calledholdinglock
|
|
|
|
= ObjectSynchronizer::current_thread_holds_lock((JavaThread*)THREAD, lockObject);
|
|
|
|
assert(calledholdinglock,"must hold lock for notify");
|
2018-04-03 13:15:27 +02:00
|
|
|
assert((!oopDesc::equals(lockObject(), _system_loader_lock_obj) && !is_parallelCapable(lockObject)), "unexpected double_lock_wait");
|
2007-12-01 00:00:00 +00:00
|
|
|
ObjectSynchronizer::notifyall(lockObject, THREAD);
|
|
|
|
intptr_t recursions = ObjectSynchronizer::complete_exit(lockObject, THREAD);
|
|
|
|
SystemDictionary_lock->wait();
|
|
|
|
SystemDictionary_lock->unlock();
|
|
|
|
ObjectSynchronizer::reenter(lockObject, recursions, THREAD);
|
|
|
|
SystemDictionary_lock->lock();
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the class in is in the placeholder table, class loading is in progress
|
|
|
|
// For cases where the application changes threads to load classes, it
|
|
|
|
// is critical to ClassCircularity detection that we try loading
|
|
|
|
// the superclass on the same thread internally, so we do parallel
|
|
|
|
// super class loading here.
|
|
|
|
// This also is critical in cases where the original thread gets stalled
|
|
|
|
// even in non-circularity situations.
|
|
|
|
// Note: must call resolve_super_or_fail even if null super -
|
2009-01-05 13:44:03 -05:00
|
|
|
// to force placeholder entry creation for this class for circularity detection
|
2007-12-01 00:00:00 +00:00
|
|
|
// Caller must check for pending exception
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
// Returns non-null Klass* if other thread has completed load
|
2007-12-01 00:00:00 +00:00
|
|
|
// and we are done,
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
// If return null Klass* and no pending exception, the caller must load the class
|
2017-03-15 10:25:37 -04:00
|
|
|
InstanceKlass* SystemDictionary::handle_parallel_super_load(
|
2011-01-27 16:11:27 -08:00
|
|
|
Symbol* name, Symbol* superclassname, Handle class_loader,
|
2007-12-01 00:00:00 +00:00
|
|
|
Handle protection_domain, Handle lockObject, TRAPS) {
|
|
|
|
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
ClassLoaderData* loader_data = class_loader_data(class_loader);
|
2017-07-28 10:48:35 -04:00
|
|
|
Dictionary* dictionary = loader_data->dictionary();
|
|
|
|
unsigned int d_hash = dictionary->compute_hash(name);
|
|
|
|
unsigned int p_hash = placeholders()->compute_hash(name);
|
2007-12-01 00:00:00 +00:00
|
|
|
int p_index = placeholders()->hash_to_index(p_hash);
|
|
|
|
|
|
|
|
// superk is not used, resolve_super called for circularity check only
|
|
|
|
// This code is reached in two situations. One if this thread
|
|
|
|
// is loading the same class twice (e.g. ClassCircularity, or
|
|
|
|
// java.lang.instrument).
|
|
|
|
// The second is if another thread started the resolve_super first
|
|
|
|
// and has not yet finished.
|
|
|
|
// In both cases the original caller will clean up the placeholder
|
|
|
|
// entry on error.
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
Klass* superk = SystemDictionary::resolve_super_or_fail(name,
|
2007-12-01 00:00:00 +00:00
|
|
|
superclassname,
|
|
|
|
class_loader,
|
|
|
|
protection_domain,
|
|
|
|
true,
|
2017-03-15 10:25:37 -04:00
|
|
|
CHECK_NULL);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2009-01-05 13:44:03 -05:00
|
|
|
// parallelCapable class loaders do NOT wait for parallel superclass loads to complete
|
|
|
|
// Serial class loaders and bootstrap classloader do wait for superclass loads
|
|
|
|
if (!class_loader.is_null() && is_parallelCapable(class_loader)) {
|
2007-12-01 00:00:00 +00:00
|
|
|
MutexLocker mu(SystemDictionary_lock, THREAD);
|
|
|
|
// Check if classloading completed while we were loading superclass or waiting
|
2017-11-02 11:00:34 -05:00
|
|
|
return find_class(d_hash, name, dictionary);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// must loop to both handle other placeholder updates
|
|
|
|
// and spurious notifications
|
|
|
|
bool super_load_in_progress = true;
|
|
|
|
PlaceholderEntry* placeholder;
|
|
|
|
while (super_load_in_progress) {
|
|
|
|
MutexLocker mu(SystemDictionary_lock, THREAD);
|
|
|
|
// Check if classloading completed while we were loading superclass or waiting
|
2017-11-02 11:00:34 -05:00
|
|
|
InstanceKlass* check = find_class(d_hash, name, dictionary);
|
2007-12-01 00:00:00 +00:00
|
|
|
if (check != NULL) {
|
|
|
|
// Klass is already loaded, so just return it
|
2017-03-15 10:25:37 -04:00
|
|
|
return check;
|
2007-12-01 00:00:00 +00:00
|
|
|
} else {
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
placeholder = placeholders()->get_entry(p_index, p_hash, name, loader_data);
|
2007-12-01 00:00:00 +00:00
|
|
|
if (placeholder && placeholder->super_load_in_progress() ){
|
|
|
|
// We only get here if the application has released the
|
|
|
|
// classloader lock when another thread was in the middle of loading a
|
|
|
|
// superclass/superinterface for this class, and now
|
|
|
|
// this thread is also trying to load this class.
|
|
|
|
// To minimize surprises, the first thread that started to
|
|
|
|
// load a class should be the one to complete the loading
|
|
|
|
// with the classfile it initially expected.
|
|
|
|
// This logic has the current thread wait once it has done
|
|
|
|
// all the superclass/superinterface loading it can, until
|
|
|
|
// the original thread completes the class loading or fails
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
// If it completes we will use the resulting InstanceKlass
|
2007-12-01 00:00:00 +00:00
|
|
|
// which we will find below in the systemDictionary.
|
|
|
|
// We also get here for parallel bootstrap classloader
|
|
|
|
if (class_loader.is_null()) {
|
|
|
|
SystemDictionary_lock->wait();
|
|
|
|
} else {
|
|
|
|
double_lock_wait(lockObject, THREAD);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// If not in SD and not in PH, other thread's load must have failed
|
|
|
|
super_load_in_progress = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-03-15 10:25:37 -04:00
|
|
|
return NULL;
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2018-05-15 20:24:34 +02:00
|
|
|
static void post_class_load_event(EventClassLoad* event, const InstanceKlass* k, const ClassLoaderData* init_cld) {
|
2017-08-28 00:20:35 +02:00
|
|
|
assert(event != NULL, "invariant");
|
|
|
|
assert(k != NULL, "invariant");
|
2018-05-15 20:24:34 +02:00
|
|
|
assert(event->should_commit(), "invariant");
|
|
|
|
event->set_loadedClass(k);
|
|
|
|
event->set_definingClassLoader(k->class_loader_data());
|
|
|
|
event->set_initiatingClassLoader(init_cld);
|
|
|
|
event->commit();
|
2015-12-08 20:04:03 +01:00
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2016-07-25 09:40:31 -04:00
|
|
|
|
2016-07-27 08:31:48 -04:00
|
|
|
// Be careful when modifying this code: once you have run
|
|
|
|
// placeholders()->find_and_add(PlaceholderTable::LOAD_INSTANCE),
|
|
|
|
// you need to find_and_remove it before returning.
|
|
|
|
// So be careful to not exit with a CHECK_ macro betweeen these calls.
|
2018-08-07 15:45:07 -07:00
|
|
|
//
|
|
|
|
// name must be in the form of "java/lang/Object" -- cannot be "Ljava/lang/Object;"
|
|
|
|
InstanceKlass* SystemDictionary::resolve_instance_class_or_null(Symbol* name,
|
|
|
|
Handle class_loader,
|
|
|
|
Handle protection_domain,
|
|
|
|
TRAPS) {
|
2011-01-27 16:11:27 -08:00
|
|
|
assert(name != NULL && !FieldType::is_array(name) &&
|
|
|
|
!FieldType::is_obj(name), "invalid class name");
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2017-08-28 00:20:35 +02:00
|
|
|
EventClassLoad class_load_start_event;
|
2013-06-10 11:30:51 +02:00
|
|
|
|
2017-02-15 22:59:57 -05:00
|
|
|
HandleMark hm(THREAD);
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
// Fix for 4474172; see evaluation for more details
|
|
|
|
class_loader = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader()));
|
2018-03-06 17:15:16 -05:00
|
|
|
ClassLoaderData* loader_data = register_loader(class_loader);
|
2017-07-28 10:48:35 -04:00
|
|
|
Dictionary* dictionary = loader_data->dictionary();
|
2017-11-02 11:00:34 -05:00
|
|
|
unsigned int d_hash = dictionary->compute_hash(name);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// Do lookup to see if class already exist and the protection domain
|
|
|
|
// has the right access
|
2013-01-10 17:38:20 -05:00
|
|
|
// This call uses find which checks protection domain already matches
|
|
|
|
// All subsequent calls use find_class, and set has_loaded_class so that
|
|
|
|
// before we return a result we call out to java to check for valid protection domain
|
|
|
|
// to allow returning the Klass* and add it to the pd_set if it is valid
|
2017-11-02 11:00:34 -05:00
|
|
|
{
|
2018-08-07 15:45:07 -07:00
|
|
|
InstanceKlass* probe = dictionary->find(d_hash, name, protection_domain);
|
2017-11-02 11:00:34 -05:00
|
|
|
if (probe != NULL) return probe;
|
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// Non-bootstrap class loaders will call out to class loader and
|
|
|
|
// define via jvm/jni_DefineClass which will acquire the
|
|
|
|
// class loader object lock to protect against multiple threads
|
|
|
|
// defining the class in parallel by accident.
|
|
|
|
// This lock must be acquired here so the waiter will find
|
|
|
|
// any successful result in the SystemDictionary and not attempt
|
2018-02-21 11:18:52 -05:00
|
|
|
// the define.
|
|
|
|
// ParallelCapable Classloaders and the bootstrap classloader
|
|
|
|
// do not acquire lock here.
|
2007-12-01 00:00:00 +00:00
|
|
|
bool DoObjectLock = true;
|
2009-01-05 13:44:03 -05:00
|
|
|
if (is_parallelCapable(class_loader)) {
|
2007-12-01 00:00:00 +00:00
|
|
|
DoObjectLock = false;
|
|
|
|
}
|
|
|
|
|
2017-07-28 10:48:35 -04:00
|
|
|
unsigned int p_hash = placeholders()->compute_hash(name);
|
2007-12-01 00:00:00 +00:00
|
|
|
int p_index = placeholders()->hash_to_index(p_hash);
|
|
|
|
|
|
|
|
// Class is not in SystemDictionary so we have to do loading.
|
|
|
|
// Make sure we are synchronized on the class loader before we proceed
|
|
|
|
Handle lockObject = compute_loader_lock_object(class_loader, THREAD);
|
|
|
|
check_loader_lock_contention(lockObject, THREAD);
|
|
|
|
ObjectLocker ol(lockObject, THREAD, DoObjectLock);
|
|
|
|
|
|
|
|
// Check again (after locking) if class already exist in SystemDictionary
|
|
|
|
bool class_has_been_loaded = false;
|
|
|
|
bool super_load_in_progress = false;
|
|
|
|
bool havesupername = false;
|
2017-03-15 10:25:37 -04:00
|
|
|
InstanceKlass* k = NULL;
|
2007-12-01 00:00:00 +00:00
|
|
|
PlaceholderEntry* placeholder;
|
2011-01-27 16:11:27 -08:00
|
|
|
Symbol* superclassname = NULL;
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2018-06-23 01:32:41 -04:00
|
|
|
assert(THREAD->can_call_java(),
|
|
|
|
"can not load classes with compiler thread: class=%s, classloader=%s",
|
|
|
|
name->as_C_string(),
|
|
|
|
class_loader.is_null() ? "null" : class_loader->klass()->name()->as_C_string());
|
2007-12-01 00:00:00 +00:00
|
|
|
{
|
|
|
|
MutexLocker mu(SystemDictionary_lock, THREAD);
|
2017-11-02 11:00:34 -05:00
|
|
|
InstanceKlass* check = find_class(d_hash, name, dictionary);
|
2007-12-01 00:00:00 +00:00
|
|
|
if (check != NULL) {
|
2018-08-07 15:45:07 -07:00
|
|
|
// InstanceKlass is already loaded, so just return it
|
2007-12-01 00:00:00 +00:00
|
|
|
class_has_been_loaded = true;
|
2017-03-15 10:25:37 -04:00
|
|
|
k = check;
|
2007-12-01 00:00:00 +00:00
|
|
|
} else {
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
placeholder = placeholders()->get_entry(p_index, p_hash, name, loader_data);
|
2007-12-01 00:00:00 +00:00
|
|
|
if (placeholder && placeholder->super_load_in_progress()) {
|
|
|
|
super_load_in_progress = true;
|
|
|
|
if (placeholder->havesupername() == true) {
|
2011-01-27 16:11:27 -08:00
|
|
|
superclassname = placeholder->supername();
|
2007-12-01 00:00:00 +00:00
|
|
|
havesupername = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-10 17:38:20 -05:00
|
|
|
// If the class is in the placeholder table, class loading is in progress
|
2007-12-01 00:00:00 +00:00
|
|
|
if (super_load_in_progress && havesupername==true) {
|
2017-03-15 10:25:37 -04:00
|
|
|
k = handle_parallel_super_load(name,
|
|
|
|
superclassname,
|
|
|
|
class_loader,
|
|
|
|
protection_domain,
|
|
|
|
lockObject, THREAD);
|
2007-12-01 00:00:00 +00:00
|
|
|
if (HAS_PENDING_EXCEPTION) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2017-03-15 10:25:37 -04:00
|
|
|
if (k != NULL) {
|
2007-12-01 00:00:00 +00:00
|
|
|
class_has_been_loaded = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-10 17:38:20 -05:00
|
|
|
bool throw_circularity_error = false;
|
2007-12-01 00:00:00 +00:00
|
|
|
if (!class_has_been_loaded) {
|
2013-01-10 17:38:20 -05:00
|
|
|
bool load_instance_added = false;
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// add placeholder entry to record loading instance class
|
|
|
|
// Five cases:
|
|
|
|
// All cases need to prevent modifying bootclasssearchpath
|
|
|
|
// in parallel with a classload of same classname
|
2009-01-05 13:44:03 -05:00
|
|
|
// Redefineclasses uses existence of the placeholder for the duration
|
|
|
|
// of the class load to prevent concurrent redefinition of not completely
|
|
|
|
// defined classes.
|
2007-12-01 00:00:00 +00:00
|
|
|
// case 1. traditional classloaders that rely on the classloader object lock
|
|
|
|
// - no other need for LOAD_INSTANCE
|
|
|
|
// case 2. traditional classloaders that break the classloader object lock
|
|
|
|
// as a deadlock workaround. Detection of this case requires that
|
|
|
|
// this check is done while holding the classloader object lock,
|
|
|
|
// and that lock is still held when calling classloader's loadClass.
|
|
|
|
// For these classloaders, we ensure that the first requestor
|
|
|
|
// completes the load and other requestors wait for completion.
|
2018-02-21 11:18:52 -05:00
|
|
|
// case 3. Bootstrap classloader - don't own objectLocker
|
2007-12-01 00:00:00 +00:00
|
|
|
// This classloader supports parallelism at the classloader level,
|
|
|
|
// but only allows a single load of a class/classloader pair.
|
|
|
|
// No performance benefit and no deadlock issues.
|
2018-02-21 11:18:52 -05:00
|
|
|
// case 4. parallelCapable user level classloaders - without objectLocker
|
2009-01-05 13:44:03 -05:00
|
|
|
// Allow parallel classloading of a class/classloader pair
|
2013-01-10 17:38:20 -05:00
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
{
|
|
|
|
MutexLocker mu(SystemDictionary_lock, THREAD);
|
2009-01-05 13:44:03 -05:00
|
|
|
if (class_loader.is_null() || !is_parallelCapable(class_loader)) {
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
PlaceholderEntry* oldprobe = placeholders()->get_entry(p_index, p_hash, name, loader_data);
|
2007-12-01 00:00:00 +00:00
|
|
|
if (oldprobe) {
|
|
|
|
// only need check_seen_thread once, not on each loop
|
|
|
|
// 6341374 java/lang/Instrument with -Xcomp
|
|
|
|
if (oldprobe->check_seen_thread(THREAD, PlaceholderTable::LOAD_INSTANCE)) {
|
|
|
|
throw_circularity_error = true;
|
|
|
|
} else {
|
|
|
|
// case 1: traditional: should never see load_in_progress.
|
|
|
|
while (!class_has_been_loaded && oldprobe && oldprobe->instance_load_in_progress()) {
|
|
|
|
|
2018-02-21 11:18:52 -05:00
|
|
|
// case 3: bootstrap classloader: prevent futile classloading,
|
2007-12-01 00:00:00 +00:00
|
|
|
// wait on first requestor
|
|
|
|
if (class_loader.is_null()) {
|
|
|
|
SystemDictionary_lock->wait();
|
|
|
|
} else {
|
|
|
|
// case 2: traditional with broken classloader lock. wait on first
|
|
|
|
// requestor.
|
|
|
|
double_lock_wait(lockObject, THREAD);
|
|
|
|
}
|
|
|
|
// Check if classloading completed while we were waiting
|
2017-11-02 11:00:34 -05:00
|
|
|
InstanceKlass* check = find_class(d_hash, name, dictionary);
|
2007-12-01 00:00:00 +00:00
|
|
|
if (check != NULL) {
|
|
|
|
// Klass is already loaded, so just return it
|
2017-03-15 10:25:37 -04:00
|
|
|
k = check;
|
2007-12-01 00:00:00 +00:00
|
|
|
class_has_been_loaded = true;
|
|
|
|
}
|
|
|
|
// check if other thread failed to load and cleaned up
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
oldprobe = placeholders()->get_entry(p_index, p_hash, name, loader_data);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-01-10 17:38:20 -05:00
|
|
|
// All cases: add LOAD_INSTANCE holding SystemDictionary_lock
|
2018-02-21 11:18:52 -05:00
|
|
|
// case 4: parallelCapable: allow competing threads to try
|
2007-12-01 00:00:00 +00:00
|
|
|
// LOAD_INSTANCE in parallel
|
2013-01-10 17:38:20 -05:00
|
|
|
|
2009-01-05 13:44:03 -05:00
|
|
|
if (!throw_circularity_error && !class_has_been_loaded) {
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
PlaceholderEntry* newprobe = placeholders()->find_and_add(p_index, p_hash, name, loader_data, PlaceholderTable::LOAD_INSTANCE, NULL, THREAD);
|
2013-01-10 17:38:20 -05:00
|
|
|
load_instance_added = true;
|
2007-12-01 00:00:00 +00:00
|
|
|
// For class loaders that do not acquire the classloader object lock,
|
|
|
|
// if they did not catch another thread holding LOAD_INSTANCE,
|
|
|
|
// need a check analogous to the acquire ObjectLocker/find_class
|
|
|
|
// i.e. now that we hold the LOAD_INSTANCE token on loading this class/CL
|
|
|
|
// one final check if the load has already completed
|
2009-01-05 13:44:03 -05:00
|
|
|
// class loaders holding the ObjectLock shouldn't find the class here
|
2017-11-02 11:00:34 -05:00
|
|
|
InstanceKlass* check = find_class(d_hash, name, dictionary);
|
2007-12-01 00:00:00 +00:00
|
|
|
if (check != NULL) {
|
2013-01-10 17:38:20 -05:00
|
|
|
// Klass is already loaded, so return it after checking/adding protection domain
|
2017-03-15 10:25:37 -04:00
|
|
|
k = check;
|
2007-12-01 00:00:00 +00:00
|
|
|
class_has_been_loaded = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-01-10 17:38:20 -05:00
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
// must throw error outside of owning lock
|
|
|
|
if (throw_circularity_error) {
|
2013-01-10 17:38:20 -05:00
|
|
|
assert(!HAS_PENDING_EXCEPTION && load_instance_added == false,"circularity error cleanup");
|
2007-12-01 00:00:00 +00:00
|
|
|
ResourceMark rm(THREAD);
|
2013-01-10 17:38:20 -05:00
|
|
|
THROW_MSG_NULL(vmSymbols::java_lang_ClassCircularityError(), name->as_C_string());
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!class_has_been_loaded) {
|
|
|
|
|
|
|
|
// Do actual loading
|
|
|
|
k = load_instance_class(name, class_loader, THREAD);
|
|
|
|
|
|
|
|
// If everything was OK (no exceptions, no null return value), and
|
|
|
|
// class_loader is NOT the defining loader, do a little more bookkeeping.
|
2017-03-15 10:25:37 -04:00
|
|
|
if (!HAS_PENDING_EXCEPTION && k != NULL &&
|
2018-04-03 13:15:27 +02:00
|
|
|
!oopDesc::equals(k->class_loader(), class_loader())) {
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2017-11-02 11:00:34 -05:00
|
|
|
check_constraints(d_hash, k, class_loader, false, THREAD);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// Need to check for a PENDING_EXCEPTION again; check_constraints
|
|
|
|
// can throw and doesn't use the CHECK macro.
|
|
|
|
if (!HAS_PENDING_EXCEPTION) {
|
|
|
|
{ // Grabbing the Compile_lock prevents systemDictionary updates
|
|
|
|
// during compilations.
|
|
|
|
MutexLocker mu(Compile_lock, THREAD);
|
2017-11-02 11:00:34 -05:00
|
|
|
update_dictionary(d_hash, p_index, p_hash,
|
2017-08-28 15:34:04 -07:00
|
|
|
k, class_loader, THREAD);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
2013-06-10 11:30:51 +02:00
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
if (JvmtiExport::should_post_class_load()) {
|
|
|
|
Thread *thread = THREAD;
|
|
|
|
assert(thread->is_Java_thread(), "thread->is_Java_thread()");
|
2017-03-15 10:25:37 -04:00
|
|
|
JvmtiExport::post_class_load((JavaThread *) thread, k);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-07-28 10:48:35 -04:00
|
|
|
} // load_instance_class
|
2013-01-10 17:38:20 -05:00
|
|
|
|
|
|
|
if (load_instance_added == true) {
|
|
|
|
// clean up placeholder entries for LOAD_INSTANCE success or error
|
|
|
|
// This brackets the SystemDictionary updates for both defining
|
|
|
|
// and initiating loaders
|
|
|
|
MutexLocker mu(SystemDictionary_lock, THREAD);
|
2013-06-10 11:30:51 +02:00
|
|
|
placeholders()->find_and_remove(p_index, p_hash, name, loader_data, PlaceholderTable::LOAD_INSTANCE, THREAD);
|
|
|
|
SystemDictionary_lock->notify_all();
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-15 10:25:37 -04:00
|
|
|
if (HAS_PENDING_EXCEPTION || k == NULL) {
|
2013-01-10 17:38:20 -05:00
|
|
|
return NULL;
|
|
|
|
}
|
2018-05-15 20:24:34 +02:00
|
|
|
if (class_load_start_event.should_commit()) {
|
|
|
|
post_class_load_event(&class_load_start_event, k, loader_data);
|
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
#ifdef ASSERT
|
|
|
|
{
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
ClassLoaderData* loader_data = k->class_loader_data();
|
2007-12-01 00:00:00 +00:00
|
|
|
MutexLocker mu(SystemDictionary_lock, THREAD);
|
2018-08-07 15:45:07 -07:00
|
|
|
InstanceKlass* kk = find_class(name, loader_data);
|
2017-03-15 10:25:37 -04:00
|
|
|
assert(kk == k, "should be present in dictionary");
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// return if the protection domain in NULL
|
2017-03-15 10:25:37 -04:00
|
|
|
if (protection_domain() == NULL) return k;
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// Check the protection domain has the right access
|
2017-11-02 11:00:34 -05:00
|
|
|
if (dictionary->is_valid_protection_domain(d_hash, name,
|
2017-08-30 19:18:22 -04:00
|
|
|
protection_domain)) {
|
|
|
|
return k;
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Verify protection domain. If it fails an exception is thrown
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
validate_protection_domain(k, class_loader, protection_domain, CHECK_NULL);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2017-03-15 10:25:37 -04:00
|
|
|
return k;
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// This routine does not lock the system dictionary.
|
|
|
|
//
|
|
|
|
// Since readers don't hold a lock, we must make sure that system
|
|
|
|
// dictionary entries are only removed at a safepoint (when only one
|
|
|
|
// thread is running), and are added to in a safe way (all links must
|
|
|
|
// be updated in an MT-safe manner).
|
|
|
|
//
|
|
|
|
// Callers should be aware that an entry could be added just after
|
|
|
|
// _dictionary->bucket(index) is read here, so the caller will not see
|
|
|
|
// the new entry.
|
|
|
|
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
Klass* SystemDictionary::find(Symbol* class_name,
|
2013-02-21 17:22:15 +01:00
|
|
|
Handle class_loader,
|
|
|
|
Handle protection_domain,
|
|
|
|
TRAPS) {
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2009-01-16 11:23:10 -08:00
|
|
|
// The result of this call should be consistent with the result
|
|
|
|
// of the call to resolve_instance_class_or_null().
|
|
|
|
// See evaluation 6790209 and 4474172 for more details.
|
|
|
|
class_loader = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader()));
|
2013-02-21 17:22:15 +01:00
|
|
|
ClassLoaderData* loader_data = ClassLoaderData::class_loader_data_or_null(class_loader());
|
|
|
|
|
|
|
|
if (loader_data == NULL) {
|
|
|
|
// If the ClassLoaderData has not been setup,
|
|
|
|
// then the class loader has no entries in the dictionary.
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-01-16 11:23:10 -08:00
|
|
|
|
2017-07-28 10:48:35 -04:00
|
|
|
Dictionary* dictionary = loader_data->dictionary();
|
|
|
|
unsigned int d_hash = dictionary->compute_hash(class_name);
|
2017-11-02 11:00:34 -05:00
|
|
|
return dictionary->find(d_hash, class_name,
|
2017-07-28 10:48:35 -04:00
|
|
|
protection_domain);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Look for a loaded instance or array klass by name. Do not do any loading.
|
|
|
|
// return NULL in case of error.
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
Klass* SystemDictionary::find_instance_or_array_klass(Symbol* class_name,
|
2012-09-29 06:40:00 -04:00
|
|
|
Handle class_loader,
|
|
|
|
Handle protection_domain,
|
|
|
|
TRAPS) {
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
Klass* k = NULL;
|
2011-01-27 16:11:27 -08:00
|
|
|
assert(class_name != NULL, "class name must be non NULL");
|
2008-04-29 19:45:22 -07:00
|
|
|
|
2011-01-27 16:11:27 -08:00
|
|
|
if (FieldType::is_array(class_name)) {
|
2007-12-01 00:00:00 +00:00
|
|
|
// The name refers to an array. Parse the name.
|
2011-01-27 16:11:27 -08:00
|
|
|
// dimension and object_key in FieldArrayInfo are assigned as a
|
|
|
|
// side-effect of this call
|
|
|
|
FieldArrayInfo fd;
|
|
|
|
BasicType t = FieldType::get_array_info(class_name, fd, CHECK_(NULL));
|
2007-12-01 00:00:00 +00:00
|
|
|
if (t != T_OBJECT) {
|
|
|
|
k = Universe::typeArrayKlassObj(t);
|
|
|
|
} else {
|
2011-01-27 16:11:27 -08:00
|
|
|
k = SystemDictionary::find(fd.object_key(), class_loader, protection_domain, THREAD);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
if (k != NULL) {
|
2012-11-12 16:15:05 -05:00
|
|
|
k = k->array_klass_or_null(fd.dimension());
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
k = find(class_name, class_loader, protection_domain, THREAD);
|
|
|
|
}
|
|
|
|
return k;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Note: this method is much like resolve_from_stream, but
|
2016-07-27 08:31:48 -04:00
|
|
|
// does not publish the classes via the SystemDictionary.
|
|
|
|
// Handles unsafe_DefineAnonymousClass and redefineclasses
|
|
|
|
// RedefinedClasses do not add to the class hierarchy
|
2017-03-15 10:25:37 -04:00
|
|
|
InstanceKlass* SystemDictionary::parse_stream(Symbol* class_name,
|
|
|
|
Handle class_loader,
|
|
|
|
Handle protection_domain,
|
|
|
|
ClassFileStream* st,
|
2018-08-20 08:25:57 -04:00
|
|
|
const InstanceKlass* unsafe_anonymous_host,
|
2017-03-15 10:25:37 -04:00
|
|
|
GrowableArray<Handle>* cp_patches,
|
|
|
|
TRAPS) {
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2017-08-28 00:20:35 +02:00
|
|
|
EventClassLoad class_load_start_event;
|
2013-06-10 11:30:51 +02:00
|
|
|
|
2012-11-29 16:50:29 -05:00
|
|
|
ClassLoaderData* loader_data;
|
2018-08-20 08:25:57 -04:00
|
|
|
if (unsafe_anonymous_host != NULL) {
|
|
|
|
// Create a new CLD for an unsafe anonymous class, that uses the same class loader
|
|
|
|
// as the unsafe_anonymous_host
|
|
|
|
guarantee(oopDesc::equals(unsafe_anonymous_host->class_loader(), class_loader()), "should be the same");
|
|
|
|
loader_data = ClassLoaderData::unsafe_anonymous_class_loader_data(class_loader);
|
2012-11-29 16:50:29 -05:00
|
|
|
} else {
|
|
|
|
loader_data = ClassLoaderData::class_loader_data(class_loader());
|
|
|
|
}
|
|
|
|
|
2015-12-08 20:04:03 +01:00
|
|
|
assert(st != NULL, "invariant");
|
|
|
|
assert(st->need_verify(), "invariant");
|
|
|
|
|
|
|
|
// Parse stream and create a klass.
|
|
|
|
// Note that we do this even though this klass might
|
2007-12-01 00:00:00 +00:00
|
|
|
// already be present in the SystemDictionary, otherwise we would not
|
|
|
|
// throw potential ClassFormatErrors.
|
|
|
|
|
2017-03-15 10:25:37 -04:00
|
|
|
InstanceKlass* k = KlassFactory::create_from_stream(st,
|
|
|
|
class_name,
|
|
|
|
loader_data,
|
|
|
|
protection_domain,
|
2018-08-20 08:25:57 -04:00
|
|
|
unsafe_anonymous_host,
|
2017-03-15 10:25:37 -04:00
|
|
|
cp_patches,
|
|
|
|
CHECK_NULL);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2018-08-20 08:25:57 -04:00
|
|
|
if (unsafe_anonymous_host != NULL && k != NULL) {
|
|
|
|
// Unsafe anonymous classes must update ClassLoaderData holder (was unsafe_anonymous_host loader)
|
2018-04-10 10:06:42 -04:00
|
|
|
// so that they can be unloaded when the mirror is no longer referenced.
|
|
|
|
k->class_loader_data()->initialize_holder(Handle(THREAD, k->java_mirror()));
|
2008-11-12 22:33:26 -08:00
|
|
|
|
|
|
|
{
|
|
|
|
MutexLocker mu_r(Compile_lock, THREAD);
|
|
|
|
|
|
|
|
// Add to class hierarchy, initialize vtables, and do possible
|
|
|
|
// deoptimizations.
|
|
|
|
add_to_hierarchy(k, CHECK_NULL); // No exception, but can block
|
|
|
|
|
2017-07-28 10:48:35 -04:00
|
|
|
// But, do not add to dictionary.
|
2013-12-13 09:25:44 +01:00
|
|
|
|
|
|
|
// compiled code dependencies need to be validated anyway
|
|
|
|
notice_modification();
|
2008-11-12 22:33:26 -08:00
|
|
|
}
|
|
|
|
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
// Rewrite and patch constant pool here.
|
2012-11-29 16:50:29 -05:00
|
|
|
k->link_class(CHECK_NULL);
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
if (cp_patches != NULL) {
|
|
|
|
k->constants()->patch_resolved_references(cp_patches);
|
|
|
|
}
|
2018-04-10 10:06:42 -04:00
|
|
|
|
|
|
|
// If it's anonymous, initialize it now, since nobody else will.
|
2012-11-29 16:50:29 -05:00
|
|
|
k->eager_initialize(CHECK_NULL);
|
2008-11-12 22:33:26 -08:00
|
|
|
|
|
|
|
// notify jvmti
|
|
|
|
if (JvmtiExport::should_post_class_load()) {
|
|
|
|
assert(THREAD->is_Java_thread(), "thread->is_Java_thread()");
|
2017-03-15 10:25:37 -04:00
|
|
|
JvmtiExport::post_class_load((JavaThread *) THREAD, k);
|
2008-11-12 22:33:26 -08:00
|
|
|
}
|
2018-05-15 20:24:34 +02:00
|
|
|
if (class_load_start_event.should_commit()) {
|
|
|
|
post_class_load_event(&class_load_start_event, k, loader_data);
|
|
|
|
}
|
2008-11-12 22:33:26 -08:00
|
|
|
}
|
2018-08-20 08:25:57 -04:00
|
|
|
assert(unsafe_anonymous_host != NULL || NULL == cp_patches,
|
|
|
|
"cp_patches only found with unsafe_anonymous_host");
|
2008-11-12 22:33:26 -08:00
|
|
|
|
2017-03-15 10:25:37 -04:00
|
|
|
return k;
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add a klass to the system from a stream (called by jni_DefineClass and
|
|
|
|
// JVM_DefineClass).
|
|
|
|
// Note: class_name can be NULL. In that case we do not know the name of
|
|
|
|
// the class until we have parsed the stream.
|
|
|
|
|
2017-03-15 10:25:37 -04:00
|
|
|
InstanceKlass* SystemDictionary::resolve_from_stream(Symbol* class_name,
|
|
|
|
Handle class_loader,
|
|
|
|
Handle protection_domain,
|
|
|
|
ClassFileStream* st,
|
|
|
|
TRAPS) {
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2017-02-15 22:59:57 -05:00
|
|
|
HandleMark hm(THREAD);
|
|
|
|
|
2009-01-05 13:44:03 -05:00
|
|
|
// Classloaders that support parallelism, e.g. bootstrap classloader,
|
2018-02-21 11:18:52 -05:00
|
|
|
// do not acquire lock here
|
2009-01-05 13:44:03 -05:00
|
|
|
bool DoObjectLock = true;
|
|
|
|
if (is_parallelCapable(class_loader)) {
|
|
|
|
DoObjectLock = false;
|
|
|
|
}
|
|
|
|
|
2018-03-06 17:15:16 -05:00
|
|
|
ClassLoaderData* loader_data = register_loader(class_loader);
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
|
2009-01-05 13:44:03 -05:00
|
|
|
// Make sure we are synchronized on the class loader before we proceed
|
2007-12-01 00:00:00 +00:00
|
|
|
Handle lockObject = compute_loader_lock_object(class_loader, THREAD);
|
|
|
|
check_loader_lock_contention(lockObject, THREAD);
|
2009-01-05 13:44:03 -05:00
|
|
|
ObjectLocker ol(lockObject, THREAD, DoObjectLock);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2015-12-08 20:04:03 +01:00
|
|
|
assert(st != NULL, "invariant");
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2015-12-08 20:04:03 +01:00
|
|
|
// Parse the stream and create a klass.
|
|
|
|
// Note that we do this even though this klass might
|
2007-12-01 00:00:00 +00:00
|
|
|
// already be present in the SystemDictionary, otherwise we would not
|
|
|
|
// throw potential ClassFormatErrors.
|
2017-03-15 10:25:37 -04:00
|
|
|
InstanceKlass* k = NULL;
|
2015-08-18 11:27:23 -07:00
|
|
|
|
|
|
|
#if INCLUDE_CDS
|
2017-08-28 15:34:04 -07:00
|
|
|
if (!DumpSharedSpaces) {
|
|
|
|
k = SystemDictionaryShared::lookup_from_stream(class_name,
|
|
|
|
class_loader,
|
|
|
|
protection_domain,
|
|
|
|
st,
|
|
|
|
CHECK_NULL);
|
|
|
|
}
|
2015-08-18 11:27:23 -07:00
|
|
|
#endif
|
|
|
|
|
2017-03-15 10:25:37 -04:00
|
|
|
if (k == NULL) {
|
2015-08-18 11:27:23 -07:00
|
|
|
if (st->buffer() == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-12-08 20:04:03 +01:00
|
|
|
k = KlassFactory::create_from_stream(st,
|
|
|
|
class_name,
|
|
|
|
loader_data,
|
|
|
|
protection_domain,
|
2018-08-20 08:25:57 -04:00
|
|
|
NULL, // unsafe_anonymous_host
|
2015-12-08 20:04:03 +01:00
|
|
|
NULL, // cp_patches
|
2016-07-27 08:31:48 -04:00
|
|
|
CHECK_NULL);
|
2015-08-18 11:27:23 -07:00
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2017-03-15 10:25:37 -04:00
|
|
|
assert(k != NULL, "no klass created");
|
2016-07-27 08:31:48 -04:00
|
|
|
Symbol* h_name = k->name();
|
|
|
|
assert(class_name == NULL || class_name == h_name, "name mismatch");
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2016-07-27 08:31:48 -04:00
|
|
|
// Add class just loaded
|
|
|
|
// If a class loader supports parallel classloading handle parallel define requests
|
|
|
|
// find_or_define_instance_class may return a different InstanceKlass
|
|
|
|
if (is_parallelCapable(class_loader)) {
|
2017-03-15 10:25:37 -04:00
|
|
|
InstanceKlass* defined_k = find_or_define_instance_class(h_name, class_loader, k, THREAD);
|
|
|
|
if (!HAS_PENDING_EXCEPTION && defined_k != k) {
|
2017-02-10 17:22:17 +01:00
|
|
|
// If a parallel capable class loader already defined this class, register 'k' for cleanup.
|
2017-03-15 10:25:37 -04:00
|
|
|
assert(defined_k != NULL, "Should have a klass if there's no exception");
|
|
|
|
loader_data->add_to_deallocate_list(k);
|
2017-02-10 17:22:17 +01:00
|
|
|
k = defined_k;
|
2016-12-11 19:07:04 -08:00
|
|
|
}
|
2016-07-27 08:31:48 -04:00
|
|
|
} else {
|
2017-02-10 17:22:17 +01:00
|
|
|
define_instance_class(k, THREAD);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If defining the class throws an exception register 'k' for cleanup.
|
|
|
|
if (HAS_PENDING_EXCEPTION) {
|
2017-03-15 10:25:37 -04:00
|
|
|
assert(k != NULL, "Must have an instance klass here!");
|
|
|
|
loader_data->add_to_deallocate_list(k);
|
2017-02-10 17:22:17 +01:00
|
|
|
return NULL;
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2013-01-10 17:38:20 -05:00
|
|
|
// Make sure we have an entry in the SystemDictionary on success
|
2007-12-01 00:00:00 +00:00
|
|
|
debug_only( {
|
2016-07-27 08:31:48 -04:00
|
|
|
MutexLocker mu(SystemDictionary_lock, THREAD);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2016-07-27 08:31:48 -04:00
|
|
|
Klass* check = find_class(h_name, k->class_loader_data());
|
2017-03-15 10:25:37 -04:00
|
|
|
assert(check == k, "should be present in the dictionary");
|
2007-12-01 00:00:00 +00:00
|
|
|
} );
|
|
|
|
|
2017-03-15 10:25:37 -04:00
|
|
|
return k;
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2014-08-12 17:29:00 -07:00
|
|
|
#if INCLUDE_CDS
|
2018-11-07 19:40:27 -08:00
|
|
|
// Load a class for boot loader from the shared spaces. This also
|
|
|
|
// forces the super class and all interfaces to be loaded.
|
2018-10-30 22:24:04 -04:00
|
|
|
InstanceKlass* SystemDictionary::load_shared_boot_class(Symbol* class_name,
|
|
|
|
TRAPS) {
|
2018-11-07 19:40:27 -08:00
|
|
|
InstanceKlass* ik = SystemDictionaryShared::find_builtin_class(class_name);
|
2018-10-30 22:24:04 -04:00
|
|
|
if (ik != NULL && ik->is_shared_boot_class()) {
|
|
|
|
return load_shared_class(ik, Handle(), Handle(), THREAD);
|
2014-08-12 17:29:00 -07:00
|
|
|
}
|
2017-03-15 10:25:37 -04:00
|
|
|
return NULL;
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
8142968: Module System implementation
Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282
Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Mark Reinhold <mark.reinhold@oracle.com>
Co-authored-by: Harold Seigel <harold.seigel@oracle.com>
Co-authored-by: Lois Foltan <lois.foltan@oracle.com>
Co-authored-by: Calvin Cheung <calvin.cheung@oracle.com>
Co-authored-by: Christian Tornqvist <christian.tornqvist@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Co-authored-by: George Triantafillou <george.triantafillou@oracle.com>
Co-authored-by: Igor Ignatyev <igor.ignatyev@oracle.com>
Co-authored-by: Ioi Lam <ioi.lam@oracle.com>
Co-authored-by: James Laskey <james.laskey@oracle.com>
Co-authored-by: Jean-Francois Denise <jean-francois.denise@oracle.com>
Co-authored-by: Jiangli Zhou <jiangli.zhou@oracle.com>
Co-authored-by: Markus Gronlund <markus.gronlund@oracle.com>
Co-authored-by: Serguei Spitsyn <serguei.spitsyn@oracle.com>
Co-authored-by: Staffan Larsen <staffan.larsen@oracle.com>
Co-authored-by: Sundararajan Athijegannathan <sundararajan.athijegannathan@oracle.com>
Reviewed-by: acorn, ccheung, coleenp, ctornqvi, dholmes, dsimms, gtriantafill, iklam, jiangli, mgronlun, mseledtsov, cjplummer, sspitsyn, stefank, twisti, hseigel, lfoltan, alanb, mchung, dfazunen
2016-03-17 19:04:01 +00:00
|
|
|
// Check if a shared class can be loaded by the specific classloader:
|
|
|
|
//
|
|
|
|
// NULL classloader:
|
|
|
|
// - Module class from "modules" jimage. ModuleEntry must be defined in the classloader.
|
|
|
|
// - Class from -Xbootclasspath/a. The class has no defined PackageEntry, or must
|
|
|
|
// be defined in an unnamed module.
|
|
|
|
bool SystemDictionary::is_shared_class_visible(Symbol* class_name,
|
2017-03-15 10:25:37 -04:00
|
|
|
InstanceKlass* ik,
|
8142968: Module System implementation
Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282
Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Mark Reinhold <mark.reinhold@oracle.com>
Co-authored-by: Harold Seigel <harold.seigel@oracle.com>
Co-authored-by: Lois Foltan <lois.foltan@oracle.com>
Co-authored-by: Calvin Cheung <calvin.cheung@oracle.com>
Co-authored-by: Christian Tornqvist <christian.tornqvist@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Co-authored-by: George Triantafillou <george.triantafillou@oracle.com>
Co-authored-by: Igor Ignatyev <igor.ignatyev@oracle.com>
Co-authored-by: Ioi Lam <ioi.lam@oracle.com>
Co-authored-by: James Laskey <james.laskey@oracle.com>
Co-authored-by: Jean-Francois Denise <jean-francois.denise@oracle.com>
Co-authored-by: Jiangli Zhou <jiangli.zhou@oracle.com>
Co-authored-by: Markus Gronlund <markus.gronlund@oracle.com>
Co-authored-by: Serguei Spitsyn <serguei.spitsyn@oracle.com>
Co-authored-by: Staffan Larsen <staffan.larsen@oracle.com>
Co-authored-by: Sundararajan Athijegannathan <sundararajan.athijegannathan@oracle.com>
Reviewed-by: acorn, ccheung, coleenp, ctornqvi, dholmes, dsimms, gtriantafill, iklam, jiangli, mgronlun, mseledtsov, cjplummer, sspitsyn, stefank, twisti, hseigel, lfoltan, alanb, mchung, dfazunen
2016-03-17 19:04:01 +00:00
|
|
|
Handle class_loader, TRAPS) {
|
2016-12-19 13:54:33 -05:00
|
|
|
assert(!ModuleEntryTable::javabase_moduleEntry()->is_patched(),
|
|
|
|
"Cannot use sharing if java.base is patched");
|
2016-06-07 11:39:47 -04:00
|
|
|
ResourceMark rm;
|
8142968: Module System implementation
Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282
Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Mark Reinhold <mark.reinhold@oracle.com>
Co-authored-by: Harold Seigel <harold.seigel@oracle.com>
Co-authored-by: Lois Foltan <lois.foltan@oracle.com>
Co-authored-by: Calvin Cheung <calvin.cheung@oracle.com>
Co-authored-by: Christian Tornqvist <christian.tornqvist@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Co-authored-by: George Triantafillou <george.triantafillou@oracle.com>
Co-authored-by: Igor Ignatyev <igor.ignatyev@oracle.com>
Co-authored-by: Ioi Lam <ioi.lam@oracle.com>
Co-authored-by: James Laskey <james.laskey@oracle.com>
Co-authored-by: Jean-Francois Denise <jean-francois.denise@oracle.com>
Co-authored-by: Jiangli Zhou <jiangli.zhou@oracle.com>
Co-authored-by: Markus Gronlund <markus.gronlund@oracle.com>
Co-authored-by: Serguei Spitsyn <serguei.spitsyn@oracle.com>
Co-authored-by: Staffan Larsen <staffan.larsen@oracle.com>
Co-authored-by: Sundararajan Athijegannathan <sundararajan.athijegannathan@oracle.com>
Reviewed-by: acorn, ccheung, coleenp, ctornqvi, dholmes, dsimms, gtriantafill, iklam, jiangli, mgronlun, mseledtsov, cjplummer, sspitsyn, stefank, twisti, hseigel, lfoltan, alanb, mchung, dfazunen
2016-03-17 19:04:01 +00:00
|
|
|
int path_index = ik->shared_classpath_index();
|
2017-08-28 15:34:04 -07:00
|
|
|
ClassLoaderData* loader_data = class_loader_data(class_loader);
|
|
|
|
if (path_index < 0) {
|
|
|
|
// path_index < 0 indicates that the class is intended for a custom loader
|
|
|
|
// and should not be loaded by boot/platform/app loaders
|
|
|
|
if (loader_data->is_builtin_class_loader_data()) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
8142968: Module System implementation
Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282
Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Mark Reinhold <mark.reinhold@oracle.com>
Co-authored-by: Harold Seigel <harold.seigel@oracle.com>
Co-authored-by: Lois Foltan <lois.foltan@oracle.com>
Co-authored-by: Calvin Cheung <calvin.cheung@oracle.com>
Co-authored-by: Christian Tornqvist <christian.tornqvist@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Co-authored-by: George Triantafillou <george.triantafillou@oracle.com>
Co-authored-by: Igor Ignatyev <igor.ignatyev@oracle.com>
Co-authored-by: Ioi Lam <ioi.lam@oracle.com>
Co-authored-by: James Laskey <james.laskey@oracle.com>
Co-authored-by: Jean-Francois Denise <jean-francois.denise@oracle.com>
Co-authored-by: Jiangli Zhou <jiangli.zhou@oracle.com>
Co-authored-by: Markus Gronlund <markus.gronlund@oracle.com>
Co-authored-by: Serguei Spitsyn <serguei.spitsyn@oracle.com>
Co-authored-by: Staffan Larsen <staffan.larsen@oracle.com>
Co-authored-by: Sundararajan Athijegannathan <sundararajan.athijegannathan@oracle.com>
Reviewed-by: acorn, ccheung, coleenp, ctornqvi, dholmes, dsimms, gtriantafill, iklam, jiangli, mgronlun, mseledtsov, cjplummer, sspitsyn, stefank, twisti, hseigel, lfoltan, alanb, mchung, dfazunen
2016-03-17 19:04:01 +00:00
|
|
|
SharedClassPathEntry* ent =
|
2018-04-10 11:43:40 -07:00
|
|
|
(SharedClassPathEntry*)FileMapInfo::shared_path(path_index);
|
8142968: Module System implementation
Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282
Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Mark Reinhold <mark.reinhold@oracle.com>
Co-authored-by: Harold Seigel <harold.seigel@oracle.com>
Co-authored-by: Lois Foltan <lois.foltan@oracle.com>
Co-authored-by: Calvin Cheung <calvin.cheung@oracle.com>
Co-authored-by: Christian Tornqvist <christian.tornqvist@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Co-authored-by: George Triantafillou <george.triantafillou@oracle.com>
Co-authored-by: Igor Ignatyev <igor.ignatyev@oracle.com>
Co-authored-by: Ioi Lam <ioi.lam@oracle.com>
Co-authored-by: James Laskey <james.laskey@oracle.com>
Co-authored-by: Jean-Francois Denise <jean-francois.denise@oracle.com>
Co-authored-by: Jiangli Zhou <jiangli.zhou@oracle.com>
Co-authored-by: Markus Gronlund <markus.gronlund@oracle.com>
Co-authored-by: Serguei Spitsyn <serguei.spitsyn@oracle.com>
Co-authored-by: Staffan Larsen <staffan.larsen@oracle.com>
Co-authored-by: Sundararajan Athijegannathan <sundararajan.athijegannathan@oracle.com>
Reviewed-by: acorn, ccheung, coleenp, ctornqvi, dholmes, dsimms, gtriantafill, iklam, jiangli, mgronlun, mseledtsov, cjplummer, sspitsyn, stefank, twisti, hseigel, lfoltan, alanb, mchung, dfazunen
2016-03-17 19:04:01 +00:00
|
|
|
if (!Universe::is_module_initialized()) {
|
2017-10-21 15:15:46 -07:00
|
|
|
assert(ent != NULL && ent->is_modules_image(),
|
8142968: Module System implementation
Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282
Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Mark Reinhold <mark.reinhold@oracle.com>
Co-authored-by: Harold Seigel <harold.seigel@oracle.com>
Co-authored-by: Lois Foltan <lois.foltan@oracle.com>
Co-authored-by: Calvin Cheung <calvin.cheung@oracle.com>
Co-authored-by: Christian Tornqvist <christian.tornqvist@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Co-authored-by: George Triantafillou <george.triantafillou@oracle.com>
Co-authored-by: Igor Ignatyev <igor.ignatyev@oracle.com>
Co-authored-by: Ioi Lam <ioi.lam@oracle.com>
Co-authored-by: James Laskey <james.laskey@oracle.com>
Co-authored-by: Jean-Francois Denise <jean-francois.denise@oracle.com>
Co-authored-by: Jiangli Zhou <jiangli.zhou@oracle.com>
Co-authored-by: Markus Gronlund <markus.gronlund@oracle.com>
Co-authored-by: Serguei Spitsyn <serguei.spitsyn@oracle.com>
Co-authored-by: Staffan Larsen <staffan.larsen@oracle.com>
Co-authored-by: Sundararajan Athijegannathan <sundararajan.athijegannathan@oracle.com>
Reviewed-by: acorn, ccheung, coleenp, ctornqvi, dholmes, dsimms, gtriantafill, iklam, jiangli, mgronlun, mseledtsov, cjplummer, sspitsyn, stefank, twisti, hseigel, lfoltan, alanb, mchung, dfazunen
2016-03-17 19:04:01 +00:00
|
|
|
"Loading non-bootstrap classes before the module system is initialized");
|
|
|
|
assert(class_loader.is_null(), "sanity");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// Get the pkg_entry from the classloader
|
|
|
|
TempNewSymbol pkg_name = NULL;
|
|
|
|
PackageEntry* pkg_entry = NULL;
|
|
|
|
ModuleEntry* mod_entry = NULL;
|
2016-06-07 11:39:47 -04:00
|
|
|
const char* pkg_string = NULL;
|
|
|
|
pkg_name = InstanceKlass::package_from_name(class_name, CHECK_false);
|
|
|
|
if (pkg_name != NULL) {
|
|
|
|
pkg_string = pkg_name->as_C_string();
|
8142968: Module System implementation
Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282
Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Mark Reinhold <mark.reinhold@oracle.com>
Co-authored-by: Harold Seigel <harold.seigel@oracle.com>
Co-authored-by: Lois Foltan <lois.foltan@oracle.com>
Co-authored-by: Calvin Cheung <calvin.cheung@oracle.com>
Co-authored-by: Christian Tornqvist <christian.tornqvist@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Co-authored-by: George Triantafillou <george.triantafillou@oracle.com>
Co-authored-by: Igor Ignatyev <igor.ignatyev@oracle.com>
Co-authored-by: Ioi Lam <ioi.lam@oracle.com>
Co-authored-by: James Laskey <james.laskey@oracle.com>
Co-authored-by: Jean-Francois Denise <jean-francois.denise@oracle.com>
Co-authored-by: Jiangli Zhou <jiangli.zhou@oracle.com>
Co-authored-by: Markus Gronlund <markus.gronlund@oracle.com>
Co-authored-by: Serguei Spitsyn <serguei.spitsyn@oracle.com>
Co-authored-by: Staffan Larsen <staffan.larsen@oracle.com>
Co-authored-by: Sundararajan Athijegannathan <sundararajan.athijegannathan@oracle.com>
Reviewed-by: acorn, ccheung, coleenp, ctornqvi, dholmes, dsimms, gtriantafill, iklam, jiangli, mgronlun, mseledtsov, cjplummer, sspitsyn, stefank, twisti, hseigel, lfoltan, alanb, mchung, dfazunen
2016-03-17 19:04:01 +00:00
|
|
|
if (loader_data != NULL) {
|
|
|
|
pkg_entry = loader_data->packages()->lookup_only(pkg_name);
|
|
|
|
}
|
|
|
|
if (pkg_entry != NULL) {
|
|
|
|
mod_entry = pkg_entry->module();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-19 13:54:33 -05:00
|
|
|
// If the archived class is from a module that has been patched at runtime,
|
|
|
|
// the class cannot be loaded from the archive.
|
|
|
|
if (mod_entry != NULL && mod_entry->is_patched()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
8142968: Module System implementation
Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282
Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Mark Reinhold <mark.reinhold@oracle.com>
Co-authored-by: Harold Seigel <harold.seigel@oracle.com>
Co-authored-by: Lois Foltan <lois.foltan@oracle.com>
Co-authored-by: Calvin Cheung <calvin.cheung@oracle.com>
Co-authored-by: Christian Tornqvist <christian.tornqvist@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Co-authored-by: George Triantafillou <george.triantafillou@oracle.com>
Co-authored-by: Igor Ignatyev <igor.ignatyev@oracle.com>
Co-authored-by: Ioi Lam <ioi.lam@oracle.com>
Co-authored-by: James Laskey <james.laskey@oracle.com>
Co-authored-by: Jean-Francois Denise <jean-francois.denise@oracle.com>
Co-authored-by: Jiangli Zhou <jiangli.zhou@oracle.com>
Co-authored-by: Markus Gronlund <markus.gronlund@oracle.com>
Co-authored-by: Serguei Spitsyn <serguei.spitsyn@oracle.com>
Co-authored-by: Staffan Larsen <staffan.larsen@oracle.com>
Co-authored-by: Sundararajan Athijegannathan <sundararajan.athijegannathan@oracle.com>
Reviewed-by: acorn, ccheung, coleenp, ctornqvi, dholmes, dsimms, gtriantafill, iklam, jiangli, mgronlun, mseledtsov, cjplummer, sspitsyn, stefank, twisti, hseigel, lfoltan, alanb, mchung, dfazunen
2016-03-17 19:04:01 +00:00
|
|
|
if (class_loader.is_null()) {
|
2016-10-10 20:50:33 -04:00
|
|
|
assert(ent != NULL, "Shared class for NULL classloader must have valid SharedClassPathEntry");
|
8142968: Module System implementation
Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282
Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Mark Reinhold <mark.reinhold@oracle.com>
Co-authored-by: Harold Seigel <harold.seigel@oracle.com>
Co-authored-by: Lois Foltan <lois.foltan@oracle.com>
Co-authored-by: Calvin Cheung <calvin.cheung@oracle.com>
Co-authored-by: Christian Tornqvist <christian.tornqvist@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Co-authored-by: George Triantafillou <george.triantafillou@oracle.com>
Co-authored-by: Igor Ignatyev <igor.ignatyev@oracle.com>
Co-authored-by: Ioi Lam <ioi.lam@oracle.com>
Co-authored-by: James Laskey <james.laskey@oracle.com>
Co-authored-by: Jean-Francois Denise <jean-francois.denise@oracle.com>
Co-authored-by: Jiangli Zhou <jiangli.zhou@oracle.com>
Co-authored-by: Markus Gronlund <markus.gronlund@oracle.com>
Co-authored-by: Serguei Spitsyn <serguei.spitsyn@oracle.com>
Co-authored-by: Staffan Larsen <staffan.larsen@oracle.com>
Co-authored-by: Sundararajan Athijegannathan <sundararajan.athijegannathan@oracle.com>
Reviewed-by: acorn, ccheung, coleenp, ctornqvi, dholmes, dsimms, gtriantafill, iklam, jiangli, mgronlun, mseledtsov, cjplummer, sspitsyn, stefank, twisti, hseigel, lfoltan, alanb, mchung, dfazunen
2016-03-17 19:04:01 +00:00
|
|
|
// The NULL classloader can load archived class originated from the
|
|
|
|
// "modules" jimage and the -Xbootclasspath/a. For class from the
|
|
|
|
// "modules" jimage, the PackageEntry/ModuleEntry must be defined
|
|
|
|
// by the NULL classloader.
|
|
|
|
if (mod_entry != NULL) {
|
|
|
|
// PackageEntry/ModuleEntry is found in the classloader. Check if the
|
|
|
|
// ModuleEntry's location agrees with the archived class' origination.
|
2017-10-21 15:15:46 -07:00
|
|
|
if (ent->is_modules_image() && mod_entry->location()->starts_with("jrt:")) {
|
8142968: Module System implementation
Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282
Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Mark Reinhold <mark.reinhold@oracle.com>
Co-authored-by: Harold Seigel <harold.seigel@oracle.com>
Co-authored-by: Lois Foltan <lois.foltan@oracle.com>
Co-authored-by: Calvin Cheung <calvin.cheung@oracle.com>
Co-authored-by: Christian Tornqvist <christian.tornqvist@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Co-authored-by: George Triantafillou <george.triantafillou@oracle.com>
Co-authored-by: Igor Ignatyev <igor.ignatyev@oracle.com>
Co-authored-by: Ioi Lam <ioi.lam@oracle.com>
Co-authored-by: James Laskey <james.laskey@oracle.com>
Co-authored-by: Jean-Francois Denise <jean-francois.denise@oracle.com>
Co-authored-by: Jiangli Zhou <jiangli.zhou@oracle.com>
Co-authored-by: Markus Gronlund <markus.gronlund@oracle.com>
Co-authored-by: Serguei Spitsyn <serguei.spitsyn@oracle.com>
Co-authored-by: Staffan Larsen <staffan.larsen@oracle.com>
Co-authored-by: Sundararajan Athijegannathan <sundararajan.athijegannathan@oracle.com>
Reviewed-by: acorn, ccheung, coleenp, ctornqvi, dholmes, dsimms, gtriantafill, iklam, jiangli, mgronlun, mseledtsov, cjplummer, sspitsyn, stefank, twisti, hseigel, lfoltan, alanb, mchung, dfazunen
2016-03-17 19:04:01 +00:00
|
|
|
return true; // Module class from the "module" jimage
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the archived class is not from the "module" jimage, the class can be
|
|
|
|
// loaded by the NULL classloader if
|
|
|
|
//
|
|
|
|
// 1. the class is from the unamed package
|
|
|
|
// 2. or, the class is not from a module defined in the NULL classloader
|
|
|
|
// 3. or, the class is from an unamed module
|
2017-10-21 15:15:46 -07:00
|
|
|
if (!ent->is_modules_image() && ik->is_shared_boot_class()) {
|
8142968: Module System implementation
Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282
Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Mark Reinhold <mark.reinhold@oracle.com>
Co-authored-by: Harold Seigel <harold.seigel@oracle.com>
Co-authored-by: Lois Foltan <lois.foltan@oracle.com>
Co-authored-by: Calvin Cheung <calvin.cheung@oracle.com>
Co-authored-by: Christian Tornqvist <christian.tornqvist@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Co-authored-by: George Triantafillou <george.triantafillou@oracle.com>
Co-authored-by: Igor Ignatyev <igor.ignatyev@oracle.com>
Co-authored-by: Ioi Lam <ioi.lam@oracle.com>
Co-authored-by: James Laskey <james.laskey@oracle.com>
Co-authored-by: Jean-Francois Denise <jean-francois.denise@oracle.com>
Co-authored-by: Jiangli Zhou <jiangli.zhou@oracle.com>
Co-authored-by: Markus Gronlund <markus.gronlund@oracle.com>
Co-authored-by: Serguei Spitsyn <serguei.spitsyn@oracle.com>
Co-authored-by: Staffan Larsen <staffan.larsen@oracle.com>
Co-authored-by: Sundararajan Athijegannathan <sundararajan.athijegannathan@oracle.com>
Reviewed-by: acorn, ccheung, coleenp, ctornqvi, dholmes, dsimms, gtriantafill, iklam, jiangli, mgronlun, mseledtsov, cjplummer, sspitsyn, stefank, twisti, hseigel, lfoltan, alanb, mchung, dfazunen
2016-03-17 19:04:01 +00:00
|
|
|
// the class is from the -Xbootclasspath/a
|
|
|
|
if (pkg_string == NULL ||
|
|
|
|
pkg_entry == NULL ||
|
|
|
|
pkg_entry->in_unnamed_module()) {
|
|
|
|
assert(mod_entry == NULL ||
|
2017-04-18 13:19:42 -04:00
|
|
|
mod_entry == loader_data->unnamed_module(),
|
8142968: Module System implementation
Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282
Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Mark Reinhold <mark.reinhold@oracle.com>
Co-authored-by: Harold Seigel <harold.seigel@oracle.com>
Co-authored-by: Lois Foltan <lois.foltan@oracle.com>
Co-authored-by: Calvin Cheung <calvin.cheung@oracle.com>
Co-authored-by: Christian Tornqvist <christian.tornqvist@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Co-authored-by: George Triantafillou <george.triantafillou@oracle.com>
Co-authored-by: Igor Ignatyev <igor.ignatyev@oracle.com>
Co-authored-by: Ioi Lam <ioi.lam@oracle.com>
Co-authored-by: James Laskey <james.laskey@oracle.com>
Co-authored-by: Jean-Francois Denise <jean-francois.denise@oracle.com>
Co-authored-by: Jiangli Zhou <jiangli.zhou@oracle.com>
Co-authored-by: Markus Gronlund <markus.gronlund@oracle.com>
Co-authored-by: Serguei Spitsyn <serguei.spitsyn@oracle.com>
Co-authored-by: Staffan Larsen <staffan.larsen@oracle.com>
Co-authored-by: Sundararajan Athijegannathan <sundararajan.athijegannathan@oracle.com>
Reviewed-by: acorn, ccheung, coleenp, ctornqvi, dholmes, dsimms, gtriantafill, iklam, jiangli, mgronlun, mseledtsov, cjplummer, sspitsyn, stefank, twisti, hseigel, lfoltan, alanb, mchung, dfazunen
2016-03-17 19:04:01 +00:00
|
|
|
"the unnamed module is not defined in the classloader");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
bool res = SystemDictionaryShared::is_shared_class_visible_for_classloader(
|
|
|
|
ik, class_loader, pkg_string, pkg_name,
|
|
|
|
pkg_entry, mod_entry, CHECK_(false));
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-15 10:25:37 -04:00
|
|
|
InstanceKlass* SystemDictionary::load_shared_class(InstanceKlass* ik,
|
|
|
|
Handle class_loader,
|
|
|
|
Handle protection_domain, TRAPS) {
|
2016-07-19 13:52:14 -04:00
|
|
|
|
2017-03-15 10:25:37 -04:00
|
|
|
if (ik != NULL) {
|
2014-08-12 17:29:00 -07:00
|
|
|
Symbol* class_name = ik->name();
|
2007-12-01 00:00:00 +00:00
|
|
|
|
8142968: Module System implementation
Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282
Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Mark Reinhold <mark.reinhold@oracle.com>
Co-authored-by: Harold Seigel <harold.seigel@oracle.com>
Co-authored-by: Lois Foltan <lois.foltan@oracle.com>
Co-authored-by: Calvin Cheung <calvin.cheung@oracle.com>
Co-authored-by: Christian Tornqvist <christian.tornqvist@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Co-authored-by: George Triantafillou <george.triantafillou@oracle.com>
Co-authored-by: Igor Ignatyev <igor.ignatyev@oracle.com>
Co-authored-by: Ioi Lam <ioi.lam@oracle.com>
Co-authored-by: James Laskey <james.laskey@oracle.com>
Co-authored-by: Jean-Francois Denise <jean-francois.denise@oracle.com>
Co-authored-by: Jiangli Zhou <jiangli.zhou@oracle.com>
Co-authored-by: Markus Gronlund <markus.gronlund@oracle.com>
Co-authored-by: Serguei Spitsyn <serguei.spitsyn@oracle.com>
Co-authored-by: Staffan Larsen <staffan.larsen@oracle.com>
Co-authored-by: Sundararajan Athijegannathan <sundararajan.athijegannathan@oracle.com>
Reviewed-by: acorn, ccheung, coleenp, ctornqvi, dholmes, dsimms, gtriantafill, iklam, jiangli, mgronlun, mseledtsov, cjplummer, sspitsyn, stefank, twisti, hseigel, lfoltan, alanb, mchung, dfazunen
2016-03-17 19:04:01 +00:00
|
|
|
bool visible = is_shared_class_visible(
|
2017-03-15 10:25:37 -04:00
|
|
|
class_name, ik, class_loader, CHECK_NULL);
|
8142968: Module System implementation
Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282
Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Mark Reinhold <mark.reinhold@oracle.com>
Co-authored-by: Harold Seigel <harold.seigel@oracle.com>
Co-authored-by: Lois Foltan <lois.foltan@oracle.com>
Co-authored-by: Calvin Cheung <calvin.cheung@oracle.com>
Co-authored-by: Christian Tornqvist <christian.tornqvist@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Co-authored-by: George Triantafillou <george.triantafillou@oracle.com>
Co-authored-by: Igor Ignatyev <igor.ignatyev@oracle.com>
Co-authored-by: Ioi Lam <ioi.lam@oracle.com>
Co-authored-by: James Laskey <james.laskey@oracle.com>
Co-authored-by: Jean-Francois Denise <jean-francois.denise@oracle.com>
Co-authored-by: Jiangli Zhou <jiangli.zhou@oracle.com>
Co-authored-by: Markus Gronlund <markus.gronlund@oracle.com>
Co-authored-by: Serguei Spitsyn <serguei.spitsyn@oracle.com>
Co-authored-by: Staffan Larsen <staffan.larsen@oracle.com>
Co-authored-by: Sundararajan Athijegannathan <sundararajan.athijegannathan@oracle.com>
Reviewed-by: acorn, ccheung, coleenp, ctornqvi, dholmes, dsimms, gtriantafill, iklam, jiangli, mgronlun, mseledtsov, cjplummer, sspitsyn, stefank, twisti, hseigel, lfoltan, alanb, mchung, dfazunen
2016-03-17 19:04:01 +00:00
|
|
|
if (!visible) {
|
2017-03-15 10:25:37 -04:00
|
|
|
return NULL;
|
8142968: Module System implementation
Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282
Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Mark Reinhold <mark.reinhold@oracle.com>
Co-authored-by: Harold Seigel <harold.seigel@oracle.com>
Co-authored-by: Lois Foltan <lois.foltan@oracle.com>
Co-authored-by: Calvin Cheung <calvin.cheung@oracle.com>
Co-authored-by: Christian Tornqvist <christian.tornqvist@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Co-authored-by: George Triantafillou <george.triantafillou@oracle.com>
Co-authored-by: Igor Ignatyev <igor.ignatyev@oracle.com>
Co-authored-by: Ioi Lam <ioi.lam@oracle.com>
Co-authored-by: James Laskey <james.laskey@oracle.com>
Co-authored-by: Jean-Francois Denise <jean-francois.denise@oracle.com>
Co-authored-by: Jiangli Zhou <jiangli.zhou@oracle.com>
Co-authored-by: Markus Gronlund <markus.gronlund@oracle.com>
Co-authored-by: Serguei Spitsyn <serguei.spitsyn@oracle.com>
Co-authored-by: Staffan Larsen <staffan.larsen@oracle.com>
Co-authored-by: Sundararajan Athijegannathan <sundararajan.athijegannathan@oracle.com>
Reviewed-by: acorn, ccheung, coleenp, ctornqvi, dholmes, dsimms, gtriantafill, iklam, jiangli, mgronlun, mseledtsov, cjplummer, sspitsyn, stefank, twisti, hseigel, lfoltan, alanb, mchung, dfazunen
2016-03-17 19:04:01 +00:00
|
|
|
}
|
|
|
|
|
2016-05-27 05:49:24 -07:00
|
|
|
// Resolve the superclass and interfaces. They must be the same
|
|
|
|
// as in dump time, because the layout of <ik> depends on
|
|
|
|
// the specific layout of ik->super() and ik->local_interfaces().
|
|
|
|
//
|
|
|
|
// If unexpected superclass or interfaces are found, we cannot
|
|
|
|
// load <ik> from the shared archive.
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
if (ik->super() != NULL) {
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
Symbol* cn = ik->super()->name();
|
2015-08-18 11:27:23 -07:00
|
|
|
Klass *s = resolve_super_or_fail(class_name, cn,
|
2017-03-15 10:25:37 -04:00
|
|
|
class_loader, protection_domain, true, CHECK_NULL);
|
2015-08-18 11:27:23 -07:00
|
|
|
if (s != ik->super()) {
|
|
|
|
// The dynamically resolved super class is not the same as the one we used during dump time,
|
|
|
|
// so we cannot use ik.
|
2017-03-15 10:25:37 -04:00
|
|
|
return NULL;
|
2016-05-27 05:49:24 -07:00
|
|
|
} else {
|
|
|
|
assert(s->is_shared(), "must be");
|
2015-08-18 11:27:23 -07:00
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2018-08-07 15:45:07 -07:00
|
|
|
Array<InstanceKlass*>* interfaces = ik->local_interfaces();
|
2007-12-01 00:00:00 +00:00
|
|
|
int num_interfaces = interfaces->length();
|
|
|
|
for (int index = 0; index < num_interfaces; index++) {
|
2018-08-07 15:45:07 -07:00
|
|
|
InstanceKlass* k = interfaces->at(index);
|
|
|
|
Symbol* name = k->name();
|
2017-03-15 10:25:37 -04:00
|
|
|
Klass* i = resolve_super_or_fail(class_name, name, class_loader, protection_domain, false, CHECK_NULL);
|
2015-08-18 11:27:23 -07:00
|
|
|
if (k != i) {
|
|
|
|
// The dynamically resolved interface class is not the same as the one we used during dump time,
|
|
|
|
// so we cannot use ik.
|
2017-03-15 10:25:37 -04:00
|
|
|
return NULL;
|
2016-05-27 05:49:24 -07:00
|
|
|
} else {
|
|
|
|
assert(i->is_shared(), "must be");
|
2015-08-18 11:27:23 -07:00
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2017-03-15 10:25:37 -04:00
|
|
|
InstanceKlass* new_ik = KlassFactory::check_shared_class_file_load_hook(
|
|
|
|
ik, class_name, class_loader, protection_domain, CHECK_NULL);
|
|
|
|
if (new_ik != NULL) {
|
2016-09-18 21:10:48 -04:00
|
|
|
// The class is changed by CFLH. Return the new class. The shared class is
|
|
|
|
// not used.
|
|
|
|
return new_ik;
|
|
|
|
}
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
// Adjust methods to recover missing data. They need addresses for
|
|
|
|
// interpreter entry points and their default native method address
|
|
|
|
// must be reset.
|
|
|
|
|
|
|
|
// Updating methods must be done under a lock so multiple
|
|
|
|
// threads don't update these in parallel
|
2014-08-12 17:29:00 -07:00
|
|
|
//
|
|
|
|
// Shared classes are all currently loaded by either the bootstrap or
|
|
|
|
// internal parallel class loaders, so this will never cause a deadlock
|
|
|
|
// on a custom class loader lock.
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2014-08-12 17:29:00 -07:00
|
|
|
ClassLoaderData* loader_data = ClassLoaderData::class_loader_data(class_loader());
|
2007-12-01 00:00:00 +00:00
|
|
|
{
|
2017-02-15 22:59:57 -05:00
|
|
|
HandleMark hm(THREAD);
|
2007-12-01 00:00:00 +00:00
|
|
|
Handle lockObject = compute_loader_lock_object(class_loader, THREAD);
|
|
|
|
check_loader_lock_contention(lockObject, THREAD);
|
|
|
|
ObjectLocker ol(lockObject, THREAD, true);
|
2016-07-27 08:31:48 -04:00
|
|
|
// prohibited package check assumes all classes loaded from archive call
|
|
|
|
// restore_unshareable_info which calls ik->set_package()
|
2017-03-15 10:25:37 -04:00
|
|
|
ik->restore_unshareable_info(loader_data, protection_domain, CHECK_NULL);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2017-05-08 09:45:24 -04:00
|
|
|
ik->print_class_load_logging(loader_data, NULL, NULL);
|
8142968: Module System implementation
Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282
Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Mark Reinhold <mark.reinhold@oracle.com>
Co-authored-by: Harold Seigel <harold.seigel@oracle.com>
Co-authored-by: Lois Foltan <lois.foltan@oracle.com>
Co-authored-by: Calvin Cheung <calvin.cheung@oracle.com>
Co-authored-by: Christian Tornqvist <christian.tornqvist@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Co-authored-by: George Triantafillou <george.triantafillou@oracle.com>
Co-authored-by: Igor Ignatyev <igor.ignatyev@oracle.com>
Co-authored-by: Ioi Lam <ioi.lam@oracle.com>
Co-authored-by: James Laskey <james.laskey@oracle.com>
Co-authored-by: Jean-Francois Denise <jean-francois.denise@oracle.com>
Co-authored-by: Jiangli Zhou <jiangli.zhou@oracle.com>
Co-authored-by: Markus Gronlund <markus.gronlund@oracle.com>
Co-authored-by: Serguei Spitsyn <serguei.spitsyn@oracle.com>
Co-authored-by: Staffan Larsen <staffan.larsen@oracle.com>
Co-authored-by: Sundararajan Athijegannathan <sundararajan.athijegannathan@oracle.com>
Reviewed-by: acorn, ccheung, coleenp, ctornqvi, dholmes, dsimms, gtriantafill, iklam, jiangli, mgronlun, mseledtsov, cjplummer, sspitsyn, stefank, twisti, hseigel, lfoltan, alanb, mchung, dfazunen
2016-03-17 19:04:01 +00:00
|
|
|
|
|
|
|
// For boot loader, ensure that GetSystemPackage knows that a class in this
|
|
|
|
// package was loaded.
|
|
|
|
if (class_loader.is_null()) {
|
|
|
|
int path_index = ik->shared_classpath_index();
|
|
|
|
ResourceMark rm;
|
|
|
|
ClassLoader::add_package(ik->name()->as_C_string(), path_index, THREAD);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
2014-08-12 17:29:00 -07:00
|
|
|
|
|
|
|
if (DumpLoadedClassList != NULL && classlist_file->is_open()) {
|
|
|
|
// Only dump the classes that can be stored into CDS archive
|
|
|
|
if (SystemDictionaryShared::is_sharing_possible(loader_data)) {
|
|
|
|
ResourceMark rm(THREAD);
|
|
|
|
classlist_file->print_cr("%s", ik->name()->as_C_string());
|
|
|
|
classlist_file->flush();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
// notify a class loaded from shared object
|
2017-03-15 10:25:37 -04:00
|
|
|
ClassLoadingService::notify_class_loaded(ik, true /* shared class */);
|
2016-12-11 19:07:04 -08:00
|
|
|
|
2018-07-11 16:11:10 +02:00
|
|
|
ik->set_has_passed_fingerprint_check(false);
|
|
|
|
if (UseAOT && ik->supers_have_passed_fingerprint_checks()) {
|
|
|
|
uint64_t aot_fp = AOTLoader::get_saved_fingerprint(ik);
|
|
|
|
uint64_t cds_fp = ik->get_stored_fingerprint();
|
|
|
|
if (aot_fp != 0 && aot_fp == cds_fp) {
|
|
|
|
// This class matches with a class saved in an AOT library
|
|
|
|
ik->set_has_passed_fingerprint_check(true);
|
|
|
|
} else {
|
|
|
|
ResourceMark rm;
|
|
|
|
log_info(class, fingerprint)("%s : expected = " PTR64_FORMAT " actual = " PTR64_FORMAT, ik->external_name(), aot_fp, cds_fp);
|
|
|
|
}
|
2016-12-11 19:07:04 -08:00
|
|
|
}
|
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
return ik;
|
|
|
|
}
|
2014-09-02 09:51:24 -07:00
|
|
|
#endif // INCLUDE_CDS
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2017-03-15 10:25:37 -04:00
|
|
|
InstanceKlass* SystemDictionary::load_instance_class(Symbol* class_name, Handle class_loader, TRAPS) {
|
8142968: Module System implementation
Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282
Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Mark Reinhold <mark.reinhold@oracle.com>
Co-authored-by: Harold Seigel <harold.seigel@oracle.com>
Co-authored-by: Lois Foltan <lois.foltan@oracle.com>
Co-authored-by: Calvin Cheung <calvin.cheung@oracle.com>
Co-authored-by: Christian Tornqvist <christian.tornqvist@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Co-authored-by: George Triantafillou <george.triantafillou@oracle.com>
Co-authored-by: Igor Ignatyev <igor.ignatyev@oracle.com>
Co-authored-by: Ioi Lam <ioi.lam@oracle.com>
Co-authored-by: James Laskey <james.laskey@oracle.com>
Co-authored-by: Jean-Francois Denise <jean-francois.denise@oracle.com>
Co-authored-by: Jiangli Zhou <jiangli.zhou@oracle.com>
Co-authored-by: Markus Gronlund <markus.gronlund@oracle.com>
Co-authored-by: Serguei Spitsyn <serguei.spitsyn@oracle.com>
Co-authored-by: Staffan Larsen <staffan.larsen@oracle.com>
Co-authored-by: Sundararajan Athijegannathan <sundararajan.athijegannathan@oracle.com>
Reviewed-by: acorn, ccheung, coleenp, ctornqvi, dholmes, dsimms, gtriantafill, iklam, jiangli, mgronlun, mseledtsov, cjplummer, sspitsyn, stefank, twisti, hseigel, lfoltan, alanb, mchung, dfazunen
2016-03-17 19:04:01 +00:00
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
if (class_loader.is_null()) {
|
2016-06-07 11:39:47 -04:00
|
|
|
ResourceMark rm;
|
8142968: Module System implementation
Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282
Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Mark Reinhold <mark.reinhold@oracle.com>
Co-authored-by: Harold Seigel <harold.seigel@oracle.com>
Co-authored-by: Lois Foltan <lois.foltan@oracle.com>
Co-authored-by: Calvin Cheung <calvin.cheung@oracle.com>
Co-authored-by: Christian Tornqvist <christian.tornqvist@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Co-authored-by: George Triantafillou <george.triantafillou@oracle.com>
Co-authored-by: Igor Ignatyev <igor.ignatyev@oracle.com>
Co-authored-by: Ioi Lam <ioi.lam@oracle.com>
Co-authored-by: James Laskey <james.laskey@oracle.com>
Co-authored-by: Jean-Francois Denise <jean-francois.denise@oracle.com>
Co-authored-by: Jiangli Zhou <jiangli.zhou@oracle.com>
Co-authored-by: Markus Gronlund <markus.gronlund@oracle.com>
Co-authored-by: Serguei Spitsyn <serguei.spitsyn@oracle.com>
Co-authored-by: Staffan Larsen <staffan.larsen@oracle.com>
Co-authored-by: Sundararajan Athijegannathan <sundararajan.athijegannathan@oracle.com>
Reviewed-by: acorn, ccheung, coleenp, ctornqvi, dholmes, dsimms, gtriantafill, iklam, jiangli, mgronlun, mseledtsov, cjplummer, sspitsyn, stefank, twisti, hseigel, lfoltan, alanb, mchung, dfazunen
2016-03-17 19:04:01 +00:00
|
|
|
PackageEntry* pkg_entry = NULL;
|
|
|
|
bool search_only_bootloader_append = false;
|
|
|
|
ClassLoaderData *loader_data = class_loader_data(class_loader);
|
|
|
|
|
|
|
|
// Find the package in the boot loader's package entry table.
|
2016-06-07 11:39:47 -04:00
|
|
|
TempNewSymbol pkg_name = InstanceKlass::package_from_name(class_name, CHECK_NULL);
|
|
|
|
if (pkg_name != NULL) {
|
8142968: Module System implementation
Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282
Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Mark Reinhold <mark.reinhold@oracle.com>
Co-authored-by: Harold Seigel <harold.seigel@oracle.com>
Co-authored-by: Lois Foltan <lois.foltan@oracle.com>
Co-authored-by: Calvin Cheung <calvin.cheung@oracle.com>
Co-authored-by: Christian Tornqvist <christian.tornqvist@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Co-authored-by: George Triantafillou <george.triantafillou@oracle.com>
Co-authored-by: Igor Ignatyev <igor.ignatyev@oracle.com>
Co-authored-by: Ioi Lam <ioi.lam@oracle.com>
Co-authored-by: James Laskey <james.laskey@oracle.com>
Co-authored-by: Jean-Francois Denise <jean-francois.denise@oracle.com>
Co-authored-by: Jiangli Zhou <jiangli.zhou@oracle.com>
Co-authored-by: Markus Gronlund <markus.gronlund@oracle.com>
Co-authored-by: Serguei Spitsyn <serguei.spitsyn@oracle.com>
Co-authored-by: Staffan Larsen <staffan.larsen@oracle.com>
Co-authored-by: Sundararajan Athijegannathan <sundararajan.athijegannathan@oracle.com>
Reviewed-by: acorn, ccheung, coleenp, ctornqvi, dholmes, dsimms, gtriantafill, iklam, jiangli, mgronlun, mseledtsov, cjplummer, sspitsyn, stefank, twisti, hseigel, lfoltan, alanb, mchung, dfazunen
2016-03-17 19:04:01 +00:00
|
|
|
pkg_entry = loader_data->packages()->lookup_only(pkg_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prior to attempting to load the class, enforce the boot loader's
|
|
|
|
// visibility boundaries.
|
|
|
|
if (!Universe::is_module_initialized()) {
|
|
|
|
// During bootstrapping, prior to module initialization, any
|
|
|
|
// class attempting to be loaded must be checked against the
|
|
|
|
// java.base packages in the boot loader's PackageEntryTable.
|
|
|
|
// No class outside of java.base is allowed to be loaded during
|
|
|
|
// this bootstrapping window.
|
2017-11-19 23:30:41 -05:00
|
|
|
if (pkg_entry == NULL || pkg_entry->in_unnamed_module()) {
|
|
|
|
// Class is either in the unnamed package or in
|
|
|
|
// a named package within the unnamed module. Either
|
|
|
|
// case is outside of java.base, do not attempt to
|
|
|
|
// load the class post java.base definition. If
|
|
|
|
// java.base has not been defined, let the class load
|
|
|
|
// and its package will be checked later by
|
|
|
|
// ModuleEntryTable::verify_javabase_packages.
|
|
|
|
if (ModuleEntryTable::javabase_defined()) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Check that the class' package is defined within java.base.
|
|
|
|
ModuleEntry* mod_entry = pkg_entry->module();
|
|
|
|
Symbol* mod_entry_name = mod_entry->name();
|
|
|
|
if (mod_entry_name->fast_compare(vmSymbols::java_base()) != 0) {
|
|
|
|
return NULL;
|
8142968: Module System implementation
Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282
Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Mark Reinhold <mark.reinhold@oracle.com>
Co-authored-by: Harold Seigel <harold.seigel@oracle.com>
Co-authored-by: Lois Foltan <lois.foltan@oracle.com>
Co-authored-by: Calvin Cheung <calvin.cheung@oracle.com>
Co-authored-by: Christian Tornqvist <christian.tornqvist@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Co-authored-by: George Triantafillou <george.triantafillou@oracle.com>
Co-authored-by: Igor Ignatyev <igor.ignatyev@oracle.com>
Co-authored-by: Ioi Lam <ioi.lam@oracle.com>
Co-authored-by: James Laskey <james.laskey@oracle.com>
Co-authored-by: Jean-Francois Denise <jean-francois.denise@oracle.com>
Co-authored-by: Jiangli Zhou <jiangli.zhou@oracle.com>
Co-authored-by: Markus Gronlund <markus.gronlund@oracle.com>
Co-authored-by: Serguei Spitsyn <serguei.spitsyn@oracle.com>
Co-authored-by: Staffan Larsen <staffan.larsen@oracle.com>
Co-authored-by: Sundararajan Athijegannathan <sundararajan.athijegannathan@oracle.com>
Reviewed-by: acorn, ccheung, coleenp, ctornqvi, dholmes, dsimms, gtriantafill, iklam, jiangli, mgronlun, mseledtsov, cjplummer, sspitsyn, stefank, twisti, hseigel, lfoltan, alanb, mchung, dfazunen
2016-03-17 19:04:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// After the module system has been initialized, check if the class'
|
|
|
|
// package is in a module defined to the boot loader.
|
2016-06-07 11:39:47 -04:00
|
|
|
if (pkg_name == NULL || pkg_entry == NULL || pkg_entry->in_unnamed_module()) {
|
8142968: Module System implementation
Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282
Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Mark Reinhold <mark.reinhold@oracle.com>
Co-authored-by: Harold Seigel <harold.seigel@oracle.com>
Co-authored-by: Lois Foltan <lois.foltan@oracle.com>
Co-authored-by: Calvin Cheung <calvin.cheung@oracle.com>
Co-authored-by: Christian Tornqvist <christian.tornqvist@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Co-authored-by: George Triantafillou <george.triantafillou@oracle.com>
Co-authored-by: Igor Ignatyev <igor.ignatyev@oracle.com>
Co-authored-by: Ioi Lam <ioi.lam@oracle.com>
Co-authored-by: James Laskey <james.laskey@oracle.com>
Co-authored-by: Jean-Francois Denise <jean-francois.denise@oracle.com>
Co-authored-by: Jiangli Zhou <jiangli.zhou@oracle.com>
Co-authored-by: Markus Gronlund <markus.gronlund@oracle.com>
Co-authored-by: Serguei Spitsyn <serguei.spitsyn@oracle.com>
Co-authored-by: Staffan Larsen <staffan.larsen@oracle.com>
Co-authored-by: Sundararajan Athijegannathan <sundararajan.athijegannathan@oracle.com>
Reviewed-by: acorn, ccheung, coleenp, ctornqvi, dholmes, dsimms, gtriantafill, iklam, jiangli, mgronlun, mseledtsov, cjplummer, sspitsyn, stefank, twisti, hseigel, lfoltan, alanb, mchung, dfazunen
2016-03-17 19:04:01 +00:00
|
|
|
// Class is either in the unnamed package, in a named package
|
|
|
|
// within a module not defined to the boot loader or in a
|
|
|
|
// a named package within the unnamed module. In all cases,
|
|
|
|
// limit visibility to search for the class only in the boot
|
|
|
|
// loader's append path.
|
|
|
|
search_only_bootloader_append = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prior to bootstrapping's module initialization, never load a class outside
|
|
|
|
// of the boot loader's module path
|
2017-11-19 23:30:41 -05:00
|
|
|
assert(Universe::is_module_initialized() ||
|
8142968: Module System implementation
Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282
Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Mark Reinhold <mark.reinhold@oracle.com>
Co-authored-by: Harold Seigel <harold.seigel@oracle.com>
Co-authored-by: Lois Foltan <lois.foltan@oracle.com>
Co-authored-by: Calvin Cheung <calvin.cheung@oracle.com>
Co-authored-by: Christian Tornqvist <christian.tornqvist@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Co-authored-by: George Triantafillou <george.triantafillou@oracle.com>
Co-authored-by: Igor Ignatyev <igor.ignatyev@oracle.com>
Co-authored-by: Ioi Lam <ioi.lam@oracle.com>
Co-authored-by: James Laskey <james.laskey@oracle.com>
Co-authored-by: Jean-Francois Denise <jean-francois.denise@oracle.com>
Co-authored-by: Jiangli Zhou <jiangli.zhou@oracle.com>
Co-authored-by: Markus Gronlund <markus.gronlund@oracle.com>
Co-authored-by: Serguei Spitsyn <serguei.spitsyn@oracle.com>
Co-authored-by: Staffan Larsen <staffan.larsen@oracle.com>
Co-authored-by: Sundararajan Athijegannathan <sundararajan.athijegannathan@oracle.com>
Reviewed-by: acorn, ccheung, coleenp, ctornqvi, dholmes, dsimms, gtriantafill, iklam, jiangli, mgronlun, mseledtsov, cjplummer, sspitsyn, stefank, twisti, hseigel, lfoltan, alanb, mchung, dfazunen
2016-03-17 19:04:01 +00:00
|
|
|
!search_only_bootloader_append,
|
|
|
|
"Attempt to load a class outside of boot loader's module path");
|
2009-07-10 11:10:00 -07:00
|
|
|
|
2018-10-17 15:57:10 -07:00
|
|
|
// Search for classes in the CDS archive.
|
2017-03-15 10:25:37 -04:00
|
|
|
InstanceKlass* k = NULL;
|
2009-07-10 11:10:00 -07:00
|
|
|
{
|
2014-08-12 17:29:00 -07:00
|
|
|
#if INCLUDE_CDS
|
2009-07-10 11:10:00 -07:00
|
|
|
PerfTraceTime vmtimer(ClassLoader::perf_shared_classload_time());
|
2018-10-30 22:24:04 -04:00
|
|
|
k = load_shared_boot_class(class_name, THREAD);
|
2014-08-12 17:29:00 -07:00
|
|
|
#endif
|
2009-07-10 11:10:00 -07:00
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2017-03-15 10:25:37 -04:00
|
|
|
if (k == NULL) {
|
2007-12-01 00:00:00 +00:00
|
|
|
// Use VM class loader
|
2009-07-10 11:10:00 -07:00
|
|
|
PerfTraceTime vmtimer(ClassLoader::perf_sys_classload_time());
|
2017-03-15 10:25:37 -04:00
|
|
|
k = ClassLoader::load_class(class_name, search_only_bootloader_append, CHECK_NULL);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
// find_or_define_instance_class may return a different InstanceKlass
|
2017-03-15 10:25:37 -04:00
|
|
|
if (k != NULL) {
|
|
|
|
InstanceKlass* defined_k =
|
2017-02-10 17:22:17 +01:00
|
|
|
find_or_define_instance_class(class_name, class_loader, k, THREAD);
|
2017-03-15 10:25:37 -04:00
|
|
|
if (!HAS_PENDING_EXCEPTION && defined_k != k) {
|
2017-02-10 17:22:17 +01:00
|
|
|
// If a parallel capable class loader already defined this class, register 'k' for cleanup.
|
2017-03-15 10:25:37 -04:00
|
|
|
assert(defined_k != NULL, "Should have a klass if there's no exception");
|
|
|
|
loader_data->add_to_deallocate_list(k);
|
2017-02-10 17:22:17 +01:00
|
|
|
k = defined_k;
|
|
|
|
} else if (HAS_PENDING_EXCEPTION) {
|
2017-03-15 10:25:37 -04:00
|
|
|
loader_data->add_to_deallocate_list(k);
|
|
|
|
return NULL;
|
2017-02-10 17:22:17 +01:00
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
return k;
|
|
|
|
} else {
|
|
|
|
// Use user specified class loader to load class. Call loadClass operation on class_loader.
|
|
|
|
ResourceMark rm(THREAD);
|
|
|
|
|
2009-07-10 11:10:00 -07:00
|
|
|
assert(THREAD->is_Java_thread(), "must be a JavaThread");
|
|
|
|
JavaThread* jt = (JavaThread*) THREAD;
|
|
|
|
|
|
|
|
PerfClassTraceTime vmtimer(ClassLoader::perf_app_classload_time(),
|
|
|
|
ClassLoader::perf_app_classload_selftime(),
|
|
|
|
ClassLoader::perf_app_classload_count(),
|
|
|
|
jt->get_thread_stat()->perf_recursion_counts_addr(),
|
|
|
|
jt->get_thread_stat()->perf_timers_addr(),
|
|
|
|
PerfClassTraceTime::CLASS_LOAD);
|
|
|
|
|
2017-03-15 10:25:37 -04:00
|
|
|
Handle s = java_lang_String::create_from_symbol(class_name, CHECK_NULL);
|
2007-12-01 00:00:00 +00:00
|
|
|
// Translate to external class name format, i.e., convert '/' chars to '.'
|
2017-03-15 10:25:37 -04:00
|
|
|
Handle string = java_lang_String::externalize_classname(s, CHECK_NULL);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
JavaValue result(T_OBJECT);
|
|
|
|
|
2017-03-15 10:25:37 -04:00
|
|
|
InstanceKlass* spec_klass = SystemDictionary::ClassLoader_klass();
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2018-02-21 11:18:52 -05:00
|
|
|
// Call public unsynchronized loadClass(String) directly for all class loaders.
|
|
|
|
// For parallelCapable class loaders, JDK >=7, loadClass(String, boolean) will
|
2009-01-05 13:44:03 -05:00
|
|
|
// acquire a class-name based lock rather than the class loader object lock.
|
2018-02-21 11:18:52 -05:00
|
|
|
// JDK < 7 already acquire the class loader lock in loadClass(String, boolean).
|
|
|
|
JavaCalls::call_virtual(&result,
|
|
|
|
class_loader,
|
|
|
|
spec_klass,
|
|
|
|
vmSymbols::loadClass_name(),
|
|
|
|
vmSymbols::string_class_signature(),
|
|
|
|
string,
|
|
|
|
CHECK_NULL);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
assert(result.get_type() == T_OBJECT, "just checking");
|
|
|
|
oop obj = (oop) result.get_jobject();
|
|
|
|
|
|
|
|
// Primitive classes return null since forName() can not be
|
|
|
|
// used to obtain any of the Class objects representing primitives or void
|
|
|
|
if ((obj != NULL) && !(java_lang_Class::is_primitive(obj))) {
|
2017-03-15 10:25:37 -04:00
|
|
|
InstanceKlass* k = InstanceKlass::cast(java_lang_Class::as_Klass(obj));
|
2007-12-01 00:00:00 +00:00
|
|
|
// For user defined Java class loaders, check that the name returned is
|
|
|
|
// the same as that requested. This check is done for the bootstrap
|
|
|
|
// loader when parsing the class file.
|
2011-01-27 16:11:27 -08:00
|
|
|
if (class_name == k->name()) {
|
2007-12-01 00:00:00 +00:00
|
|
|
return k;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Class is not found or has the wrong name, return NULL
|
2017-03-15 10:25:37 -04:00
|
|
|
return NULL;
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-15 20:24:34 +02:00
|
|
|
static void post_class_define_event(InstanceKlass* k, const ClassLoaderData* def_cld) {
|
|
|
|
EventClassDefine event;
|
|
|
|
if (event.should_commit()) {
|
|
|
|
event.set_definedClass(k);
|
|
|
|
event.set_definingClassLoader(def_cld);
|
|
|
|
event.commit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-15 10:25:37 -04:00
|
|
|
void SystemDictionary::define_instance_class(InstanceKlass* k, TRAPS) {
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2017-02-15 22:59:57 -05:00
|
|
|
HandleMark hm(THREAD);
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
ClassLoaderData* loader_data = k->class_loader_data();
|
|
|
|
Handle class_loader_h(THREAD, loader_data->class_loader());
|
|
|
|
|
2009-01-05 13:44:03 -05:00
|
|
|
// for bootstrap and other parallel classloaders don't acquire lock,
|
|
|
|
// use placeholder token
|
|
|
|
// If a parallelCapable class loader calls define_instance_class instead of
|
|
|
|
// find_or_define_instance_class to get here, we have a timing
|
|
|
|
// hole with systemDictionary updates and check_constraints
|
|
|
|
if (!class_loader_h.is_null() && !is_parallelCapable(class_loader_h)) {
|
2007-12-01 00:00:00 +00:00
|
|
|
assert(ObjectSynchronizer::current_thread_holds_lock((JavaThread*)THREAD,
|
|
|
|
compute_loader_lock_object(class_loader_h, THREAD)),
|
|
|
|
"define called without lock");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check class-loading constraints. Throw exception if violation is detected.
|
|
|
|
// Grabs and releases SystemDictionary_lock
|
|
|
|
// The check_constraints/find_class call and update_dictionary sequence
|
|
|
|
// must be "atomic" for a specific class/classloader pair so we never
|
|
|
|
// define two different instanceKlasses for that class/classloader pair.
|
|
|
|
// Existing classloaders will call define_instance_class with the
|
|
|
|
// classloader lock held
|
|
|
|
// Parallel classloaders will call find_or_define_instance_class
|
|
|
|
// which will require a token to perform the define class
|
2011-01-27 16:11:27 -08:00
|
|
|
Symbol* name_h = k->name();
|
2017-07-28 10:48:35 -04:00
|
|
|
Dictionary* dictionary = loader_data->dictionary();
|
|
|
|
unsigned int d_hash = dictionary->compute_hash(name_h);
|
2017-11-02 11:00:34 -05:00
|
|
|
check_constraints(d_hash, k, class_loader_h, true, CHECK);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2012-09-17 10:46:59 -04:00
|
|
|
// Register class just loaded with class loader (placed in Vector)
|
|
|
|
// Note we do this before updating the dictionary, as this can
|
|
|
|
// fail with an OutOfMemoryError (if it does, we will *not* put this
|
|
|
|
// class in the dictionary and will not update the class hierarchy).
|
|
|
|
// JVMTI FollowReferences needs to find the classes this way.
|
|
|
|
if (k->class_loader() != NULL) {
|
|
|
|
methodHandle m(THREAD, Universe::loader_addClass_method());
|
|
|
|
JavaValue result(T_VOID);
|
|
|
|
JavaCallArguments args(class_loader_h);
|
|
|
|
args.push_oop(Handle(THREAD, k->java_mirror()));
|
|
|
|
JavaCalls::call(&result, m, &args, CHECK);
|
|
|
|
}
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
// Add the new class. We need recompile lock during update of CHA.
|
|
|
|
{
|
2017-07-28 10:48:35 -04:00
|
|
|
unsigned int p_hash = placeholders()->compute_hash(name_h);
|
2007-12-01 00:00:00 +00:00
|
|
|
int p_index = placeholders()->hash_to_index(p_hash);
|
|
|
|
|
|
|
|
MutexLocker mu_r(Compile_lock, THREAD);
|
|
|
|
|
|
|
|
// Add to class hierarchy, initialize vtables, and do possible
|
|
|
|
// deoptimizations.
|
|
|
|
add_to_hierarchy(k, CHECK); // No exception, but can block
|
|
|
|
|
|
|
|
// Add to systemDictionary - so other classes can see it.
|
|
|
|
// Grabs and releases SystemDictionary_lock
|
2017-11-02 11:00:34 -05:00
|
|
|
update_dictionary(d_hash, p_index, p_hash,
|
2007-12-01 00:00:00 +00:00
|
|
|
k, class_loader_h, THREAD);
|
|
|
|
}
|
|
|
|
k->eager_initialize(THREAD);
|
|
|
|
|
|
|
|
// notify jvmti
|
|
|
|
if (JvmtiExport::should_post_class_load()) {
|
|
|
|
assert(THREAD->is_Java_thread(), "thread->is_Java_thread()");
|
2017-03-15 10:25:37 -04:00
|
|
|
JvmtiExport::post_class_load((JavaThread *) THREAD, k);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
}
|
2018-05-15 20:24:34 +02:00
|
|
|
post_class_define_event(k, loader_data);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Support parallel classloading
|
2009-11-11 15:49:38 -05:00
|
|
|
// All parallel class loaders, including bootstrap classloader
|
|
|
|
// lock a placeholder entry for this class/class_loader pair
|
|
|
|
// to allow parallel defines of different classes for this class loader
|
2009-01-05 13:44:03 -05:00
|
|
|
// With AllowParallelDefine flag==true, in case they do not synchronize around
|
|
|
|
// FindLoadedClass/DefineClass, calls, we check for parallel
|
2007-12-01 00:00:00 +00:00
|
|
|
// loading for them, wait if a defineClass is in progress
|
|
|
|
// and return the initial requestor's results
|
2009-11-11 15:49:38 -05:00
|
|
|
// This flag does not apply to the bootstrap classloader.
|
2009-01-05 13:44:03 -05:00
|
|
|
// With AllowParallelDefine flag==false, call through to define_instance_class
|
|
|
|
// which will throw LinkageError: duplicate class definition.
|
2009-11-11 15:49:38 -05:00
|
|
|
// False is the requested default.
|
2007-12-01 00:00:00 +00:00
|
|
|
// For better performance, the class loaders should synchronize
|
2009-01-05 13:44:03 -05:00
|
|
|
// findClass(), i.e. FindLoadedClass/DefineClassIfAbsent or they
|
2007-12-01 00:00:00 +00:00
|
|
|
// potentially waste time reading and parsing the bytestream.
|
|
|
|
// Note: VM callers should ensure consistency of k/class_name,class_loader
|
2016-07-27 08:31:48 -04:00
|
|
|
// Be careful when modifying this code: once you have run
|
|
|
|
// placeholders()->find_and_add(PlaceholderTable::DEFINE_CLASS),
|
|
|
|
// you need to find_and_remove it before returning.
|
|
|
|
// So be careful to not exit with a CHECK_ macro betweeen these calls.
|
2017-03-15 10:25:37 -04:00
|
|
|
InstanceKlass* SystemDictionary::find_or_define_instance_class(Symbol* class_name, Handle class_loader,
|
|
|
|
InstanceKlass* k, TRAPS) {
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2011-01-27 16:11:27 -08:00
|
|
|
Symbol* name_h = k->name(); // passed in class_name may be null
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
ClassLoaderData* loader_data = class_loader_data(class_loader);
|
2017-07-28 10:48:35 -04:00
|
|
|
Dictionary* dictionary = loader_data->dictionary();
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2017-07-28 10:48:35 -04:00
|
|
|
unsigned int d_hash = dictionary->compute_hash(name_h);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2017-03-15 10:25:37 -04:00
|
|
|
// Hold SD lock around find_class and placeholder creation for DEFINE_CLASS
|
2017-07-28 10:48:35 -04:00
|
|
|
unsigned int p_hash = placeholders()->compute_hash(name_h);
|
2007-12-01 00:00:00 +00:00
|
|
|
int p_index = placeholders()->hash_to_index(p_hash);
|
|
|
|
PlaceholderEntry* probe;
|
|
|
|
|
|
|
|
{
|
|
|
|
MutexLocker mu(SystemDictionary_lock, THREAD);
|
|
|
|
// First check if class already defined
|
2018-02-21 11:18:52 -05:00
|
|
|
if (is_parallelDefine(class_loader)) {
|
2017-11-02 11:00:34 -05:00
|
|
|
InstanceKlass* check = find_class(d_hash, name_h, dictionary);
|
2009-11-11 15:49:38 -05:00
|
|
|
if (check != NULL) {
|
2017-03-15 10:25:37 -04:00
|
|
|
return check;
|
2009-11-11 15:49:38 -05:00
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Acquire define token for this class/classloader
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
probe = placeholders()->find_and_add(p_index, p_hash, name_h, loader_data, PlaceholderTable::DEFINE_CLASS, NULL, THREAD);
|
2009-01-05 13:44:03 -05:00
|
|
|
// Wait if another thread defining in parallel
|
|
|
|
// All threads wait - even those that will throw duplicate class: otherwise
|
|
|
|
// caller is surprised by LinkageError: duplicate, but findLoadedClass fails
|
|
|
|
// if other thread has not finished updating dictionary
|
|
|
|
while (probe->definer() != NULL) {
|
|
|
|
SystemDictionary_lock->wait();
|
|
|
|
}
|
|
|
|
// Only special cases allow parallel defines and can use other thread's results
|
|
|
|
// Other cases fall through, and may run into duplicate defines
|
|
|
|
// caught by finding an entry in the SystemDictionary
|
2018-02-21 11:18:52 -05:00
|
|
|
if (is_parallelDefine(class_loader) && (probe->instance_klass() != NULL)) {
|
2013-01-10 17:38:20 -05:00
|
|
|
placeholders()->find_and_remove(p_index, p_hash, name_h, loader_data, PlaceholderTable::DEFINE_CLASS, THREAD);
|
2009-01-05 13:44:03 -05:00
|
|
|
SystemDictionary_lock->notify_all();
|
2007-12-01 00:00:00 +00:00
|
|
|
#ifdef ASSERT
|
2017-11-02 11:00:34 -05:00
|
|
|
InstanceKlass* check = find_class(d_hash, name_h, dictionary);
|
2009-01-05 13:44:03 -05:00
|
|
|
assert(check != NULL, "definer missed recording success");
|
2007-12-01 00:00:00 +00:00
|
|
|
#endif
|
2017-03-15 10:25:37 -04:00
|
|
|
return probe->instance_klass();
|
2009-01-05 13:44:03 -05:00
|
|
|
} else {
|
|
|
|
// This thread will define the class (even if earlier thread tried and had an error)
|
|
|
|
probe->set_definer(THREAD);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
define_instance_class(k, THREAD);
|
|
|
|
|
|
|
|
Handle linkage_exception = Handle(); // null handle
|
|
|
|
|
|
|
|
// definer must notify any waiting threads
|
|
|
|
{
|
|
|
|
MutexLocker mu(SystemDictionary_lock, THREAD);
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
PlaceholderEntry* probe = placeholders()->get_entry(p_index, p_hash, name_h, loader_data);
|
2007-12-01 00:00:00 +00:00
|
|
|
assert(probe != NULL, "DEFINE_CLASS placeholder lost?");
|
|
|
|
if (probe != NULL) {
|
|
|
|
if (HAS_PENDING_EXCEPTION) {
|
|
|
|
linkage_exception = Handle(THREAD,PENDING_EXCEPTION);
|
|
|
|
CLEAR_PENDING_EXCEPTION;
|
|
|
|
} else {
|
2017-03-15 10:25:37 -04:00
|
|
|
probe->set_instance_klass(k);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
probe->set_definer(NULL);
|
2013-01-10 17:38:20 -05:00
|
|
|
placeholders()->find_and_remove(p_index, p_hash, name_h, loader_data, PlaceholderTable::DEFINE_CLASS, THREAD);
|
2007-12-01 00:00:00 +00:00
|
|
|
SystemDictionary_lock->notify_all();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Can't throw exception while holding lock due to rank ordering
|
|
|
|
if (linkage_exception() != NULL) {
|
2017-03-15 10:25:37 -04:00
|
|
|
THROW_OOP_(linkage_exception(), NULL); // throws exception and returns
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return k;
|
|
|
|
}
|
2017-07-28 10:48:35 -04:00
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
Handle SystemDictionary::compute_loader_lock_object(Handle class_loader, TRAPS) {
|
|
|
|
// If class_loader is NULL we synchronize on _system_loader_lock_obj
|
|
|
|
if (class_loader.is_null()) {
|
|
|
|
return Handle(THREAD, _system_loader_lock_obj);
|
|
|
|
} else {
|
|
|
|
return class_loader;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This method is added to check how often we have to wait to grab loader
|
|
|
|
// lock. The results are being recorded in the performance counters defined in
|
|
|
|
// ClassLoader::_sync_systemLoaderLockContentionRate and
|
|
|
|
// ClassLoader::_sync_nonSystemLoaderLockConteionRate.
|
|
|
|
void SystemDictionary::check_loader_lock_contention(Handle loader_lock, TRAPS) {
|
|
|
|
if (!UsePerfData) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(!loader_lock.is_null(), "NULL lock object");
|
|
|
|
|
|
|
|
if (ObjectSynchronizer::query_lock_ownership((JavaThread*)THREAD, loader_lock)
|
|
|
|
== ObjectSynchronizer::owner_other) {
|
|
|
|
// contention will likely happen, so increment the corresponding
|
|
|
|
// contention counter.
|
2018-04-03 13:15:27 +02:00
|
|
|
if (oopDesc::equals(loader_lock(), _system_loader_lock_obj)) {
|
2007-12-01 00:00:00 +00:00
|
|
|
ClassLoader::sync_systemLoaderLockContentionRate()->inc();
|
|
|
|
} else {
|
|
|
|
ClassLoader::sync_nonSystemLoaderLockContentionRate()->inc();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Lookup
|
|
|
|
|
2017-11-02 11:00:34 -05:00
|
|
|
InstanceKlass* SystemDictionary::find_class(unsigned int hash,
|
2017-03-15 10:25:37 -04:00
|
|
|
Symbol* class_name,
|
2017-07-28 10:48:35 -04:00
|
|
|
Dictionary* dictionary) {
|
2007-12-01 00:00:00 +00:00
|
|
|
assert_locked_or_safepoint(SystemDictionary_lock);
|
2017-11-02 11:00:34 -05:00
|
|
|
int index = dictionary->hash_to_index(hash);
|
2017-07-28 10:48:35 -04:00
|
|
|
return dictionary->find_class(index, hash, class_name);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Basic find on classes in the midst of being loaded
|
2011-01-27 16:11:27 -08:00
|
|
|
Symbol* SystemDictionary::find_placeholder(Symbol* class_name,
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
ClassLoaderData* loader_data) {
|
2007-12-01 00:00:00 +00:00
|
|
|
assert_locked_or_safepoint(SystemDictionary_lock);
|
2017-07-28 10:48:35 -04:00
|
|
|
unsigned int p_hash = placeholders()->compute_hash(class_name);
|
2011-01-27 16:11:27 -08:00
|
|
|
int p_index = placeholders()->hash_to_index(p_hash);
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
return placeholders()->find_entry(p_index, p_hash, class_name, loader_data);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Used for assertions and verification only
|
2017-07-28 10:48:35 -04:00
|
|
|
// Precalculating the hash and index is an optimization because there are many lookups
|
|
|
|
// before adding the class.
|
2017-03-15 10:25:37 -04:00
|
|
|
InstanceKlass* SystemDictionary::find_class(Symbol* class_name, ClassLoaderData* loader_data) {
|
2017-07-28 10:48:35 -04:00
|
|
|
assert_locked_or_safepoint(SystemDictionary_lock);
|
2007-12-01 00:00:00 +00:00
|
|
|
#ifndef ASSERT
|
2013-04-05 10:20:04 -07:00
|
|
|
guarantee(VerifyBeforeGC ||
|
|
|
|
VerifyDuringGC ||
|
|
|
|
VerifyBeforeExit ||
|
|
|
|
VerifyDuringStartup ||
|
2007-12-01 00:00:00 +00:00
|
|
|
VerifyAfterGC, "too expensive");
|
|
|
|
#endif
|
|
|
|
|
2017-07-28 10:48:35 -04:00
|
|
|
Dictionary* dictionary = loader_data->dictionary();
|
|
|
|
unsigned int d_hash = dictionary->compute_hash(class_name);
|
2017-11-02 11:00:34 -05:00
|
|
|
return find_class(d_hash, class_name, dictionary);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Update hierachy. This is done before the new klass has been added to the SystemDictionary. The Recompile_lock
|
|
|
|
// is held, to ensure that the compiler is not using the class hierachy, and that deoptimization will kick in
|
|
|
|
// before a new class is used.
|
|
|
|
|
2017-03-15 10:25:37 -04:00
|
|
|
void SystemDictionary::add_to_hierarchy(InstanceKlass* k, TRAPS) {
|
|
|
|
assert(k != NULL, "just checking");
|
2011-01-31 17:48:21 -08:00
|
|
|
assert_locked_or_safepoint(Compile_lock);
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
// Link into hierachy. Make sure the vtables are initialized before linking into
|
|
|
|
k->append_to_sibling_list(); // add to superklass/sibling list
|
|
|
|
k->process_interfaces(THREAD); // handle all "implements" declarations
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
k->set_init_state(InstanceKlass::loaded);
|
2007-12-01 00:00:00 +00:00
|
|
|
// Now flush all code that depended on old class hierarchy.
|
|
|
|
// Note: must be done *after* linking k into the hierarchy (was bug 12/9/97)
|
|
|
|
// Also, first reinitialize vtable because it may have gotten out of synch
|
|
|
|
// while the new class wasn't connected to the class hierarchy.
|
2015-01-06 19:30:28 -05:00
|
|
|
CodeCache::flush_dependents_on(k);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// GC support
|
|
|
|
|
2013-01-10 17:38:20 -05:00
|
|
|
// Assumes classes in the SystemDictionary are only unloaded at a safepoint
|
|
|
|
// Note: anonymous classes are not in the SD.
|
2018-11-13 11:45:16 +01:00
|
|
|
bool SystemDictionary::do_unloading(GCTimer* gc_timer) {
|
2017-05-27 09:21:01 -04:00
|
|
|
|
|
|
|
bool unloading_occurred;
|
2018-11-16 10:54:04 -05:00
|
|
|
bool is_concurrent = !SafepointSynchronize::is_at_safepoint();
|
2017-05-27 09:21:01 -04:00
|
|
|
{
|
|
|
|
GCTraceTime(Debug, gc, phases) t("ClassLoaderData", gc_timer);
|
2018-11-16 10:54:04 -05:00
|
|
|
assert_locked_or_safepoint(ClassLoaderDataGraph_lock); // caller locks.
|
2017-05-27 09:21:01 -04:00
|
|
|
// First, mark for unload all ClassLoaderData referencing a dead class loader.
|
2018-11-13 11:45:16 +01:00
|
|
|
unloading_occurred = ClassLoaderDataGraph::do_unloading();
|
2018-08-10 09:30:26 -04:00
|
|
|
if (unloading_occurred) {
|
2018-11-16 10:54:04 -05:00
|
|
|
MutexLockerEx ml2(is_concurrent ? Module_lock : NULL);
|
2018-08-28 10:10:11 -04:00
|
|
|
JFR_ONLY(Jfr::on_unloading_classes();)
|
2018-11-16 10:54:04 -05:00
|
|
|
MutexLockerEx ml1(is_concurrent ? SystemDictionary_lock : NULL);
|
2018-08-10 09:30:26 -04:00
|
|
|
ClassLoaderDataGraph::clean_module_and_package_info();
|
|
|
|
}
|
2017-05-27 09:21:01 -04:00
|
|
|
}
|
|
|
|
|
2018-11-16 10:54:04 -05:00
|
|
|
// Cleanup ResolvedMethodTable even if no unloading occurred.
|
|
|
|
{
|
|
|
|
GCTraceTime(Debug, gc, phases) t("ResolvedMethodTable", gc_timer);
|
|
|
|
ResolvedMethodTable::trigger_cleanup();
|
|
|
|
}
|
|
|
|
|
2014-08-14 09:15:39 +02:00
|
|
|
if (unloading_occurred) {
|
2018-08-15 16:01:48 -04:00
|
|
|
{
|
|
|
|
GCTraceTime(Debug, gc, phases) t("SymbolTable", gc_timer);
|
|
|
|
// Check if there's work to do in the SymbolTable
|
|
|
|
SymbolTable::do_check_concurrent_work();
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2018-11-16 10:54:04 -05:00
|
|
|
MutexLockerEx ml(is_concurrent ? SystemDictionary_lock : NULL);
|
2018-08-15 16:01:48 -04:00
|
|
|
GCTraceTime(Debug, gc, phases) t("Dictionary", gc_timer);
|
|
|
|
constraints()->purge_loader_constraints();
|
|
|
|
resolution_errors()->purge_resolution_errors();
|
|
|
|
}
|
2017-05-27 09:21:01 -04:00
|
|
|
|
2018-11-16 10:54:04 -05:00
|
|
|
{
|
|
|
|
GCTraceTime(Debug, gc, phases) t("ResolvedMethodTable", gc_timer);
|
|
|
|
// Oops referenced by the protection domain cache table may get unreachable independently
|
|
|
|
// of the class loader (eg. cached protection domain oops). So we need to
|
|
|
|
// explicitly unlink them here.
|
|
|
|
// All protection domain oops are linked to the caller class, so if nothing
|
|
|
|
// unloads, this is not needed.
|
|
|
|
_pd_cache_table->trigger_cleanup();
|
|
|
|
}
|
2017-05-27 09:21:01 -04:00
|
|
|
}
|
|
|
|
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
return unloading_occurred;
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SystemDictionary::oops_do(OopClosure* f) {
|
|
|
|
f->do_oop(&_java_system_loader);
|
2017-10-10 14:38:56 -07:00
|
|
|
f->do_oop(&_java_platform_loader);
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
f->do_oop(&_system_loader_lock_obj);
|
2014-08-12 17:29:00 -07:00
|
|
|
CDS_ONLY(SystemDictionaryShared::oops_do(f);)
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2009-04-08 10:56:49 -07:00
|
|
|
// Visit extra methods
|
2010-10-19 02:52:57 -07:00
|
|
|
invoke_method_table()->oops_do(f);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2017-08-02 18:06:38 -07:00
|
|
|
// CDS: scan and relocate all classes referenced by _well_known_klasses[].
|
|
|
|
void SystemDictionary::well_known_klasses_do(MetaspaceClosure* it) {
|
|
|
|
for (int id = FIRST_WKID; id < WKID_LIMIT; id++) {
|
|
|
|
it->push(well_known_klass_addr((WKID)id));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
void SystemDictionary::methods_do(void f(Method*)) {
|
2017-04-12 08:02:29 -04:00
|
|
|
// Walk methods in loaded classes
|
2018-08-31 07:03:46 -04:00
|
|
|
MutexLocker ml(ClassLoaderDataGraph_lock);
|
2017-04-12 08:02:29 -04:00
|
|
|
ClassLoaderDataGraph::methods_do(f);
|
|
|
|
// Walk method handle intrinsics
|
2010-10-19 02:52:57 -07:00
|
|
|
invoke_method_table()->methods_do(f);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Initialization
|
|
|
|
|
|
|
|
void SystemDictionary::initialize(TRAPS) {
|
|
|
|
// Allocate arrays
|
2017-07-28 10:48:35 -04:00
|
|
|
_placeholders = new PlaceholderTable(_placeholder_table_size);
|
2007-12-01 00:00:00 +00:00
|
|
|
_number_of_modifications = 0;
|
2010-10-19 02:52:57 -07:00
|
|
|
_loader_constraints = new LoaderConstraintTable(_loader_constraint_size);
|
|
|
|
_resolution_errors = new ResolutionErrorTable(_resolution_error_size);
|
|
|
|
_invoke_method_table = new SymbolPropertyTable(_invoke_method_size);
|
2017-07-28 10:48:35 -04:00
|
|
|
_pd_cache_table = new ProtectionDomainCacheTable(defaultProtectionDomainCacheSize);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// Allocate private object used as system class loader lock
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
_system_loader_lock_obj = oopFactory::new_intArray(0, CHECK);
|
2007-12-01 00:00:00 +00:00
|
|
|
// Initialize basic classes
|
2018-10-17 15:57:10 -07:00
|
|
|
resolve_well_known_classes(CHECK);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2008-04-29 19:45:22 -07:00
|
|
|
// Compact table of directions on the initialization of klasses:
|
|
|
|
static const short wk_init_info[] = {
|
2018-10-18 23:05:01 -07:00
|
|
|
#define WK_KLASS_INIT_INFO(name, symbol) \
|
|
|
|
((short)vmSymbols::VM_SYMBOL_ENUM_NAME(symbol)),
|
|
|
|
|
2008-04-29 19:45:22 -07:00
|
|
|
WK_KLASSES_DO(WK_KLASS_INIT_INFO)
|
|
|
|
#undef WK_KLASS_INIT_INFO
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
2018-10-17 15:57:10 -07:00
|
|
|
#ifdef ASSERT
|
|
|
|
bool SystemDictionary::is_well_known_klass(Symbol* class_name) {
|
|
|
|
int sid;
|
|
|
|
for (int i = 0; (sid = wk_init_info[i]) != 0; i++) {
|
|
|
|
Symbol* symbol = vmSymbols::symbol_at((vmSymbols::SID)sid);
|
|
|
|
if (class_name == symbol) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-10-18 23:05:01 -07:00
|
|
|
bool SystemDictionary::resolve_wk_klass(WKID id, TRAPS) {
|
2008-04-29 19:45:22 -07:00
|
|
|
assert(id >= (int)FIRST_WKID && id < (int)WKID_LIMIT, "oob");
|
2018-10-18 23:05:01 -07:00
|
|
|
int sid = wk_init_info[id - FIRST_WKID];
|
2011-01-27 16:11:27 -08:00
|
|
|
Symbol* symbol = vmSymbols::symbol_at((vmSymbols::SID)sid);
|
2015-10-26 13:11:36 -04:00
|
|
|
InstanceKlass** klassp = &_well_known_klasses[id];
|
2016-03-31 15:52:07 -10:00
|
|
|
|
2018-10-18 23:05:01 -07:00
|
|
|
|
2016-03-31 15:52:07 -10:00
|
|
|
#if INCLUDE_JVMCI
|
2018-10-18 23:05:01 -07:00
|
|
|
if (id >= FIRST_JVMCI_WKID) {
|
|
|
|
assert(EnableJVMCI, "resolve JVMCI classes only when EnableJVMCI is true");
|
2016-03-31 15:52:07 -10:00
|
|
|
}
|
2018-10-18 23:05:01 -07:00
|
|
|
#endif
|
2016-03-31 15:52:07 -10:00
|
|
|
|
2013-01-25 10:04:08 -05:00
|
|
|
if ((*klassp) == NULL) {
|
2018-10-18 23:05:01 -07:00
|
|
|
Klass* k = resolve_or_fail(symbol, true, CHECK_0);
|
|
|
|
(*klassp) = InstanceKlass::cast(k);
|
2008-04-29 19:45:22 -07:00
|
|
|
}
|
2011-04-07 17:02:30 -07:00
|
|
|
return ((*klassp) != NULL);
|
2008-04-29 19:45:22 -07:00
|
|
|
}
|
|
|
|
|
2018-07-20 12:19:28 -07:00
|
|
|
void SystemDictionary::resolve_wk_klasses_until(WKID limit_id, WKID &start_id, TRAPS) {
|
2008-04-29 19:45:22 -07:00
|
|
|
assert((int)start_id <= (int)limit_id, "IDs are out of order!");
|
|
|
|
for (int id = (int)start_id; id < (int)limit_id; id++) {
|
|
|
|
assert(id >= (int)FIRST_WKID && id < (int)WKID_LIMIT, "oob");
|
2018-10-18 23:05:01 -07:00
|
|
|
resolve_wk_klass((WKID)id, CHECK);
|
2008-04-29 19:45:22 -07:00
|
|
|
}
|
2009-04-08 10:56:49 -07:00
|
|
|
|
|
|
|
// move the starting value forward to the limit:
|
|
|
|
start_id = limit_id;
|
2008-04-29 19:45:22 -07:00
|
|
|
}
|
|
|
|
|
2018-10-17 15:57:10 -07:00
|
|
|
void SystemDictionary::resolve_well_known_classes(TRAPS) {
|
|
|
|
assert(WK_KLASS(Object_klass) == NULL, "well-known classes should only be initialized once");
|
8142968: Module System implementation
Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282
Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Mark Reinhold <mark.reinhold@oracle.com>
Co-authored-by: Harold Seigel <harold.seigel@oracle.com>
Co-authored-by: Lois Foltan <lois.foltan@oracle.com>
Co-authored-by: Calvin Cheung <calvin.cheung@oracle.com>
Co-authored-by: Christian Tornqvist <christian.tornqvist@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Co-authored-by: George Triantafillou <george.triantafillou@oracle.com>
Co-authored-by: Igor Ignatyev <igor.ignatyev@oracle.com>
Co-authored-by: Ioi Lam <ioi.lam@oracle.com>
Co-authored-by: James Laskey <james.laskey@oracle.com>
Co-authored-by: Jean-Francois Denise <jean-francois.denise@oracle.com>
Co-authored-by: Jiangli Zhou <jiangli.zhou@oracle.com>
Co-authored-by: Markus Gronlund <markus.gronlund@oracle.com>
Co-authored-by: Serguei Spitsyn <serguei.spitsyn@oracle.com>
Co-authored-by: Staffan Larsen <staffan.larsen@oracle.com>
Co-authored-by: Sundararajan Athijegannathan <sundararajan.athijegannathan@oracle.com>
Reviewed-by: acorn, ccheung, coleenp, ctornqvi, dholmes, dsimms, gtriantafill, iklam, jiangli, mgronlun, mseledtsov, cjplummer, sspitsyn, stefank, twisti, hseigel, lfoltan, alanb, mchung, dfazunen
2016-03-17 19:04:01 +00:00
|
|
|
|
|
|
|
// Create the ModuleEntry for java.base. This call needs to be done here,
|
|
|
|
// after vmSymbols::initialize() is called but before any classes are pre-loaded.
|
2016-07-26 10:29:27 -04:00
|
|
|
ClassLoader::classLoader_init2(CHECK);
|
8142968: Module System implementation
Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282
Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Mark Reinhold <mark.reinhold@oracle.com>
Co-authored-by: Harold Seigel <harold.seigel@oracle.com>
Co-authored-by: Lois Foltan <lois.foltan@oracle.com>
Co-authored-by: Calvin Cheung <calvin.cheung@oracle.com>
Co-authored-by: Christian Tornqvist <christian.tornqvist@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Co-authored-by: George Triantafillou <george.triantafillou@oracle.com>
Co-authored-by: Igor Ignatyev <igor.ignatyev@oracle.com>
Co-authored-by: Ioi Lam <ioi.lam@oracle.com>
Co-authored-by: James Laskey <james.laskey@oracle.com>
Co-authored-by: Jean-Francois Denise <jean-francois.denise@oracle.com>
Co-authored-by: Jiangli Zhou <jiangli.zhou@oracle.com>
Co-authored-by: Markus Gronlund <markus.gronlund@oracle.com>
Co-authored-by: Serguei Spitsyn <serguei.spitsyn@oracle.com>
Co-authored-by: Staffan Larsen <staffan.larsen@oracle.com>
Co-authored-by: Sundararajan Athijegannathan <sundararajan.athijegannathan@oracle.com>
Reviewed-by: acorn, ccheung, coleenp, ctornqvi, dholmes, dsimms, gtriantafill, iklam, jiangli, mgronlun, mseledtsov, cjplummer, sspitsyn, stefank, twisti, hseigel, lfoltan, alanb, mchung, dfazunen
2016-03-17 19:04:01 +00:00
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
// Preload commonly used klasses
|
2008-04-29 19:45:22 -07:00
|
|
|
WKID scan = FIRST_WKID;
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
// first do Object, then String, Class
|
2017-07-18 15:46:04 -04:00
|
|
|
#if INCLUDE_CDS
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
if (UseSharedSpaces) {
|
2018-07-20 12:19:28 -07:00
|
|
|
resolve_wk_klasses_through(WK_KLASS_ENUM_NAME(Object_klass), scan, CHECK);
|
2018-09-07 15:18:14 -04:00
|
|
|
|
|
|
|
// It's unsafe to access the archived heap regions before they
|
|
|
|
// are fixed up, so we must do the fixup as early as possible
|
|
|
|
// before the archived java objects are accessed by functions
|
|
|
|
// such as java_lang_Class::restore_archived_mirror and
|
|
|
|
// ConstantPool::restore_unshareable_info (restores the archived
|
|
|
|
// resolved_references array object).
|
|
|
|
//
|
2018-10-09 15:58:07 -04:00
|
|
|
// HeapShared::fixup_mapped_heap_regions() fills the empty
|
2018-09-07 15:18:14 -04:00
|
|
|
// spaces in the archived heap regions and may use
|
|
|
|
// SystemDictionary::Object_klass(), so we can do this only after
|
|
|
|
// Object_klass is resolved. See the above resolve_wk_klasses_through()
|
|
|
|
// call. No mirror objects are accessed/restored in the above call.
|
|
|
|
// Mirrors are restored after java.lang.Class is loaded.
|
2018-10-09 15:58:07 -04:00
|
|
|
HeapShared::fixup_mapped_heap_regions();
|
2018-09-07 15:18:14 -04:00
|
|
|
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
// Initialize the constant pool for the Object_class
|
2018-11-07 19:40:27 -08:00
|
|
|
assert(Object_klass()->is_shared(), "must be");
|
2017-03-15 10:25:37 -04:00
|
|
|
Object_klass()->constants()->restore_unshareable_info(CHECK);
|
2018-07-20 12:19:28 -07:00
|
|
|
resolve_wk_klasses_through(WK_KLASS_ENUM_NAME(Class_klass), scan, CHECK);
|
2017-07-18 15:46:04 -04:00
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
2018-07-20 12:19:28 -07:00
|
|
|
resolve_wk_klasses_through(WK_KLASS_ENUM_NAME(Class_klass), scan, CHECK);
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
}
|
2008-04-29 19:45:22 -07:00
|
|
|
|
2012-05-14 09:36:00 -07:00
|
|
|
// Calculate offsets for String and Class classes since they are loaded and
|
|
|
|
// can be used after this point.
|
|
|
|
java_lang_String::compute_offsets();
|
2011-09-10 17:29:02 -07:00
|
|
|
java_lang_Class::compute_offsets();
|
2008-04-29 19:45:22 -07:00
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
// Fixup mirrors for classes loaded before java.lang.Class.
|
|
|
|
// These calls iterate over the objects currently in the perm gen
|
|
|
|
// so calling them at this point is matters (not before when there
|
|
|
|
// are fewer objects and not later after there are more objects
|
|
|
|
// in the perm gen.
|
|
|
|
Universe::initialize_basic_type_mirrors(CHECK);
|
|
|
|
Universe::fixup_mirrors(CHECK);
|
|
|
|
|
2008-04-29 19:45:22 -07:00
|
|
|
// do a bunch more:
|
2018-07-20 12:19:28 -07:00
|
|
|
resolve_wk_klasses_through(WK_KLASS_ENUM_NAME(Reference_klass), scan, CHECK);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// Preload ref klasses and set reference types
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
InstanceKlass::cast(WK_KLASS(Reference_klass))->set_reference_type(REF_OTHER);
|
2012-09-07 12:04:16 -04:00
|
|
|
InstanceRefKlass::update_nonstatic_oop_maps(WK_KLASS(Reference_klass));
|
2008-04-29 19:45:22 -07:00
|
|
|
|
2018-07-20 12:19:28 -07:00
|
|
|
resolve_wk_klasses_through(WK_KLASS_ENUM_NAME(PhantomReference_klass), scan, CHECK);
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
InstanceKlass::cast(WK_KLASS(SoftReference_klass))->set_reference_type(REF_SOFT);
|
|
|
|
InstanceKlass::cast(WK_KLASS(WeakReference_klass))->set_reference_type(REF_WEAK);
|
|
|
|
InstanceKlass::cast(WK_KLASS(FinalReference_klass))->set_reference_type(REF_FINAL);
|
|
|
|
InstanceKlass::cast(WK_KLASS(PhantomReference_klass))->set_reference_type(REF_PHANTOM);
|
2008-04-29 19:45:22 -07:00
|
|
|
|
2011-03-31 02:31:57 -07:00
|
|
|
// JSR 292 classes
|
|
|
|
WKID jsr292_group_start = WK_KLASS_ENUM_NAME(MethodHandle_klass);
|
2011-08-16 04:14:05 -07:00
|
|
|
WKID jsr292_group_end = WK_KLASS_ENUM_NAME(VolatileCallSite_klass);
|
2018-07-20 12:19:28 -07:00
|
|
|
resolve_wk_klasses_until(jsr292_group_start, scan, CHECK);
|
|
|
|
resolve_wk_klasses_through(jsr292_group_end, scan, CHECK);
|
2018-10-17 15:57:10 -07:00
|
|
|
WKID last = NOT_JVMCI(WKID_LIMIT) JVMCI_ONLY(FIRST_JVMCI_WKID);
|
|
|
|
resolve_wk_klasses_until(last, scan, CHECK);
|
2008-04-29 19:45:22 -07:00
|
|
|
|
2010-01-06 14:22:39 -08:00
|
|
|
_box_klasses[T_BOOLEAN] = WK_KLASS(Boolean_klass);
|
|
|
|
_box_klasses[T_CHAR] = WK_KLASS(Character_klass);
|
|
|
|
_box_klasses[T_FLOAT] = WK_KLASS(Float_klass);
|
|
|
|
_box_klasses[T_DOUBLE] = WK_KLASS(Double_klass);
|
|
|
|
_box_klasses[T_BYTE] = WK_KLASS(Byte_klass);
|
|
|
|
_box_klasses[T_SHORT] = WK_KLASS(Short_klass);
|
|
|
|
_box_klasses[T_INT] = WK_KLASS(Integer_klass);
|
|
|
|
_box_klasses[T_LONG] = WK_KLASS(Long_klass);
|
2008-04-29 19:45:22 -07:00
|
|
|
//_box_klasses[T_OBJECT] = WK_KLASS(object_klass);
|
|
|
|
//_box_klasses[T_ARRAY] = WK_KLASS(object_klass);
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
{ // Compute whether we should use checkPackageAccess or NOT
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
Method* method = InstanceKlass::cast(ClassLoader_klass())->find_method(vmSymbols::checkPackageAccess_name(), vmSymbols::class_protectiondomain_signature());
|
2007-12-01 00:00:00 +00:00
|
|
|
_has_checkPackageAccess = (method != NULL);
|
|
|
|
}
|
2018-10-17 15:57:10 -07:00
|
|
|
|
|
|
|
#ifdef ASSERT
|
|
|
|
if (UseSharedSpaces) {
|
|
|
|
assert(JvmtiExport::is_early_phase(),
|
|
|
|
"All well known classes must be resolved in JVMTI early phase");
|
|
|
|
for (int i = FIRST_WKID; i < last; i++) {
|
|
|
|
InstanceKlass* k = _well_known_klasses[i];
|
|
|
|
assert(k->is_shared(), "must not be replaced by JVMTI class file load hook");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Tells if a given klass is a box (wrapper class, such as java.lang.Integer).
|
|
|
|
// If so, returns the basic type it holds. If not, returns T_OBJECT.
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
BasicType SystemDictionary::box_klass_type(Klass* k) {
|
2007-12-01 00:00:00 +00:00
|
|
|
assert(k != NULL, "");
|
|
|
|
for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
|
|
|
|
if (_box_klasses[i] == k)
|
|
|
|
return (BasicType)i;
|
|
|
|
}
|
|
|
|
return T_OBJECT;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Constraints on class loaders. The details of the algorithm can be
|
|
|
|
// found in the OOPSLA'98 paper "Dynamic Class Loading in the Java
|
|
|
|
// Virtual Machine" by Sheng Liang and Gilad Bracha. The basic idea is
|
2017-07-28 10:48:35 -04:00
|
|
|
// that the dictionary needs to maintain a set of contraints that
|
2007-12-01 00:00:00 +00:00
|
|
|
// must be satisfied by all classes in the dictionary.
|
2017-07-28 10:48:35 -04:00
|
|
|
// if defining is true, then LinkageError if already in dictionary
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
// if initiating loader, then ok if InstanceKlass matches existing entry
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2017-11-02 11:00:34 -05:00
|
|
|
void SystemDictionary::check_constraints(unsigned int d_hash,
|
2017-03-15 10:25:37 -04:00
|
|
|
InstanceKlass* k,
|
2018-05-07 11:38:21 +02:00
|
|
|
Handle class_loader,
|
|
|
|
bool defining,
|
2007-12-01 00:00:00 +00:00
|
|
|
TRAPS) {
|
2018-05-07 11:38:21 +02:00
|
|
|
ResourceMark rm(THREAD);
|
|
|
|
stringStream ss;
|
|
|
|
bool throwException = false;
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
{
|
2018-05-18 10:59:04 +02:00
|
|
|
Symbol *name = k->name();
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
ClassLoaderData *loader_data = class_loader_data(class_loader);
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
MutexLocker mu(SystemDictionary_lock, THREAD);
|
|
|
|
|
2017-11-02 11:00:34 -05:00
|
|
|
InstanceKlass* check = find_class(d_hash, name, loader_data->dictionary());
|
2017-03-15 10:25:37 -04:00
|
|
|
if (check != NULL) {
|
2018-05-07 11:38:21 +02:00
|
|
|
// If different InstanceKlass - duplicate class definition,
|
|
|
|
// else - ok, class loaded by a different thread in parallel.
|
|
|
|
// We should only have found it if it was done loading and ok to use.
|
|
|
|
// The dictionary only holds instance classes, placeholders
|
|
|
|
// also hold array classes.
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2015-10-28 09:47:23 -04:00
|
|
|
assert(check->is_instance_klass(), "noninstance in systemdictionary");
|
2017-03-15 10:25:37 -04:00
|
|
|
if ((defining == true) || (k != check)) {
|
2018-05-07 11:38:21 +02:00
|
|
|
throwException = true;
|
2018-07-16 11:34:17 -04:00
|
|
|
ss.print("loader %s", loader_data->loader_name_and_id());
|
|
|
|
ss.print(" attempted duplicate %s definition for %s. (%s)",
|
|
|
|
k->external_kind(), k->external_name(), k->class_in_module_of_loader(false, true));
|
2007-12-01 00:00:00 +00:00
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef ASSERT
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
Symbol* ph_check = find_placeholder(name, loader_data);
|
2011-01-27 16:11:27 -08:00
|
|
|
assert(ph_check == NULL || ph_check == name, "invalid symbol");
|
2007-12-01 00:00:00 +00:00
|
|
|
#endif
|
|
|
|
|
2018-05-07 11:38:21 +02:00
|
|
|
if (throwException == false) {
|
2007-12-01 00:00:00 +00:00
|
|
|
if (constraints()->check_or_update(k, class_loader, name) == false) {
|
2018-05-07 11:38:21 +02:00
|
|
|
throwException = true;
|
2018-07-16 11:34:17 -04:00
|
|
|
ss.print("loader constraint violation: loader %s", loader_data->loader_name_and_id());
|
2018-05-07 11:38:21 +02:00
|
|
|
ss.print(" wants to load %s %s.",
|
|
|
|
k->external_kind(), k->external_name());
|
|
|
|
Klass *existing_klass = constraints()->find_constrained_klass(name, class_loader);
|
|
|
|
if (existing_klass->class_loader() != class_loader()) {
|
2018-07-16 11:34:17 -04:00
|
|
|
ss.print(" A different %s with the same name was previously loaded by %s. (%s)",
|
2018-05-07 11:38:21 +02:00
|
|
|
existing_klass->external_kind(),
|
2018-07-16 11:34:17 -04:00
|
|
|
existing_klass->class_loader_data()->loader_name_and_id(),
|
|
|
|
existing_klass->class_in_module_of_loader(false, true));
|
|
|
|
} else {
|
|
|
|
ss.print(" (%s)", k->class_in_module_of_loader(false, true));
|
2018-05-07 11:38:21 +02:00
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Throw error now if needed (cannot throw while holding
|
|
|
|
// SystemDictionary_lock because of rank ordering)
|
2018-05-07 11:38:21 +02:00
|
|
|
if (throwException == true) {
|
|
|
|
THROW_MSG(vmSymbols::java_lang_LinkageError(), ss.as_string());
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-28 10:48:35 -04:00
|
|
|
// Update class loader data dictionary - done after check_constraint and add_to_hierachy
|
2007-12-01 00:00:00 +00:00
|
|
|
// have been called.
|
2017-11-02 11:00:34 -05:00
|
|
|
void SystemDictionary::update_dictionary(unsigned int d_hash,
|
2007-12-01 00:00:00 +00:00
|
|
|
int p_index, unsigned int p_hash,
|
2017-03-15 10:25:37 -04:00
|
|
|
InstanceKlass* k,
|
2007-12-01 00:00:00 +00:00
|
|
|
Handle class_loader,
|
|
|
|
TRAPS) {
|
|
|
|
// Compile_lock prevents systemDictionary updates during compilations
|
|
|
|
assert_locked_or_safepoint(Compile_lock);
|
2011-01-27 16:11:27 -08:00
|
|
|
Symbol* name = k->name();
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
ClassLoaderData *loader_data = class_loader_data(class_loader);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
{
|
2017-07-28 10:48:35 -04:00
|
|
|
MutexLocker mu1(SystemDictionary_lock, THREAD);
|
|
|
|
|
|
|
|
// See whether biased locking is enabled and if so set it for this
|
|
|
|
// klass.
|
|
|
|
// Note that this must be done past the last potential blocking
|
|
|
|
// point / safepoint. We enable biased locking lazily using a
|
|
|
|
// VM_Operation to iterate the SystemDictionary and installing the
|
|
|
|
// biasable mark word into each InstanceKlass's prototype header.
|
|
|
|
// To avoid race conditions where we accidentally miss enabling the
|
|
|
|
// optimization for one class in the process of being added to the
|
|
|
|
// dictionary, we must not safepoint after the test of
|
|
|
|
// BiasedLocking::enabled().
|
|
|
|
if (UseBiasedLocking && BiasedLocking::enabled()) {
|
|
|
|
// Set biased locking bit for all loaded classes; it will be
|
|
|
|
// cleared if revocation occurs too often for this type
|
|
|
|
// NOTE that we must only do this when the class is initally
|
|
|
|
// defined, not each time it is referenced from a new class loader
|
2018-04-03 13:15:27 +02:00
|
|
|
if (oopDesc::equals(k->class_loader(), class_loader())) {
|
2017-07-28 10:48:35 -04:00
|
|
|
k->set_prototype_header(markOopDesc::biased_locking_prototype());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make a new dictionary entry.
|
|
|
|
Dictionary* dictionary = loader_data->dictionary();
|
2017-11-02 11:00:34 -05:00
|
|
|
InstanceKlass* sd_check = find_class(d_hash, name, dictionary);
|
2017-07-28 10:48:35 -04:00
|
|
|
if (sd_check == NULL) {
|
2017-11-02 11:00:34 -05:00
|
|
|
dictionary->add_klass(d_hash, name, k);
|
2017-07-28 10:48:35 -04:00
|
|
|
notice_modification();
|
|
|
|
}
|
|
|
|
#ifdef ASSERT
|
2017-11-02 11:00:34 -05:00
|
|
|
sd_check = find_class(d_hash, name, dictionary);
|
2017-07-28 10:48:35 -04:00
|
|
|
assert (sd_check != NULL, "should have entry in dictionary");
|
|
|
|
// Note: there may be a placeholder entry: for circularity testing
|
|
|
|
// or for parallel defines
|
|
|
|
#endif
|
2007-12-01 00:00:00 +00:00
|
|
|
SystemDictionary_lock->notify_all();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-31 17:48:21 -08:00
|
|
|
// Try to find a class name using the loader constraints. The
|
|
|
|
// loader constraints might know about a class that isn't fully loaded
|
|
|
|
// yet and these will be ignored.
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
Klass* SystemDictionary::find_constrained_instance_or_array_klass(
|
2011-01-27 16:11:27 -08:00
|
|
|
Symbol* class_name, Handle class_loader, TRAPS) {
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// First see if it has been loaded directly.
|
|
|
|
// Force the protection domain to be null. (This removes protection checks.)
|
|
|
|
Handle no_protection_domain;
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
Klass* klass = find_instance_or_array_klass(class_name, class_loader,
|
2012-09-29 06:40:00 -04:00
|
|
|
no_protection_domain, CHECK_NULL);
|
2007-12-01 00:00:00 +00:00
|
|
|
if (klass != NULL)
|
|
|
|
return klass;
|
|
|
|
|
|
|
|
// Now look to see if it has been loaded elsewhere, and is subject to
|
|
|
|
// a loader constraint that would require this loader to return the
|
|
|
|
// klass that is already loaded.
|
2011-01-27 16:11:27 -08:00
|
|
|
if (FieldType::is_array(class_name)) {
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
// For array classes, their Klass*s are not kept in the
|
|
|
|
// constraint table. The element Klass*s are.
|
2011-01-27 16:11:27 -08:00
|
|
|
FieldArrayInfo fd;
|
|
|
|
BasicType t = FieldType::get_array_info(class_name, fd, CHECK_(NULL));
|
2007-12-01 00:00:00 +00:00
|
|
|
if (t != T_OBJECT) {
|
|
|
|
klass = Universe::typeArrayKlassObj(t);
|
|
|
|
} else {
|
|
|
|
MutexLocker mu(SystemDictionary_lock, THREAD);
|
2011-01-27 16:11:27 -08:00
|
|
|
klass = constraints()->find_constrained_klass(fd.object_key(), class_loader);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
2010-01-19 16:03:09 -05:00
|
|
|
// If element class already loaded, allocate array klass
|
2007-12-01 00:00:00 +00:00
|
|
|
if (klass != NULL) {
|
2012-11-12 16:15:05 -05:00
|
|
|
klass = klass->array_klass_or_null(fd.dimension());
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
MutexLocker mu(SystemDictionary_lock, THREAD);
|
|
|
|
// Non-array classes are easy: simply check the constraint table.
|
|
|
|
klass = constraints()->find_constrained_klass(class_name, class_loader);
|
|
|
|
}
|
|
|
|
|
|
|
|
return klass;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-27 16:11:27 -08:00
|
|
|
bool SystemDictionary::add_loader_constraint(Symbol* class_name,
|
2007-12-01 00:00:00 +00:00
|
|
|
Handle class_loader1,
|
|
|
|
Handle class_loader2,
|
|
|
|
Thread* THREAD) {
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
ClassLoaderData* loader_data1 = class_loader_data(class_loader1);
|
|
|
|
ClassLoaderData* loader_data2 = class_loader_data(class_loader2);
|
|
|
|
|
2011-01-27 16:11:27 -08:00
|
|
|
Symbol* constraint_name = NULL;
|
2018-07-20 14:52:11 -04:00
|
|
|
// Needs to be in same scope as constraint_name in case a Symbol is created and
|
|
|
|
// assigned to constraint_name.
|
|
|
|
FieldArrayInfo fd;
|
2011-01-27 16:11:27 -08:00
|
|
|
if (!FieldType::is_array(class_name)) {
|
2010-01-19 16:03:09 -05:00
|
|
|
constraint_name = class_name;
|
|
|
|
} else {
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
// For array classes, their Klass*s are not kept in the
|
2010-01-19 16:03:09 -05:00
|
|
|
// constraint table. The element classes are.
|
2011-01-27 16:11:27 -08:00
|
|
|
BasicType t = FieldType::get_array_info(class_name, fd, CHECK_(false));
|
2010-01-19 16:03:09 -05:00
|
|
|
// primitive types always pass
|
|
|
|
if (t != T_OBJECT) {
|
|
|
|
return true;
|
|
|
|
} else {
|
2011-01-27 16:11:27 -08:00
|
|
|
constraint_name = fd.object_key();
|
2010-01-19 16:03:09 -05:00
|
|
|
}
|
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2017-07-28 10:48:35 -04:00
|
|
|
Dictionary* dictionary1 = loader_data1->dictionary();
|
|
|
|
unsigned int d_hash1 = dictionary1->compute_hash(constraint_name);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2017-07-28 10:48:35 -04:00
|
|
|
Dictionary* dictionary2 = loader_data2->dictionary();
|
|
|
|
unsigned int d_hash2 = dictionary2->compute_hash(constraint_name);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2017-07-28 10:48:35 -04:00
|
|
|
{
|
|
|
|
MutexLocker mu_s(SystemDictionary_lock, THREAD);
|
2017-11-02 11:00:34 -05:00
|
|
|
InstanceKlass* klass1 = find_class(d_hash1, constraint_name, dictionary1);
|
|
|
|
InstanceKlass* klass2 = find_class(d_hash2, constraint_name, dictionary2);
|
2017-07-28 10:48:35 -04:00
|
|
|
return constraints()->add_entry(constraint_name, klass1, class_loader1,
|
|
|
|
klass2, class_loader2);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add entry to resolution error table to record the error when the first
|
|
|
|
// attempt to resolve a reference to a class has failed.
|
2015-10-23 16:48:38 -04:00
|
|
|
void SystemDictionary::add_resolution_error(const constantPoolHandle& pool, int which,
|
2014-05-05 19:53:00 -04:00
|
|
|
Symbol* error, Symbol* message) {
|
2007-12-01 00:00:00 +00:00
|
|
|
unsigned int hash = resolution_errors()->compute_hash(pool, which);
|
|
|
|
int index = resolution_errors()->hash_to_index(hash);
|
|
|
|
{
|
|
|
|
MutexLocker ml(SystemDictionary_lock, Thread::current());
|
2014-05-05 19:53:00 -04:00
|
|
|
resolution_errors()->add_entry(index, hash, pool, which, error, message);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
// Delete a resolution error for RedefineClasses for a constant pool is going away
|
|
|
|
void SystemDictionary::delete_resolution_error(ConstantPool* pool) {
|
|
|
|
resolution_errors()->delete_entry(pool);
|
|
|
|
}
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
// Lookup resolution error table. Returns error if found, otherwise NULL.
|
2015-10-23 16:48:38 -04:00
|
|
|
Symbol* SystemDictionary::find_resolution_error(const constantPoolHandle& pool, int which,
|
2014-05-05 19:53:00 -04:00
|
|
|
Symbol** message) {
|
2007-12-01 00:00:00 +00:00
|
|
|
unsigned int hash = resolution_errors()->compute_hash(pool, which);
|
|
|
|
int index = resolution_errors()->hash_to_index(hash);
|
|
|
|
{
|
|
|
|
MutexLocker ml(SystemDictionary_lock, Thread::current());
|
|
|
|
ResolutionErrorEntry* entry = resolution_errors()->find_entry(index, hash, pool, which);
|
2014-05-05 19:53:00 -04:00
|
|
|
if (entry != NULL) {
|
|
|
|
*message = entry->message();
|
|
|
|
return entry->error();
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-20 23:19:36 -07:00
|
|
|
// Signature constraints ensure that callers and callees agree about
|
|
|
|
// the meaning of type names in their signatures. This routine is the
|
|
|
|
// intake for constraints. It collects them from several places:
|
|
|
|
//
|
|
|
|
// * LinkResolver::resolve_method (if check_access is true) requires
|
|
|
|
// that the resolving class (the caller) and the defining class of
|
|
|
|
// the resolved method (the callee) agree on each type in the
|
|
|
|
// method's signature.
|
|
|
|
//
|
|
|
|
// * LinkResolver::resolve_interface_method performs exactly the same
|
|
|
|
// checks.
|
|
|
|
//
|
|
|
|
// * LinkResolver::resolve_field requires that the constant pool
|
|
|
|
// attempting to link to a field agree with the field's defining
|
|
|
|
// class about the type of the field signature.
|
|
|
|
//
|
|
|
|
// * klassVtable::initialize_vtable requires that, when a class
|
|
|
|
// overrides a vtable entry allocated by a superclass, that the
|
|
|
|
// overriding method (i.e., the callee) agree with the superclass
|
|
|
|
// on each type in the method's signature.
|
|
|
|
//
|
|
|
|
// * klassItable::initialize_itable requires that, when a class fills
|
|
|
|
// in its itables, for each non-abstract method installed in an
|
|
|
|
// itable, the method (i.e., the callee) agree with the interface
|
|
|
|
// on each type in the method's signature.
|
|
|
|
//
|
|
|
|
// All those methods have a boolean (check_access, checkconstraints)
|
|
|
|
// which turns off the checks. This is used from specialized contexts
|
|
|
|
// such as bootstrapping, dumping, and debugging.
|
|
|
|
//
|
|
|
|
// No direct constraint is placed between the class and its
|
|
|
|
// supertypes. Constraints are only placed along linked relations
|
|
|
|
// between callers and callees. When a method overrides or implements
|
|
|
|
// an abstract method in a supertype (superclass or interface), the
|
|
|
|
// constraints are placed as if the supertype were the caller to the
|
|
|
|
// overriding method. (This works well, since callers to the
|
|
|
|
// supertype have already established agreement between themselves and
|
|
|
|
// the supertype.) As a result of all this, a class can disagree with
|
|
|
|
// its supertype about the meaning of a type name, as long as that
|
|
|
|
// class neither calls a relevant method of the supertype, nor is
|
|
|
|
// called (perhaps via an override) from the supertype.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// SystemDictionary::check_signature_loaders(sig, l1, l2)
|
|
|
|
//
|
2007-12-01 00:00:00 +00:00
|
|
|
// Make sure all class components (including arrays) in the given
|
|
|
|
// signature will be resolved to the same class in both loaders.
|
|
|
|
// Returns the name of the type that failed a loader constraint check, or
|
2013-03-27 14:10:59 -04:00
|
|
|
// NULL if no constraint failed. No exception except OOME is thrown.
|
2010-01-19 16:03:09 -05:00
|
|
|
// Arrays are not added to the loader constraint table, their elements are.
|
2013-03-27 14:10:59 -04:00
|
|
|
Symbol* SystemDictionary::check_signature_loaders(Symbol* signature,
|
2007-12-01 00:00:00 +00:00
|
|
|
Handle loader1, Handle loader2,
|
|
|
|
bool is_method, TRAPS) {
|
|
|
|
// Nothing to do if loaders are the same.
|
2018-04-03 13:15:27 +02:00
|
|
|
if (oopDesc::equals(loader1(), loader2())) {
|
2007-12-01 00:00:00 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
SignatureStream sig_strm(signature, is_method);
|
|
|
|
while (!sig_strm.is_done()) {
|
|
|
|
if (sig_strm.is_object()) {
|
2013-03-27 14:10:59 -04:00
|
|
|
Symbol* sig = sig_strm.as_symbol(CHECK_NULL);
|
2007-12-01 00:00:00 +00:00
|
|
|
if (!add_loader_constraint(sig, loader1, loader2, THREAD)) {
|
2013-03-27 14:10:59 -04:00
|
|
|
return sig;
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
sig_strm.next();
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-24 10:51:00 -07:00
|
|
|
methodHandle SystemDictionary::find_method_handle_intrinsic(vmIntrinsics::ID iid,
|
|
|
|
Symbol* signature,
|
|
|
|
TRAPS) {
|
|
|
|
methodHandle empty;
|
|
|
|
assert(MethodHandles::is_signature_polymorphic(iid) &&
|
|
|
|
MethodHandles::is_signature_polymorphic_intrinsic(iid) &&
|
|
|
|
iid != vmIntrinsics::_invokeGeneric,
|
2015-09-29 11:02:08 +02:00
|
|
|
"must be a known MH intrinsic iid=%d: %s", iid, vmIntrinsics::name_at(iid));
|
2012-07-24 10:51:00 -07:00
|
|
|
|
|
|
|
unsigned int hash = invoke_method_table()->compute_hash(signature, iid);
|
2009-04-08 10:56:49 -07:00
|
|
|
int index = invoke_method_table()->hash_to_index(hash);
|
2012-07-24 10:51:00 -07:00
|
|
|
SymbolPropertyEntry* spe = invoke_method_table()->find_entry(index, hash, signature, iid);
|
|
|
|
methodHandle m;
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
if (spe == NULL || spe->method() == NULL) {
|
2010-05-01 21:57:35 -07:00
|
|
|
spe = NULL;
|
2009-04-08 10:56:49 -07:00
|
|
|
// Must create lots of stuff here, but outside of the SystemDictionary lock.
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
m = Method::make_method_handle_intrinsic(iid, signature, CHECK_(empty));
|
2014-09-26 20:09:02 -07:00
|
|
|
if (!Arguments::is_interpreter_only()) {
|
|
|
|
// Generate a compiled form of the MH intrinsic.
|
|
|
|
AdapterHandlerLibrary::create_native_wrapper(m);
|
|
|
|
// Check if have the compiled code.
|
|
|
|
if (!m->has_compiled_code()) {
|
|
|
|
THROW_MSG_(vmSymbols::java_lang_VirtualMachineError(),
|
2015-11-24 15:50:27 +03:00
|
|
|
"Out of space in CodeCache for method handle intrinsic", empty);
|
2014-09-26 20:09:02 -07:00
|
|
|
}
|
2014-09-10 19:08:17 -07:00
|
|
|
}
|
2009-04-08 10:56:49 -07:00
|
|
|
// Now grab the lock. We might have to throw away the new method,
|
|
|
|
// if a racing thread has managed to install one at the same time.
|
2012-07-24 10:51:00 -07:00
|
|
|
{
|
|
|
|
MutexLocker ml(SystemDictionary_lock, THREAD);
|
|
|
|
spe = invoke_method_table()->find_entry(index, hash, signature, iid);
|
2009-04-08 10:56:49 -07:00
|
|
|
if (spe == NULL)
|
2012-07-24 10:51:00 -07:00
|
|
|
spe = invoke_method_table()->add_entry(index, hash, signature, iid);
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
if (spe->method() == NULL)
|
|
|
|
spe->set_method(m());
|
2012-07-24 10:51:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
assert(spe != NULL && spe->method() != NULL, "");
|
2014-09-10 19:08:17 -07:00
|
|
|
assert(Arguments::is_interpreter_only() || (spe->method()->has_compiled_code() &&
|
2014-09-05 14:39:45 -07:00
|
|
|
spe->method()->code()->entry_point() == spe->method()->from_compiled_entry()),
|
|
|
|
"MH intrinsic invariant");
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
return spe->method();
|
2012-07-24 10:51:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Helper for unpacking the return value from linkMethod and linkCallSite.
|
|
|
|
static methodHandle unpack_method_and_appendix(Handle mname,
|
2017-03-15 10:25:37 -04:00
|
|
|
Klass* accessing_klass,
|
2012-07-24 10:51:00 -07:00
|
|
|
objArrayHandle appendix_box,
|
|
|
|
Handle* appendix_result,
|
|
|
|
TRAPS) {
|
|
|
|
methodHandle empty;
|
|
|
|
if (mname.not_null()) {
|
2017-05-27 09:21:01 -04:00
|
|
|
Method* m = java_lang_invoke_MemberName::vmtarget(mname());
|
|
|
|
if (m != NULL) {
|
2012-07-24 10:51:00 -07:00
|
|
|
oop appendix = appendix_box->obj_at(0);
|
|
|
|
if (TraceMethodHandles) {
|
|
|
|
#ifndef PRODUCT
|
2015-12-18 20:23:27 +03:00
|
|
|
ttyLocker ttyl;
|
2014-05-09 16:50:54 -04:00
|
|
|
tty->print("Linked method=" INTPTR_FORMAT ": ", p2i(m));
|
2012-07-24 10:51:00 -07:00
|
|
|
m->print();
|
|
|
|
if (appendix != NULL) { tty->print("appendix = "); appendix->print(); }
|
|
|
|
tty->cr();
|
|
|
|
#endif //PRODUCT
|
2011-05-06 16:33:13 -07:00
|
|
|
}
|
2012-07-24 10:51:00 -07:00
|
|
|
(*appendix_result) = Handle(THREAD, appendix);
|
2012-11-29 16:50:29 -05:00
|
|
|
// the target is stored in the cpCache and if a reference to this
|
2018-03-06 17:15:16 -05:00
|
|
|
// MemberName is dropped we need a way to make sure the
|
2012-11-29 16:50:29 -05:00
|
|
|
// class_loader containing this method is kept alive.
|
2017-03-15 10:25:37 -04:00
|
|
|
ClassLoaderData* this_key = accessing_klass->class_loader_data();
|
2018-03-06 17:15:16 -05:00
|
|
|
this_key->record_dependency(m->method_holder());
|
2012-07-24 10:51:00 -07:00
|
|
|
return methodHandle(THREAD, m);
|
2009-04-08 10:56:49 -07:00
|
|
|
}
|
|
|
|
}
|
2012-07-24 10:51:00 -07:00
|
|
|
THROW_MSG_(vmSymbols::java_lang_LinkageError(), "bad value from MethodHandleNatives", empty);
|
|
|
|
return empty;
|
|
|
|
}
|
|
|
|
|
2017-03-15 10:25:37 -04:00
|
|
|
methodHandle SystemDictionary::find_method_handle_invoker(Klass* klass,
|
2016-03-24 11:21:49 +01:00
|
|
|
Symbol* name,
|
2012-07-24 10:51:00 -07:00
|
|
|
Symbol* signature,
|
2017-03-15 10:25:37 -04:00
|
|
|
Klass* accessing_klass,
|
2012-10-01 14:50:10 -07:00
|
|
|
Handle *appendix_result,
|
|
|
|
Handle *method_type_result,
|
2012-07-24 10:51:00 -07:00
|
|
|
TRAPS) {
|
|
|
|
methodHandle empty;
|
2015-10-08 12:49:30 -10:00
|
|
|
assert(THREAD->can_call_java() ,"");
|
2012-07-24 10:51:00 -07:00
|
|
|
Handle method_type =
|
|
|
|
SystemDictionary::find_method_handle_type(signature, accessing_klass, CHECK_(empty));
|
|
|
|
|
|
|
|
int ref_kind = JVM_REF_invokeVirtual;
|
2017-02-15 22:59:57 -05:00
|
|
|
oop name_oop = StringTable::intern(name, CHECK_(empty));
|
|
|
|
Handle name_str (THREAD, name_oop);
|
|
|
|
objArrayHandle appendix_box = oopFactory::new_objArray_handle(SystemDictionary::Object_klass(), 1, CHECK_(empty));
|
2012-07-24 10:51:00 -07:00
|
|
|
assert(appendix_box->obj_at(0) == NULL, "");
|
|
|
|
|
2013-10-23 15:44:12 -07:00
|
|
|
// This should not happen. JDK code should take care of that.
|
2017-03-15 10:25:37 -04:00
|
|
|
if (accessing_klass == NULL || method_type.is_null()) {
|
2013-10-23 15:44:12 -07:00
|
|
|
THROW_MSG_(vmSymbols::java_lang_InternalError(), "bad invokehandle", empty);
|
|
|
|
}
|
|
|
|
|
2012-07-24 10:51:00 -07:00
|
|
|
// call java.lang.invoke.MethodHandleNatives::linkMethod(... String, MethodType) -> MemberName
|
|
|
|
JavaCallArguments args;
|
2017-03-15 10:25:37 -04:00
|
|
|
args.push_oop(Handle(THREAD, accessing_klass->java_mirror()));
|
2012-07-24 10:51:00 -07:00
|
|
|
args.push_int(ref_kind);
|
2017-03-15 10:25:37 -04:00
|
|
|
args.push_oop(Handle(THREAD, klass->java_mirror()));
|
2017-02-15 22:59:57 -05:00
|
|
|
args.push_oop(name_str);
|
|
|
|
args.push_oop(method_type);
|
|
|
|
args.push_oop(appendix_box);
|
2012-07-24 10:51:00 -07:00
|
|
|
JavaValue result(T_OBJECT);
|
|
|
|
JavaCalls::call_static(&result,
|
|
|
|
SystemDictionary::MethodHandleNatives_klass(),
|
|
|
|
vmSymbols::linkMethod_name(),
|
|
|
|
vmSymbols::linkMethod_signature(),
|
|
|
|
&args, CHECK_(empty));
|
|
|
|
Handle mname(THREAD, (oop) result.get_jobject());
|
2012-10-01 14:50:10 -07:00
|
|
|
(*method_type_result) = method_type;
|
2012-11-29 16:50:29 -05:00
|
|
|
return unpack_method_and_appendix(mname, accessing_klass, appendix_box, appendix_result, THREAD);
|
2009-04-08 10:56:49 -07:00
|
|
|
}
|
|
|
|
|
2015-04-14 19:10:28 +03:00
|
|
|
// Decide if we can globally cache a lookup of this class, to be returned to any client that asks.
|
|
|
|
// We must ensure that all class loaders everywhere will reach this class, for any client.
|
|
|
|
// This is a safe bet for public classes in java.lang, such as Object and String.
|
|
|
|
// We also include public classes in java.lang.invoke, because they appear frequently in system-level method types.
|
|
|
|
// Out of an abundance of caution, we do not include any other classes, not even for packages like java.util.
|
|
|
|
static bool is_always_visible_class(oop mirror) {
|
|
|
|
Klass* klass = java_lang_Class::as_Klass(mirror);
|
2015-10-28 09:47:23 -04:00
|
|
|
if (klass->is_objArray_klass()) {
|
2015-04-14 19:10:28 +03:00
|
|
|
klass = ObjArrayKlass::cast(klass)->bottom_klass(); // check element type
|
|
|
|
}
|
2015-10-28 09:47:23 -04:00
|
|
|
if (klass->is_typeArray_klass()) {
|
2015-04-14 19:10:28 +03:00
|
|
|
return true; // primitive array
|
|
|
|
}
|
2015-10-28 09:47:23 -04:00
|
|
|
assert(klass->is_instance_klass(), "%s", klass->external_name());
|
2015-04-14 19:10:28 +03:00
|
|
|
return klass->is_public() &&
|
|
|
|
(InstanceKlass::cast(klass)->is_same_class_package(SystemDictionary::Object_klass()) || // java.lang
|
|
|
|
InstanceKlass::cast(klass)->is_same_class_package(SystemDictionary::MethodHandle_klass())); // java.lang.invoke
|
|
|
|
}
|
2012-07-24 10:51:00 -07:00
|
|
|
|
2017-09-08 10:46:46 -07:00
|
|
|
|
|
|
|
// Return the Java mirror (java.lang.Class instance) for a single-character
|
|
|
|
// descriptor. This result, when available, is the same as produced by the
|
|
|
|
// heavier API point of the same name that takes a Symbol.
|
|
|
|
oop SystemDictionary::find_java_mirror_for_type(char signature_char) {
|
|
|
|
return java_lang_Class::primitive_mirror(char2type(signature_char));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find or construct the Java mirror (java.lang.Class instance) for a
|
|
|
|
// for the given field type signature, as interpreted relative to the
|
|
|
|
// given class loader. Handles primitives, void, references, arrays,
|
|
|
|
// and all other reflectable types, except method types.
|
|
|
|
// N.B. Code in reflection should use this entry point.
|
|
|
|
Handle SystemDictionary::find_java_mirror_for_type(Symbol* signature,
|
|
|
|
Klass* accessing_klass,
|
|
|
|
Handle class_loader,
|
|
|
|
Handle protection_domain,
|
|
|
|
SignatureStream::FailureMode failure_mode,
|
|
|
|
TRAPS) {
|
|
|
|
Handle empty;
|
|
|
|
|
|
|
|
assert(accessing_klass == NULL || (class_loader.is_null() && protection_domain.is_null()),
|
|
|
|
"one or the other, or perhaps neither");
|
|
|
|
|
|
|
|
Symbol* type = signature;
|
|
|
|
|
|
|
|
// What we have here must be a valid field descriptor,
|
|
|
|
// and all valid field descriptors are supported.
|
|
|
|
// Produce the same java.lang.Class that reflection reports.
|
|
|
|
if (type->utf8_length() == 1) {
|
|
|
|
|
|
|
|
// It's a primitive. (Void has a primitive mirror too.)
|
2018-10-03 09:46:46 -04:00
|
|
|
char ch = type->char_at(0);
|
2017-09-08 10:46:46 -07:00
|
|
|
assert(is_java_primitive(char2type(ch)) || ch == 'V', "");
|
|
|
|
return Handle(THREAD, find_java_mirror_for_type(ch));
|
|
|
|
|
|
|
|
} else if (FieldType::is_obj(type) || FieldType::is_array(type)) {
|
|
|
|
|
|
|
|
// It's a reference type.
|
|
|
|
if (accessing_klass != NULL) {
|
|
|
|
class_loader = Handle(THREAD, accessing_klass->class_loader());
|
|
|
|
protection_domain = Handle(THREAD, accessing_klass->protection_domain());
|
|
|
|
}
|
|
|
|
Klass* constant_type_klass;
|
|
|
|
if (failure_mode == SignatureStream::ReturnNull) {
|
|
|
|
constant_type_klass = resolve_or_null(type, class_loader, protection_domain,
|
|
|
|
CHECK_(empty));
|
|
|
|
} else {
|
|
|
|
bool throw_error = (failure_mode == SignatureStream::NCDFError);
|
|
|
|
constant_type_klass = resolve_or_fail(type, class_loader, protection_domain,
|
|
|
|
throw_error, CHECK_(empty));
|
|
|
|
}
|
|
|
|
if (constant_type_klass == NULL) {
|
|
|
|
return Handle(); // report failure this way
|
|
|
|
}
|
|
|
|
Handle mirror(THREAD, constant_type_klass->java_mirror());
|
|
|
|
|
|
|
|
// Check accessibility, emulating ConstantPool::verify_constant_pool_resolve.
|
|
|
|
if (accessing_klass != NULL) {
|
|
|
|
Klass* sel_klass = constant_type_klass;
|
|
|
|
bool fold_type_to_class = true;
|
|
|
|
LinkResolver::check_klass_accessability(accessing_klass, sel_klass,
|
|
|
|
fold_type_to_class, CHECK_(empty));
|
|
|
|
}
|
|
|
|
|
|
|
|
return mirror;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fall through to an error.
|
|
|
|
assert(false, "unsupported mirror syntax");
|
|
|
|
THROW_MSG_(vmSymbols::java_lang_InternalError(), "unsupported mirror syntax", empty);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-11 22:34:57 -08:00
|
|
|
// Ask Java code to find or construct a java.lang.invoke.MethodType for the given
|
2009-04-08 10:56:49 -07:00
|
|
|
// signature, as interpreted relative to the given class loader.
|
|
|
|
// Because of class loader constraints, all method handle usage must be
|
|
|
|
// consistent with this loader.
|
2011-01-27 16:11:27 -08:00
|
|
|
Handle SystemDictionary::find_method_handle_type(Symbol* signature,
|
2017-03-15 10:25:37 -04:00
|
|
|
Klass* accessing_klass,
|
2010-05-01 02:42:18 -07:00
|
|
|
TRAPS) {
|
2012-07-24 10:51:00 -07:00
|
|
|
Handle empty;
|
|
|
|
vmIntrinsics::ID null_iid = vmIntrinsics::_none; // distinct from all method handle invoker intrinsics
|
|
|
|
unsigned int hash = invoke_method_table()->compute_hash(signature, null_iid);
|
|
|
|
int index = invoke_method_table()->hash_to_index(hash);
|
|
|
|
SymbolPropertyEntry* spe = invoke_method_table()->find_entry(index, hash, signature, null_iid);
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
if (spe != NULL && spe->method_type() != NULL) {
|
|
|
|
assert(java_lang_invoke_MethodType::is_instance(spe->method_type()), "");
|
|
|
|
return Handle(THREAD, spe->method_type());
|
2015-10-08 12:49:30 -10:00
|
|
|
} else if (!THREAD->can_call_java()) {
|
2012-07-24 10:51:00 -07:00
|
|
|
warning("SystemDictionary::find_method_handle_type called from compiler thread"); // FIXME
|
|
|
|
return Handle(); // do not attempt from within compiler, unless it was cached
|
|
|
|
}
|
|
|
|
|
2010-05-01 21:57:35 -07:00
|
|
|
Handle class_loader, protection_domain;
|
2017-03-15 10:25:37 -04:00
|
|
|
if (accessing_klass != NULL) {
|
|
|
|
class_loader = Handle(THREAD, accessing_klass->class_loader());
|
|
|
|
protection_domain = Handle(THREAD, accessing_klass->protection_domain());
|
2015-04-14 19:10:28 +03:00
|
|
|
}
|
|
|
|
bool can_be_cached = true;
|
2011-01-27 16:11:27 -08:00
|
|
|
int npts = ArgumentCount(signature).size();
|
2017-02-15 22:59:57 -05:00
|
|
|
objArrayHandle pts = oopFactory::new_objArray_handle(SystemDictionary::Class_klass(), npts, CHECK_(empty));
|
2009-04-08 10:56:49 -07:00
|
|
|
int arg = 0;
|
2015-04-14 19:10:28 +03:00
|
|
|
Handle rt; // the return type from the signature
|
2011-01-27 16:11:27 -08:00
|
|
|
ResourceMark rm(THREAD);
|
|
|
|
for (SignatureStream ss(signature); !ss.is_done(); ss.next()) {
|
2010-05-01 21:57:35 -07:00
|
|
|
oop mirror = NULL;
|
2015-04-14 19:10:28 +03:00
|
|
|
if (can_be_cached) {
|
|
|
|
// Use neutral class loader to lookup candidate classes to be placed in the cache.
|
|
|
|
mirror = ss.as_java_mirror(Handle(), Handle(),
|
2010-05-01 21:57:35 -07:00
|
|
|
SignatureStream::ReturnNull, CHECK_(empty));
|
2015-04-14 19:10:28 +03:00
|
|
|
if (mirror == NULL || (ss.is_object() && !is_always_visible_class(mirror))) {
|
|
|
|
// Fall back to accessing_klass context.
|
|
|
|
can_be_cached = false;
|
2010-05-01 21:57:35 -07:00
|
|
|
}
|
|
|
|
}
|
2015-04-14 19:10:28 +03:00
|
|
|
if (!can_be_cached) {
|
2010-05-01 21:57:35 -07:00
|
|
|
// Resolve, throwing a real error if it doesn't work.
|
|
|
|
mirror = ss.as_java_mirror(class_loader, protection_domain,
|
|
|
|
SignatureStream::NCDFError, CHECK_(empty));
|
2009-04-08 10:56:49 -07:00
|
|
|
}
|
2018-03-15 21:24:10 +01:00
|
|
|
assert(mirror != NULL, "%s", ss.as_symbol(THREAD)->as_C_string());
|
2009-04-08 10:56:49 -07:00
|
|
|
if (ss.at_return_type())
|
|
|
|
rt = Handle(THREAD, mirror);
|
|
|
|
else
|
|
|
|
pts->obj_at_put(arg++, mirror);
|
2012-07-24 10:51:00 -07:00
|
|
|
|
2010-05-01 21:57:35 -07:00
|
|
|
// Check accessibility.
|
2017-09-08 10:46:46 -07:00
|
|
|
if (!java_lang_Class::is_primitive(mirror) && accessing_klass != NULL) {
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
Klass* sel_klass = java_lang_Class::as_Klass(mirror);
|
2012-07-24 10:51:00 -07:00
|
|
|
mirror = NULL; // safety
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
// Emulate ConstantPool::verify_constant_pool_resolve.
|
2017-09-08 10:46:46 -07:00
|
|
|
bool fold_type_to_class = true;
|
|
|
|
LinkResolver::check_klass_accessability(accessing_klass, sel_klass,
|
|
|
|
fold_type_to_class, CHECK_(empty));
|
2010-05-01 21:57:35 -07:00
|
|
|
}
|
2009-04-08 10:56:49 -07:00
|
|
|
}
|
|
|
|
assert(arg == npts, "");
|
|
|
|
|
2016-10-14 14:47:01 -07:00
|
|
|
// call java.lang.invoke.MethodHandleNatives::findMethodHandleType(Class rt, Class[] pts) -> MethodType
|
2009-04-08 10:56:49 -07:00
|
|
|
JavaCallArguments args(Handle(THREAD, rt()));
|
2017-02-15 22:59:57 -05:00
|
|
|
args.push_oop(pts);
|
2009-04-08 10:56:49 -07:00
|
|
|
JavaValue result(T_OBJECT);
|
|
|
|
JavaCalls::call_static(&result,
|
2010-05-01 02:42:18 -07:00
|
|
|
SystemDictionary::MethodHandleNatives_klass(),
|
|
|
|
vmSymbols::findMethodHandleType_name(),
|
2011-04-07 17:02:30 -07:00
|
|
|
vmSymbols::findMethodHandleType_signature(),
|
2009-04-08 10:56:49 -07:00
|
|
|
&args, CHECK_(empty));
|
2010-09-13 23:24:30 -07:00
|
|
|
Handle method_type(THREAD, (oop) result.get_jobject());
|
|
|
|
|
2015-04-14 19:10:28 +03:00
|
|
|
if (can_be_cached) {
|
2012-07-24 10:51:00 -07:00
|
|
|
// We can cache this MethodType inside the JVM.
|
|
|
|
MutexLocker ml(SystemDictionary_lock, THREAD);
|
|
|
|
spe = invoke_method_table()->find_entry(index, hash, signature, null_iid);
|
|
|
|
if (spe == NULL)
|
|
|
|
spe = invoke_method_table()->add_entry(index, hash, signature, null_iid);
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
if (spe->method_type() == NULL) {
|
|
|
|
spe->set_method_type(method_type());
|
2010-09-13 23:24:30 -07:00
|
|
|
}
|
|
|
|
}
|
2010-05-01 21:57:35 -07:00
|
|
|
|
2012-07-24 10:51:00 -07:00
|
|
|
// report back to the caller with the MethodType
|
2010-09-13 23:24:30 -07:00
|
|
|
return method_type;
|
2009-04-08 10:56:49 -07:00
|
|
|
}
|
|
|
|
|
2018-01-12 01:52:06 +03:00
|
|
|
Handle SystemDictionary::find_field_handle_type(Symbol* signature,
|
|
|
|
Klass* accessing_klass,
|
|
|
|
TRAPS) {
|
|
|
|
Handle empty;
|
|
|
|
ResourceMark rm(THREAD);
|
|
|
|
SignatureStream ss(signature, /*is_method=*/ false);
|
|
|
|
if (!ss.is_done()) {
|
|
|
|
Handle class_loader, protection_domain;
|
|
|
|
if (accessing_klass != NULL) {
|
|
|
|
class_loader = Handle(THREAD, accessing_klass->class_loader());
|
|
|
|
protection_domain = Handle(THREAD, accessing_klass->protection_domain());
|
|
|
|
}
|
|
|
|
oop mirror = ss.as_java_mirror(class_loader, protection_domain, SignatureStream::NCDFError, CHECK_(empty));
|
|
|
|
ss.next();
|
|
|
|
if (ss.is_done()) {
|
|
|
|
return Handle(THREAD, mirror);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return empty;
|
|
|
|
}
|
|
|
|
|
2010-06-09 18:50:45 -07:00
|
|
|
// Ask Java code to find or construct a method handle constant.
|
2017-03-15 10:25:37 -04:00
|
|
|
Handle SystemDictionary::link_method_handle_constant(Klass* caller,
|
2010-06-09 18:50:45 -07:00
|
|
|
int ref_kind, //e.g., JVM_REF_invokeVirtual
|
2017-03-15 10:25:37 -04:00
|
|
|
Klass* callee,
|
2018-01-12 01:52:06 +03:00
|
|
|
Symbol* name,
|
2011-01-27 16:11:27 -08:00
|
|
|
Symbol* signature,
|
2010-06-09 18:50:45 -07:00
|
|
|
TRAPS) {
|
|
|
|
Handle empty;
|
2018-01-12 01:52:06 +03:00
|
|
|
if (caller == NULL) {
|
2013-10-23 15:44:12 -07:00
|
|
|
THROW_MSG_(vmSymbols::java_lang_InternalError(), "bad MH constant", empty);
|
2010-06-09 18:50:45 -07:00
|
|
|
}
|
2018-01-12 01:52:06 +03:00
|
|
|
Handle name_str = java_lang_String::create_from_symbol(name, CHECK_(empty));
|
|
|
|
Handle signature_str = java_lang_String::create_from_symbol(signature, CHECK_(empty));
|
|
|
|
|
|
|
|
// Put symbolic info from the MH constant into freshly created MemberName and resolve it.
|
|
|
|
Handle mname = MemberName_klass()->allocate_instance_handle(CHECK_(empty));
|
|
|
|
java_lang_invoke_MemberName::set_clazz(mname(), callee->java_mirror());
|
|
|
|
java_lang_invoke_MemberName::set_name (mname(), name_str());
|
|
|
|
java_lang_invoke_MemberName::set_type (mname(), signature_str());
|
|
|
|
java_lang_invoke_MemberName::set_flags(mname(), MethodHandles::ref_kind_to_flags(ref_kind));
|
2018-01-18 02:25:18 +03:00
|
|
|
|
|
|
|
if (ref_kind == JVM_REF_invokeVirtual &&
|
2018-06-25 14:39:44 -07:00
|
|
|
MethodHandles::is_signature_polymorphic_public_name(callee, name)) {
|
|
|
|
// Skip resolution for public signature polymorphic methods such as
|
|
|
|
// j.l.i.MethodHandle.invoke()/invokeExact() and those on VarHandle
|
|
|
|
// They require appendix argument which MemberName resolution doesn't handle.
|
|
|
|
// There's special logic on JDK side to handle them
|
2018-01-18 02:25:18 +03:00
|
|
|
// (see MethodHandles.linkMethodHandleConstant() and MethodHandles.findVirtualForMH()).
|
|
|
|
} else {
|
2018-03-29 10:38:29 +02:00
|
|
|
MethodHandles::resolve_MemberName(mname, caller, /*speculative_resolve*/false, CHECK_(empty));
|
2018-01-18 02:25:18 +03:00
|
|
|
}
|
2018-01-12 01:52:06 +03:00
|
|
|
|
|
|
|
// After method/field resolution succeeded, it's safe to resolve MH signature as well.
|
|
|
|
Handle type = MethodHandles::resolve_MemberName_type(mname, caller, CHECK_(empty));
|
2010-06-09 18:50:45 -07:00
|
|
|
|
2011-03-11 22:34:57 -08:00
|
|
|
// call java.lang.invoke.MethodHandleNatives::linkMethodHandleConstant(Class caller, int refKind, Class callee, String name, Object type) -> MethodHandle
|
2010-06-09 18:50:45 -07:00
|
|
|
JavaCallArguments args;
|
2017-02-15 22:59:57 -05:00
|
|
|
args.push_oop(Handle(THREAD, caller->java_mirror())); // the referring class
|
2010-06-09 18:50:45 -07:00
|
|
|
args.push_int(ref_kind);
|
2017-02-15 22:59:57 -05:00
|
|
|
args.push_oop(Handle(THREAD, callee->java_mirror())); // the target class
|
2018-01-12 01:52:06 +03:00
|
|
|
args.push_oop(name_str);
|
2017-02-15 22:59:57 -05:00
|
|
|
args.push_oop(type);
|
2010-06-09 18:50:45 -07:00
|
|
|
JavaValue result(T_OBJECT);
|
|
|
|
JavaCalls::call_static(&result,
|
|
|
|
SystemDictionary::MethodHandleNatives_klass(),
|
|
|
|
vmSymbols::linkMethodHandleConstant_name(),
|
2011-04-07 17:02:30 -07:00
|
|
|
vmSymbols::linkMethodHandleConstant_signature(),
|
2010-06-09 18:50:45 -07:00
|
|
|
&args, CHECK_(empty));
|
|
|
|
return Handle(THREAD, (oop) result.get_jobject());
|
|
|
|
}
|
2009-04-08 10:56:49 -07:00
|
|
|
|
2017-09-08 10:46:46 -07:00
|
|
|
// Ask Java to compute a constant by invoking a BSM given a Dynamic_info CP entry
|
|
|
|
Handle SystemDictionary::link_dynamic_constant(Klass* caller,
|
|
|
|
int condy_index,
|
|
|
|
Handle bootstrap_specifier,
|
|
|
|
Symbol* name,
|
|
|
|
Symbol* type,
|
|
|
|
TRAPS) {
|
|
|
|
Handle empty;
|
|
|
|
Handle bsm, info;
|
|
|
|
if (java_lang_invoke_MethodHandle::is_instance(bootstrap_specifier())) {
|
|
|
|
bsm = bootstrap_specifier;
|
|
|
|
} else {
|
|
|
|
assert(bootstrap_specifier->is_objArray(), "");
|
|
|
|
objArrayOop args = (objArrayOop) bootstrap_specifier();
|
|
|
|
assert(args->length() == 2, "");
|
|
|
|
bsm = Handle(THREAD, args->obj_at(0));
|
|
|
|
info = Handle(THREAD, args->obj_at(1));
|
|
|
|
}
|
|
|
|
guarantee(java_lang_invoke_MethodHandle::is_instance(bsm()),
|
|
|
|
"caller must supply a valid BSM");
|
|
|
|
|
|
|
|
// This should not happen. JDK code should take care of that.
|
|
|
|
if (caller == NULL) {
|
|
|
|
THROW_MSG_(vmSymbols::java_lang_InternalError(), "bad dynamic constant", empty);
|
|
|
|
}
|
|
|
|
|
|
|
|
Handle constant_name = java_lang_String::create_from_symbol(name, CHECK_(empty));
|
|
|
|
|
|
|
|
// Resolve the constant type in the context of the caller class
|
|
|
|
Handle type_mirror = find_java_mirror_for_type(type, caller, SignatureStream::NCDFError,
|
|
|
|
CHECK_(empty));
|
|
|
|
|
|
|
|
// call java.lang.invoke.MethodHandleNatives::linkConstantDyanmic(caller, condy_index, bsm, type, info)
|
|
|
|
JavaCallArguments args;
|
|
|
|
args.push_oop(Handle(THREAD, caller->java_mirror()));
|
|
|
|
args.push_int(condy_index);
|
|
|
|
args.push_oop(bsm);
|
|
|
|
args.push_oop(constant_name);
|
|
|
|
args.push_oop(type_mirror);
|
|
|
|
args.push_oop(info);
|
|
|
|
JavaValue result(T_OBJECT);
|
|
|
|
JavaCalls::call_static(&result,
|
|
|
|
SystemDictionary::MethodHandleNatives_klass(),
|
|
|
|
vmSymbols::linkDynamicConstant_name(),
|
|
|
|
vmSymbols::linkDynamicConstant_signature(),
|
|
|
|
&args, CHECK_(empty));
|
|
|
|
|
|
|
|
return Handle(THREAD, (oop) result.get_jobject());
|
|
|
|
}
|
|
|
|
|
2011-03-11 22:34:57 -08:00
|
|
|
// Ask Java code to find or construct a java.lang.invoke.CallSite for the given
|
2009-04-21 23:21:04 -07:00
|
|
|
// name and signature, as interpreted relative to the given class loader.
|
2017-03-15 10:25:37 -04:00
|
|
|
methodHandle SystemDictionary::find_dynamic_call_site_invoker(Klass* caller,
|
2017-09-08 10:46:46 -07:00
|
|
|
int indy_index,
|
2012-07-24 10:51:00 -07:00
|
|
|
Handle bootstrap_specifier,
|
|
|
|
Symbol* name,
|
|
|
|
Symbol* type,
|
2012-10-01 14:50:10 -07:00
|
|
|
Handle *appendix_result,
|
|
|
|
Handle *method_type_result,
|
2012-07-24 10:51:00 -07:00
|
|
|
TRAPS) {
|
|
|
|
methodHandle empty;
|
|
|
|
Handle bsm, info;
|
|
|
|
if (java_lang_invoke_MethodHandle::is_instance(bootstrap_specifier())) {
|
|
|
|
bsm = bootstrap_specifier;
|
|
|
|
} else {
|
2017-09-08 10:46:46 -07:00
|
|
|
objArrayOop args = (objArrayOop) bootstrap_specifier();
|
|
|
|
assert(args->length() == 2, "");
|
|
|
|
bsm = Handle(THREAD, args->obj_at(0));
|
|
|
|
info = Handle(THREAD, args->obj_at(1));
|
2012-07-24 10:51:00 -07:00
|
|
|
}
|
|
|
|
guarantee(java_lang_invoke_MethodHandle::is_instance(bsm()),
|
2010-07-15 18:40:45 -07:00
|
|
|
"caller must supply a valid BSM");
|
|
|
|
|
2012-07-24 10:51:00 -07:00
|
|
|
Handle method_name = java_lang_String::create_from_symbol(name, CHECK_(empty));
|
|
|
|
Handle method_type = find_method_handle_type(type, caller, CHECK_(empty));
|
|
|
|
|
2013-10-23 15:44:12 -07:00
|
|
|
// This should not happen. JDK code should take care of that.
|
2017-03-15 10:25:37 -04:00
|
|
|
if (caller == NULL || method_type.is_null()) {
|
2013-10-23 15:44:12 -07:00
|
|
|
THROW_MSG_(vmSymbols::java_lang_InternalError(), "bad invokedynamic", empty);
|
|
|
|
}
|
|
|
|
|
2017-02-15 22:59:57 -05:00
|
|
|
objArrayHandle appendix_box = oopFactory::new_objArray_handle(SystemDictionary::Object_klass(), 1, CHECK_(empty));
|
2012-07-24 10:51:00 -07:00
|
|
|
assert(appendix_box->obj_at(0) == NULL, "");
|
2010-05-01 02:42:18 -07:00
|
|
|
|
2017-09-08 10:46:46 -07:00
|
|
|
// call java.lang.invoke.MethodHandleNatives::linkCallSite(caller, indy_index, bsm, name, mtype, info, &appendix)
|
2012-07-24 10:51:00 -07:00
|
|
|
JavaCallArguments args;
|
2017-02-15 22:59:57 -05:00
|
|
|
args.push_oop(Handle(THREAD, caller->java_mirror()));
|
2017-09-08 10:46:46 -07:00
|
|
|
args.push_int(indy_index);
|
2017-02-15 22:59:57 -05:00
|
|
|
args.push_oop(bsm);
|
|
|
|
args.push_oop(method_name);
|
|
|
|
args.push_oop(method_type);
|
|
|
|
args.push_oop(info);
|
2012-07-24 10:51:00 -07:00
|
|
|
args.push_oop(appendix_box);
|
2009-04-21 23:21:04 -07:00
|
|
|
JavaValue result(T_OBJECT);
|
|
|
|
JavaCalls::call_static(&result,
|
2010-05-01 02:42:18 -07:00
|
|
|
SystemDictionary::MethodHandleNatives_klass(),
|
2012-07-24 10:51:00 -07:00
|
|
|
vmSymbols::linkCallSite_name(),
|
|
|
|
vmSymbols::linkCallSite_signature(),
|
2009-04-21 23:21:04 -07:00
|
|
|
&args, CHECK_(empty));
|
2012-07-24 10:51:00 -07:00
|
|
|
Handle mname(THREAD, (oop) result.get_jobject());
|
2012-10-01 14:50:10 -07:00
|
|
|
(*method_type_result) = method_type;
|
2012-11-29 16:50:29 -05:00
|
|
|
return unpack_method_and_appendix(mname, caller, appendix_box, appendix_result, THREAD);
|
2009-04-21 23:21:04 -07:00
|
|
|
}
|
|
|
|
|
2017-07-28 10:48:35 -04:00
|
|
|
// Protection domain cache table handling
|
|
|
|
|
|
|
|
ProtectionDomainCacheEntry* SystemDictionary::cache_get(Handle protection_domain) {
|
|
|
|
return _pd_cache_table->get(protection_domain);
|
|
|
|
}
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2017-08-02 10:52:50 -04:00
|
|
|
void SystemDictionary::print_on(outputStream *st) {
|
2018-11-07 19:40:27 -08:00
|
|
|
CDS_ONLY(SystemDictionaryShared::print_on(st));
|
2007-12-01 00:00:00 +00:00
|
|
|
GCMutexLocker mu(SystemDictionary_lock);
|
2017-07-28 10:48:35 -04:00
|
|
|
|
2017-08-02 10:52:50 -04:00
|
|
|
ClassLoaderDataGraph::print_dictionary(st);
|
2017-07-28 10:48:35 -04:00
|
|
|
|
|
|
|
// Placeholders
|
2017-08-02 10:52:50 -04:00
|
|
|
placeholders()->print_on(st);
|
|
|
|
st->cr();
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// loader constraints - print under SD_lock
|
2017-08-02 10:52:50 -04:00
|
|
|
constraints()->print_on(st);
|
|
|
|
st->cr();
|
2017-07-28 10:48:35 -04:00
|
|
|
|
2017-08-02 10:52:50 -04:00
|
|
|
_pd_cache_table->print_on(st);
|
|
|
|
st->cr();
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SystemDictionary::verify() {
|
|
|
|
guarantee(constraints() != NULL,
|
|
|
|
"Verify of loader constraints failed");
|
2017-07-28 10:48:35 -04:00
|
|
|
guarantee(placeholders()->number_of_entries() >= 0,
|
|
|
|
"Verify of placeholders failed");
|
|
|
|
|
|
|
|
GCMutexLocker mu(SystemDictionary_lock);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// Verify dictionary
|
2017-07-28 10:48:35 -04:00
|
|
|
ClassLoaderDataGraph::verify_dictionary();
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
placeholders()->verify();
|
|
|
|
|
|
|
|
// Verify constraint table
|
|
|
|
guarantee(constraints() != NULL, "Verify of loader constraints failed");
|
2017-07-28 10:48:35 -04:00
|
|
|
constraints()->verify(placeholders());
|
|
|
|
|
|
|
|
_pd_cache_table->verify();
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2017-08-02 10:52:50 -04:00
|
|
|
void SystemDictionary::dump(outputStream *st, bool verbose) {
|
|
|
|
assert_locked_or_safepoint(SystemDictionary_lock);
|
|
|
|
if (verbose) {
|
|
|
|
print_on(st);
|
|
|
|
} else {
|
2018-11-07 19:40:27 -08:00
|
|
|
CDS_ONLY(SystemDictionaryShared::print_table_statistics(st));
|
2017-08-02 10:52:50 -04:00
|
|
|
ClassLoaderDataGraph::print_dictionary_statistics(st);
|
|
|
|
placeholders()->print_table_statistics(st, "Placeholder Table");
|
|
|
|
constraints()->print_table_statistics(st, "LoaderConstraints Table");
|
|
|
|
_pd_cache_table->print_table_statistics(st, "ProtectionDomainCache Table");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Utility for dumping dictionaries.
|
|
|
|
SystemDictionaryDCmd::SystemDictionaryDCmd(outputStream* output, bool heap) :
|
|
|
|
DCmdWithParser(output, heap),
|
|
|
|
_verbose("-verbose", "Dump the content of each dictionary entry for all class loaders",
|
|
|
|
"BOOLEAN", false, "false") {
|
|
|
|
_dcmdparser.add_dcmd_option(&_verbose);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SystemDictionaryDCmd::execute(DCmdSource source, TRAPS) {
|
|
|
|
VM_DumpHashtable dumper(output(), VM_DumpHashtable::DumpSysDict,
|
|
|
|
_verbose.value());
|
|
|
|
VMThread::execute(&dumper);
|
|
|
|
}
|
|
|
|
|
|
|
|
int SystemDictionaryDCmd::num_arguments() {
|
|
|
|
ResourceMark rm;
|
|
|
|
SystemDictionaryDCmd* dcmd = new SystemDictionaryDCmd(NULL, false);
|
|
|
|
if (dcmd != NULL) {
|
|
|
|
DCmdMark mark(dcmd);
|
|
|
|
return dcmd->_dcmdparser.num_arguments();
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-10 10:06:42 -04:00
|
|
|
void SystemDictionary::initialize_oop_storage() {
|
|
|
|
_vm_weak_oop_storage =
|
|
|
|
new OopStorage("VM Weak Oop Handles",
|
|
|
|
VMWeakAlloc_lock,
|
|
|
|
VMWeakActive_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
OopStorage* SystemDictionary::vm_weak_oop_storage() {
|
|
|
|
assert(_vm_weak_oop_storage != NULL, "Uninitialized");
|
|
|
|
return _vm_weak_oop_storage;
|
|
|
|
}
|