Thu, 24 Mar 2016 21:38:15 -0700
8150752: Share Class Data
Reviewed-by: acorn, hseigel, mschoene
1.1 --- a/src/share/vm/classfile/dictionary.cpp Mon Apr 04 13:58:22 2016 -0700 1.2 +++ b/src/share/vm/classfile/dictionary.cpp Thu Mar 24 21:38:15 2016 -0700 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved. 1.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 * 1.9 * This code is free software; you can redistribute it and/or modify it 1.10 @@ -25,6 +25,7 @@ 1.11 #include "precompiled.hpp" 1.12 #include "classfile/dictionary.hpp" 1.13 #include "classfile/systemDictionary.hpp" 1.14 +#include "classfile/systemDictionaryShared.hpp" 1.15 #include "memory/iterator.hpp" 1.16 #include "oops/oop.inline.hpp" 1.17 #include "prims/jvmtiRedefineClassesTrace.hpp" 1.18 @@ -36,9 +37,16 @@ 1.19 DictionaryEntry* Dictionary::_current_class_entry = NULL; 1.20 int Dictionary::_current_class_index = 0; 1.21 1.22 +size_t Dictionary::entry_size() { 1.23 + if (DumpSharedSpaces) { 1.24 + return SystemDictionaryShared::dictionary_entry_size(); 1.25 + } else { 1.26 + return sizeof(DictionaryEntry); 1.27 + } 1.28 +} 1.29 1.30 Dictionary::Dictionary(int table_size) 1.31 - : TwoOopHashtable<Klass*, mtClass>(table_size, sizeof(DictionaryEntry)) { 1.32 + : TwoOopHashtable<Klass*, mtClass>(table_size, (int)entry_size()) { 1.33 _current_class_index = 0; 1.34 _current_class_entry = NULL; 1.35 _pd_cache_table = new ProtectionDomainCacheTable(defaultProtectionDomainCacheSize); 1.36 @@ -47,7 +55,7 @@ 1.37 1.38 Dictionary::Dictionary(int table_size, HashtableBucket<mtClass>* t, 1.39 int number_of_entries) 1.40 - : TwoOopHashtable<Klass*, mtClass>(table_size, sizeof(DictionaryEntry), t, number_of_entries) { 1.41 + : TwoOopHashtable<Klass*, mtClass>(table_size, (int)entry_size(), t, number_of_entries) { 1.42 _current_class_index = 0; 1.43 _current_class_entry = NULL; 1.44 _pd_cache_table = new ProtectionDomainCacheTable(defaultProtectionDomainCacheSize); 1.45 @@ -63,6 +71,9 @@ 1.46 entry->set_loader_data(loader_data); 1.47 entry->set_pd_set(NULL); 1.48 assert(klass->oop_is_instance(), "Must be"); 1.49 + if (DumpSharedSpaces) { 1.50 + SystemDictionaryShared::init_shared_dictionary_entry(klass, entry); 1.51 + } 1.52 return entry; 1.53 } 1.54
2.1 --- a/src/share/vm/classfile/dictionary.hpp Mon Apr 04 13:58:22 2016 -0700 2.2 +++ b/src/share/vm/classfile/dictionary.hpp Thu Mar 24 21:38:15 2016 -0700 2.3 @@ -1,5 +1,5 @@ 2.4 /* 2.5 - * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved. 2.6 + * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved. 2.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.8 * 2.9 * This code is free software; you can redistribute it and/or modify it 2.10 @@ -53,6 +53,7 @@ 2.11 DictionaryEntry* get_entry(int index, unsigned int hash, 2.12 Symbol* name, ClassLoaderData* loader_data); 2.13 2.14 +protected: 2.15 DictionaryEntry* bucket(int i) { 2.16 return (DictionaryEntry*)Hashtable<Klass*, mtClass>::bucket(i); 2.17 } 2.18 @@ -66,6 +67,8 @@ 2.19 Hashtable<Klass*, mtClass>::add_entry(index, (HashtableEntry<Klass*, mtClass>*)new_entry); 2.20 } 2.21 2.22 + static size_t entry_size(); 2.23 + 2.24 public: 2.25 Dictionary(int table_size); 2.26 Dictionary(int table_size, HashtableBucket<mtClass>* t, int number_of_entries);
3.1 --- a/src/share/vm/classfile/systemDictionary.cpp Mon Apr 04 13:58:22 2016 -0700 3.2 +++ b/src/share/vm/classfile/systemDictionary.cpp Thu Mar 24 21:38:15 2016 -0700 3.3 @@ -1,5 +1,5 @@ 3.4 /* 3.5 - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. 3.6 + * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. 3.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3.8 * 3.9 * This code is free software; you can redistribute it and/or modify it 3.10 @@ -1198,8 +1198,13 @@ 3.11 3.12 if (ik->super() != NULL) { 3.13 Symbol* cn = ik->super()->name(); 3.14 - resolve_super_or_fail(class_name, cn, 3.15 - class_loader, protection_domain, true, CHECK_(nh)); 3.16 + Klass *s = resolve_super_or_fail(class_name, cn, 3.17 + class_loader, protection_domain, true, CHECK_(nh)); 3.18 + if (s != ik->super()) { 3.19 + // The dynamically resolved super class is not the same as the one we used during dump time, 3.20 + // so we cannot use ik. 3.21 + return nh; 3.22 + } 3.23 } 3.24 3.25 Array<Klass*>* interfaces = ik->local_interfaces(); 3.26 @@ -1212,7 +1217,12 @@ 3.27 // reinitialized yet (they will be once the interface classes 3.28 // are loaded) 3.29 Symbol* name = k->name(); 3.30 - resolve_super_or_fail(class_name, name, class_loader, protection_domain, false, CHECK_(nh)); 3.31 + Klass* i = resolve_super_or_fail(class_name, name, class_loader, protection_domain, false, CHECK_(nh)); 3.32 + if (k != i) { 3.33 + // The dynamically resolved interface class is not the same as the one we used during dump time, 3.34 + // so we cannot use ik. 3.35 + return nh; 3.36 + } 3.37 } 3.38 3.39 // Adjust methods to recover missing data. They need addresses for
4.1 --- a/src/share/vm/classfile/systemDictionaryShared.hpp Mon Apr 04 13:58:22 2016 -0700 4.2 +++ b/src/share/vm/classfile/systemDictionaryShared.hpp Thu Mar 24 21:38:15 2016 -0700 4.3 @@ -1,5 +1,5 @@ 4.4 /* 4.5 - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 4.6 + * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved. 4.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4.8 * 4.9 * This code is free software; you can redistribute it and/or modify it 4.10 @@ -26,6 +26,7 @@ 4.11 #ifndef SHARE_VM_CLASSFILE_SYSTEMDICTIONARYSHARED_HPP 4.12 #define SHARE_VM_CLASSFILE_SYSTEMDICTIONARYSHARED_HPP 4.13 4.14 +#include "classfile/dictionary.hpp" 4.15 #include "classfile/systemDictionary.hpp" 4.16 4.17 class SystemDictionaryShared: public SystemDictionary { 4.18 @@ -42,6 +43,22 @@ 4.19 oop class_loader = loader_data->class_loader(); 4.20 return (class_loader == NULL); 4.21 } 4.22 + 4.23 + static size_t dictionary_entry_size() { 4.24 + return sizeof(DictionaryEntry); 4.25 + } 4.26 + static void init_shared_dictionary_entry(Klass* k, DictionaryEntry* entry) {} 4.27 + 4.28 + // The (non-application) CDS implementation supports only classes in the boot 4.29 + // class loader, which ensures that the verification dependencies are the same 4.30 + // during archive creation time and runtime. Thus we can do the dependency checks 4.31 + // entirely during archive creation time. 4.32 + static void add_verification_dependency(Klass* k, Symbol* accessor_clsname, 4.33 + Symbol* target_clsname) {} 4.34 + static void finalize_verification_dependencies() {} 4.35 + static bool check_verification_dependencies(Klass* k, Handle class_loader, 4.36 + Handle protection_domain, 4.37 + char** message_buffer, TRAPS) {return true;} 4.38 }; 4.39 4.40 #endif // SHARE_VM_CLASSFILE_SYSTEMDICTIONARYSHARED_HPP
5.1 --- a/src/share/vm/classfile/verificationType.cpp Mon Apr 04 13:58:22 2016 -0700 5.2 +++ b/src/share/vm/classfile/verificationType.cpp Thu Mar 24 21:38:15 2016 -0700 5.3 @@ -1,5 +1,5 @@ 5.4 /* 5.5 - * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved. 5.6 + * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved. 5.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5.8 * 5.9 * This code is free software; you can redistribute it and/or modify it 5.10 @@ -24,6 +24,7 @@ 5.11 5.12 #include "precompiled.hpp" 5.13 #include "classfile/symbolTable.hpp" 5.14 +#include "classfile/systemDictionaryShared.hpp" 5.15 #include "classfile/verificationType.hpp" 5.16 #include "classfile/verifier.hpp" 5.17 5.18 @@ -73,7 +74,23 @@ 5.19 Klass* from_class = SystemDictionary::resolve_or_fail( 5.20 from.name(), Handle(THREAD, klass->class_loader()), 5.21 Handle(THREAD, klass->protection_domain()), true, CHECK_false); 5.22 - return InstanceKlass::cast(from_class)->is_subclass_of(this_class()); 5.23 + bool result = InstanceKlass::cast(from_class)->is_subclass_of(this_class()); 5.24 + if (result && DumpSharedSpaces) { 5.25 + if (klass()->is_subclass_of(from_class) && klass()->is_subclass_of(this_class())) { 5.26 + // No need to save verification dependency. At run time, <klass> will be 5.27 + // loaded from the archived only if <from_class> and <this_class> are 5.28 + // also loaded from the archive. I.e., all 3 classes are exactly the same 5.29 + // as we saw at archive creation time. 5.30 + } else { 5.31 + // Save the dependency. At run time, we need to check that the condition 5.32 + // from_class->is_subclass_of(this_class() is still true. 5.33 + Symbol* accessor_clsname = from.name(); 5.34 + Symbol* target_clsname = this_class()->name(); 5.35 + SystemDictionaryShared::add_verification_dependency(klass(), 5.36 + accessor_clsname, target_clsname); 5.37 + } 5.38 + } 5.39 + return result; 5.40 } 5.41 } else if (is_array() && from.is_array()) { 5.42 VerificationType comp_this = get_component(context, CHECK_false);
6.1 --- a/src/share/vm/memory/metaspaceShared.cpp Mon Apr 04 13:58:22 2016 -0700 6.2 +++ b/src/share/vm/memory/metaspaceShared.cpp Thu Mar 24 21:38:15 2016 -0700 6.3 @@ -1,5 +1,5 @@ 6.4 /* 6.5 - * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. 6.6 + * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved. 6.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6.8 * 6.9 * This code is free software; you can redistribute it and/or modify it 6.10 @@ -30,6 +30,7 @@ 6.11 #include "classfile/sharedClassUtil.hpp" 6.12 #include "classfile/symbolTable.hpp" 6.13 #include "classfile/systemDictionary.hpp" 6.14 +#include "classfile/systemDictionaryShared.hpp" 6.15 #include "code/codeCache.hpp" 6.16 #include "memory/filemap.hpp" 6.17 #include "memory/gcLocker.hpp" 6.18 @@ -684,6 +685,10 @@ 6.19 exit(1); 6.20 } 6.21 } 6.22 + 6.23 + // Copy the dependencies from C_HEAP-alloced GrowableArrays to RO-alloced 6.24 + // Arrays 6.25 + SystemDictionaryShared::finalize_verification_dependencies(); 6.26 } 6.27 6.28 void MetaspaceShared::prepare_for_dumping() {
7.1 --- a/src/share/vm/oops/instanceKlass.cpp Mon Apr 04 13:58:22 2016 -0700 7.2 +++ b/src/share/vm/oops/instanceKlass.cpp Thu Mar 24 21:38:15 2016 -0700 7.3 @@ -1,5 +1,5 @@ 7.4 /* 7.5 - * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. 7.6 + * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. 7.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7.8 * 7.9 * This code is free software; you can redistribute it and/or modify it 7.10 @@ -25,6 +25,7 @@ 7.11 #include "precompiled.hpp" 7.12 #include "classfile/javaClasses.hpp" 7.13 #include "classfile/systemDictionary.hpp" 7.14 +#include "classfile/systemDictionaryShared.hpp" 7.15 #include "classfile/verifier.hpp" 7.16 #include "classfile/vmSymbols.hpp" 7.17 #include "compiler/compileBroker.hpp" 7.18 @@ -706,6 +707,16 @@ 7.19 7.20 // also sets rewritten 7.21 this_oop->rewrite_class(CHECK_false); 7.22 + } else if (this_oop()->is_shared()) { 7.23 + ResourceMark rm(THREAD); 7.24 + char* message_buffer; // res-allocated by check_verification_dependencies 7.25 + Handle loader = this_oop()->class_loader(); 7.26 + Handle pd = this_oop()->protection_domain(); 7.27 + bool verified = SystemDictionaryShared::check_verification_dependencies(this_oop(), 7.28 + loader, pd, &message_buffer, THREAD); 7.29 + if (!verified) { 7.30 + THROW_MSG_(vmSymbols::java_lang_VerifyError(), message_buffer, false); 7.31 + } 7.32 } 7.33 7.34 // relocate jsrs and link methods after they are all rewritten
8.1 --- a/src/share/vm/prims/whitebox.cpp Mon Apr 04 13:58:22 2016 -0700 8.2 +++ b/src/share/vm/prims/whitebox.cpp Thu Mar 24 21:38:15 2016 -0700 8.3 @@ -1,5 +1,5 @@ 8.4 /* 8.5 - * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. 8.6 + * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved. 8.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 8.8 * 8.9 * This code is free software; you can redistribute it and/or modify it 8.10 @@ -25,6 +25,7 @@ 8.11 #include "precompiled.hpp" 8.12 8.13 #include "memory/metadataFactory.hpp" 8.14 +#include "memory/metaspaceShared.hpp" 8.15 #include "memory/universe.hpp" 8.16 #include "oops/oop.inline.hpp" 8.17 8.18 @@ -914,6 +915,10 @@ 8.19 return (jlong) MetaspaceGC::capacity_until_GC(); 8.20 WB_END 8.21 8.22 +WB_ENTRY(jboolean, WB_IsSharedClass(JNIEnv* env, jobject wb, jclass clazz)) 8.23 + return (jboolean)MetaspaceShared::is_in_shared_space(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz))); 8.24 +WB_END 8.25 + 8.26 WB_ENTRY(jboolean, WB_IsMonitorInflated(JNIEnv* env, jobject wb, jobject obj)) 8.27 oop obj_oop = JNIHandles::resolve(obj); 8.28 return (jboolean) obj_oop->mark()->has_monitor(); 8.29 @@ -1034,6 +1039,7 @@ 8.30 {CC"runMemoryUnitTests", CC"()V", (void*)&WB_RunMemoryUnitTests}, 8.31 {CC"readFromNoaccessArea",CC"()V", (void*)&WB_ReadFromNoaccessArea}, 8.32 {CC"stressVirtualSpaceResize",CC"(JJJ)I", (void*)&WB_StressVirtualSpaceResize}, 8.33 + {CC"isSharedClass", CC"(Ljava/lang/Class;)Z", (void*)&WB_IsSharedClass }, 8.34 #if INCLUDE_ALL_GCS 8.35 {CC"g1InConcurrentMark", CC"()Z", (void*)&WB_G1InConcurrentMark}, 8.36 {CC"g1IsHumongous", CC"(Ljava/lang/Object;)Z", (void*)&WB_G1IsHumongous },
9.1 --- a/test/testlibrary/whitebox/sun/hotspot/WhiteBox.java Mon Apr 04 13:58:22 2016 -0700 9.2 +++ b/test/testlibrary/whitebox/sun/hotspot/WhiteBox.java Thu Mar 24 21:38:15 2016 -0700 9.3 @@ -1,5 +1,5 @@ 9.4 /* 9.5 - * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. 9.6 + * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved. 9.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 9.8 * 9.9 * This code is free software; you can redistribute it and/or modify it 9.10 @@ -233,4 +233,6 @@ 9.11 return offset; 9.12 } 9.13 9.14 + // Class Data Sharing 9.15 + public native boolean isSharedClass(Class<?> c); 9.16 }