提交 5418c529 编写于 作者: I iklam

8150752: Share Class Data

Reviewed-by: acorn, hseigel, mschoene
上级 0ed6766a
/* /*
* Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "precompiled.hpp" #include "precompiled.hpp"
#include "classfile/dictionary.hpp" #include "classfile/dictionary.hpp"
#include "classfile/systemDictionary.hpp" #include "classfile/systemDictionary.hpp"
#include "classfile/systemDictionaryShared.hpp"
#include "memory/iterator.hpp" #include "memory/iterator.hpp"
#include "oops/oop.inline.hpp" #include "oops/oop.inline.hpp"
#include "prims/jvmtiRedefineClassesTrace.hpp" #include "prims/jvmtiRedefineClassesTrace.hpp"
...@@ -36,9 +37,16 @@ PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC ...@@ -36,9 +37,16 @@ PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
DictionaryEntry* Dictionary::_current_class_entry = NULL; DictionaryEntry* Dictionary::_current_class_entry = NULL;
int Dictionary::_current_class_index = 0; int Dictionary::_current_class_index = 0;
size_t Dictionary::entry_size() {
if (DumpSharedSpaces) {
return SystemDictionaryShared::dictionary_entry_size();
} else {
return sizeof(DictionaryEntry);
}
}
Dictionary::Dictionary(int table_size) Dictionary::Dictionary(int table_size)
: TwoOopHashtable<Klass*, mtClass>(table_size, sizeof(DictionaryEntry)) { : TwoOopHashtable<Klass*, mtClass>(table_size, (int)entry_size()) {
_current_class_index = 0; _current_class_index = 0;
_current_class_entry = NULL; _current_class_entry = NULL;
_pd_cache_table = new ProtectionDomainCacheTable(defaultProtectionDomainCacheSize); _pd_cache_table = new ProtectionDomainCacheTable(defaultProtectionDomainCacheSize);
...@@ -47,7 +55,7 @@ Dictionary::Dictionary(int table_size) ...@@ -47,7 +55,7 @@ Dictionary::Dictionary(int table_size)
Dictionary::Dictionary(int table_size, HashtableBucket<mtClass>* t, Dictionary::Dictionary(int table_size, HashtableBucket<mtClass>* t,
int number_of_entries) int number_of_entries)
: TwoOopHashtable<Klass*, mtClass>(table_size, sizeof(DictionaryEntry), t, number_of_entries) { : TwoOopHashtable<Klass*, mtClass>(table_size, (int)entry_size(), t, number_of_entries) {
_current_class_index = 0; _current_class_index = 0;
_current_class_entry = NULL; _current_class_entry = NULL;
_pd_cache_table = new ProtectionDomainCacheTable(defaultProtectionDomainCacheSize); _pd_cache_table = new ProtectionDomainCacheTable(defaultProtectionDomainCacheSize);
...@@ -63,6 +71,9 @@ DictionaryEntry* Dictionary::new_entry(unsigned int hash, Klass* klass, ...@@ -63,6 +71,9 @@ DictionaryEntry* Dictionary::new_entry(unsigned int hash, Klass* klass,
entry->set_loader_data(loader_data); entry->set_loader_data(loader_data);
entry->set_pd_set(NULL); entry->set_pd_set(NULL);
assert(klass->oop_is_instance(), "Must be"); assert(klass->oop_is_instance(), "Must be");
if (DumpSharedSpaces) {
SystemDictionaryShared::init_shared_dictionary_entry(klass, entry);
}
return entry; return entry;
} }
......
/* /*
* Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -53,6 +53,7 @@ private: ...@@ -53,6 +53,7 @@ private:
DictionaryEntry* get_entry(int index, unsigned int hash, DictionaryEntry* get_entry(int index, unsigned int hash,
Symbol* name, ClassLoaderData* loader_data); Symbol* name, ClassLoaderData* loader_data);
protected:
DictionaryEntry* bucket(int i) { DictionaryEntry* bucket(int i) {
return (DictionaryEntry*)Hashtable<Klass*, mtClass>::bucket(i); return (DictionaryEntry*)Hashtable<Klass*, mtClass>::bucket(i);
} }
...@@ -66,6 +67,8 @@ private: ...@@ -66,6 +67,8 @@ private:
Hashtable<Klass*, mtClass>::add_entry(index, (HashtableEntry<Klass*, mtClass>*)new_entry); Hashtable<Klass*, mtClass>::add_entry(index, (HashtableEntry<Klass*, mtClass>*)new_entry);
} }
static size_t entry_size();
public: public:
Dictionary(int table_size); Dictionary(int table_size);
Dictionary(int table_size, HashtableBucket<mtClass>* t, int number_of_entries); Dictionary(int table_size, HashtableBucket<mtClass>* t, int number_of_entries);
......
/* /*
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -1198,8 +1198,13 @@ instanceKlassHandle SystemDictionary::load_shared_class(instanceKlassHandle ik, ...@@ -1198,8 +1198,13 @@ instanceKlassHandle SystemDictionary::load_shared_class(instanceKlassHandle ik,
if (ik->super() != NULL) { if (ik->super() != NULL) {
Symbol* cn = ik->super()->name(); Symbol* cn = ik->super()->name();
resolve_super_or_fail(class_name, cn, Klass *s = resolve_super_or_fail(class_name, cn,
class_loader, protection_domain, true, CHECK_(nh)); class_loader, protection_domain, true, CHECK_(nh));
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.
return nh;
}
} }
Array<Klass*>* interfaces = ik->local_interfaces(); Array<Klass*>* interfaces = ik->local_interfaces();
...@@ -1212,7 +1217,12 @@ instanceKlassHandle SystemDictionary::load_shared_class(instanceKlassHandle ik, ...@@ -1212,7 +1217,12 @@ instanceKlassHandle SystemDictionary::load_shared_class(instanceKlassHandle ik,
// reinitialized yet (they will be once the interface classes // reinitialized yet (they will be once the interface classes
// are loaded) // are loaded)
Symbol* name = k->name(); Symbol* name = k->name();
resolve_super_or_fail(class_name, name, class_loader, protection_domain, false, CHECK_(nh)); Klass* i = resolve_super_or_fail(class_name, name, class_loader, protection_domain, false, CHECK_(nh));
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.
return nh;
}
} }
// Adjust methods to recover missing data. They need addresses for // Adjust methods to recover missing data. They need addresses for
......
/* /*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#ifndef SHARE_VM_CLASSFILE_SYSTEMDICTIONARYSHARED_HPP #ifndef SHARE_VM_CLASSFILE_SYSTEMDICTIONARYSHARED_HPP
#define SHARE_VM_CLASSFILE_SYSTEMDICTIONARYSHARED_HPP #define SHARE_VM_CLASSFILE_SYSTEMDICTIONARYSHARED_HPP
#include "classfile/dictionary.hpp"
#include "classfile/systemDictionary.hpp" #include "classfile/systemDictionary.hpp"
class SystemDictionaryShared: public SystemDictionary { class SystemDictionaryShared: public SystemDictionary {
...@@ -42,6 +43,22 @@ public: ...@@ -42,6 +43,22 @@ public:
oop class_loader = loader_data->class_loader(); oop class_loader = loader_data->class_loader();
return (class_loader == NULL); return (class_loader == NULL);
} }
static size_t dictionary_entry_size() {
return sizeof(DictionaryEntry);
}
static void init_shared_dictionary_entry(Klass* k, DictionaryEntry* entry) {}
// The (non-application) CDS implementation supports only classes in the boot
// class loader, which ensures that the verification dependencies are the same
// during archive creation time and runtime. Thus we can do the dependency checks
// entirely during archive creation time.
static void add_verification_dependency(Klass* k, Symbol* accessor_clsname,
Symbol* target_clsname) {}
static void finalize_verification_dependencies() {}
static bool check_verification_dependencies(Klass* k, Handle class_loader,
Handle protection_domain,
char** message_buffer, TRAPS) {return true;}
}; };
#endif // SHARE_VM_CLASSFILE_SYSTEMDICTIONARYSHARED_HPP #endif // SHARE_VM_CLASSFILE_SYSTEMDICTIONARYSHARED_HPP
/* /*
* Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "precompiled.hpp" #include "precompiled.hpp"
#include "classfile/symbolTable.hpp" #include "classfile/symbolTable.hpp"
#include "classfile/systemDictionaryShared.hpp"
#include "classfile/verificationType.hpp" #include "classfile/verificationType.hpp"
#include "classfile/verifier.hpp" #include "classfile/verifier.hpp"
...@@ -73,7 +74,23 @@ bool VerificationType::is_reference_assignable_from( ...@@ -73,7 +74,23 @@ bool VerificationType::is_reference_assignable_from(
Klass* from_class = SystemDictionary::resolve_or_fail( Klass* from_class = SystemDictionary::resolve_or_fail(
from.name(), Handle(THREAD, klass->class_loader()), from.name(), Handle(THREAD, klass->class_loader()),
Handle(THREAD, klass->protection_domain()), true, CHECK_false); Handle(THREAD, klass->protection_domain()), true, CHECK_false);
return InstanceKlass::cast(from_class)->is_subclass_of(this_class()); bool result = InstanceKlass::cast(from_class)->is_subclass_of(this_class());
if (result && DumpSharedSpaces) {
if (klass()->is_subclass_of(from_class) && klass()->is_subclass_of(this_class())) {
// No need to save verification dependency. At run time, <klass> will be
// loaded from the archived only if <from_class> and <this_class> are
// also loaded from the archive. I.e., all 3 classes are exactly the same
// as we saw at archive creation time.
} else {
// Save the dependency. At run time, we need to check that the condition
// from_class->is_subclass_of(this_class() is still true.
Symbol* accessor_clsname = from.name();
Symbol* target_clsname = this_class()->name();
SystemDictionaryShared::add_verification_dependency(klass(),
accessor_clsname, target_clsname);
}
}
return result;
} }
} else if (is_array() && from.is_array()) { } else if (is_array() && from.is_array()) {
VerificationType comp_this = get_component(context, CHECK_false); VerificationType comp_this = get_component(context, CHECK_false);
......
/* /*
* Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include "classfile/sharedClassUtil.hpp" #include "classfile/sharedClassUtil.hpp"
#include "classfile/symbolTable.hpp" #include "classfile/symbolTable.hpp"
#include "classfile/systemDictionary.hpp" #include "classfile/systemDictionary.hpp"
#include "classfile/systemDictionaryShared.hpp"
#include "code/codeCache.hpp" #include "code/codeCache.hpp"
#include "memory/filemap.hpp" #include "memory/filemap.hpp"
#include "memory/gcLocker.hpp" #include "memory/gcLocker.hpp"
...@@ -684,6 +685,10 @@ void MetaspaceShared::link_and_cleanup_shared_classes(TRAPS) { ...@@ -684,6 +685,10 @@ void MetaspaceShared::link_and_cleanup_shared_classes(TRAPS) {
exit(1); exit(1);
} }
} }
// Copy the dependencies from C_HEAP-alloced GrowableArrays to RO-alloced
// Arrays
SystemDictionaryShared::finalize_verification_dependencies();
} }
void MetaspaceShared::prepare_for_dumping() { void MetaspaceShared::prepare_for_dumping() {
......
/* /*
* Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "precompiled.hpp" #include "precompiled.hpp"
#include "classfile/javaClasses.hpp" #include "classfile/javaClasses.hpp"
#include "classfile/systemDictionary.hpp" #include "classfile/systemDictionary.hpp"
#include "classfile/systemDictionaryShared.hpp"
#include "classfile/verifier.hpp" #include "classfile/verifier.hpp"
#include "classfile/vmSymbols.hpp" #include "classfile/vmSymbols.hpp"
#include "compiler/compileBroker.hpp" #include "compiler/compileBroker.hpp"
...@@ -706,6 +707,16 @@ bool InstanceKlass::link_class_impl( ...@@ -706,6 +707,16 @@ bool InstanceKlass::link_class_impl(
// also sets rewritten // also sets rewritten
this_oop->rewrite_class(CHECK_false); this_oop->rewrite_class(CHECK_false);
} else if (this_oop()->is_shared()) {
ResourceMark rm(THREAD);
char* message_buffer; // res-allocated by check_verification_dependencies
Handle loader = this_oop()->class_loader();
Handle pd = this_oop()->protection_domain();
bool verified = SystemDictionaryShared::check_verification_dependencies(this_oop(),
loader, pd, &message_buffer, THREAD);
if (!verified) {
THROW_MSG_(vmSymbols::java_lang_VerifyError(), message_buffer, false);
}
} }
// relocate jsrs and link methods after they are all rewritten // relocate jsrs and link methods after they are all rewritten
......
/* /*
* Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "precompiled.hpp" #include "precompiled.hpp"
#include "memory/metadataFactory.hpp" #include "memory/metadataFactory.hpp"
#include "memory/metaspaceShared.hpp"
#include "memory/universe.hpp" #include "memory/universe.hpp"
#include "oops/oop.inline.hpp" #include "oops/oop.inline.hpp"
...@@ -914,6 +915,10 @@ WB_ENTRY(jlong, WB_MetaspaceCapacityUntilGC(JNIEnv* env, jobject wb)) ...@@ -914,6 +915,10 @@ WB_ENTRY(jlong, WB_MetaspaceCapacityUntilGC(JNIEnv* env, jobject wb))
return (jlong) MetaspaceGC::capacity_until_GC(); return (jlong) MetaspaceGC::capacity_until_GC();
WB_END WB_END
WB_ENTRY(jboolean, WB_IsSharedClass(JNIEnv* env, jobject wb, jclass clazz))
return (jboolean)MetaspaceShared::is_in_shared_space(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz)));
WB_END
WB_ENTRY(jboolean, WB_IsMonitorInflated(JNIEnv* env, jobject wb, jobject obj)) WB_ENTRY(jboolean, WB_IsMonitorInflated(JNIEnv* env, jobject wb, jobject obj))
oop obj_oop = JNIHandles::resolve(obj); oop obj_oop = JNIHandles::resolve(obj);
return (jboolean) obj_oop->mark()->has_monitor(); return (jboolean) obj_oop->mark()->has_monitor();
...@@ -1034,6 +1039,7 @@ static JNINativeMethod methods[] = { ...@@ -1034,6 +1039,7 @@ static JNINativeMethod methods[] = {
{CC"runMemoryUnitTests", CC"()V", (void*)&WB_RunMemoryUnitTests}, {CC"runMemoryUnitTests", CC"()V", (void*)&WB_RunMemoryUnitTests},
{CC"readFromNoaccessArea",CC"()V", (void*)&WB_ReadFromNoaccessArea}, {CC"readFromNoaccessArea",CC"()V", (void*)&WB_ReadFromNoaccessArea},
{CC"stressVirtualSpaceResize",CC"(JJJ)I", (void*)&WB_StressVirtualSpaceResize}, {CC"stressVirtualSpaceResize",CC"(JJJ)I", (void*)&WB_StressVirtualSpaceResize},
{CC"isSharedClass", CC"(Ljava/lang/Class;)Z", (void*)&WB_IsSharedClass },
#if INCLUDE_ALL_GCS #if INCLUDE_ALL_GCS
{CC"g1InConcurrentMark", CC"()Z", (void*)&WB_G1InConcurrentMark}, {CC"g1InConcurrentMark", CC"()Z", (void*)&WB_G1InConcurrentMark},
{CC"g1IsHumongous", CC"(Ljava/lang/Object;)Z", (void*)&WB_G1IsHumongous }, {CC"g1IsHumongous", CC"(Ljava/lang/Object;)Z", (void*)&WB_G1IsHumongous },
......
/* /*
* Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -233,4 +233,6 @@ public class WhiteBox { ...@@ -233,4 +233,6 @@ public class WhiteBox {
return offset; return offset;
} }
// Class Data Sharing
public native boolean isSharedClass(Class<?> c);
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册