src/share/vm/oops/instanceKlass.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File hotspot Sdiff src/share/vm/oops

src/share/vm/oops/instanceKlass.cpp

Print this page




   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"

  26 #include "classfile/classFileParser.hpp"
  27 #include "classfile/classFileStream.hpp"

  28 #include "classfile/javaClasses.hpp"
  29 #include "classfile/systemDictionary.hpp"
  30 #include "classfile/systemDictionaryShared.hpp"
  31 #include "classfile/verifier.hpp"
  32 #include "classfile/vmSymbols.hpp"
  33 #include "code/dependencyContext.hpp"
  34 #include "compiler/compileBroker.hpp"
  35 #include "gc/shared/collectedHeap.inline.hpp"
  36 #include "gc/shared/specialized_oop_closures.hpp"
  37 #include "interpreter/oopMapCache.hpp"
  38 #include "interpreter/rewriter.hpp"
  39 #include "jvmtifiles/jvmti.h"
  40 #include "logging/log.hpp"
  41 #include "memory/heapInspection.hpp"
  42 #include "memory/iterator.inline.hpp"
  43 #include "memory/metadataFactory.hpp"
  44 #include "memory/metaspaceShared.hpp"
  45 #include "memory/oopFactory.hpp"
  46 #include "memory/resourceArea.hpp"
  47 #include "oops/fieldStreams.hpp"


 127   if (class_name == vmSymbols::java_lang_ClassLoader()) {
 128     return true;
 129   }
 130 
 131   if (SystemDictionary::ClassLoader_klass_loaded()) {
 132     const Klass* const super_klass = parser.super_klass();
 133     if (super_klass != NULL) {
 134       if (super_klass->is_subtype_of(SystemDictionary::ClassLoader_klass())) {
 135         return true;
 136       }
 137     }
 138   }
 139   return false;
 140 }
 141 
 142 InstanceKlass* InstanceKlass::allocate_instance_klass(const ClassFileParser& parser, TRAPS) {
 143   const int size = InstanceKlass::size(parser.vtable_size(),
 144                                        parser.itable_size(),
 145                                        nonstatic_oop_map_size(parser.total_oop_map_count()),
 146                                        parser.is_interface(),
 147                                        parser.is_anonymous());

 148 
 149   const Symbol* const class_name = parser.class_name();
 150   assert(class_name != NULL, "invariant");
 151   ClassLoaderData* loader_data = parser.loader_data();
 152   assert(loader_data != NULL, "invariant");
 153 
 154   InstanceKlass* ik;
 155 
 156   // Allocation
 157   if (REF_NONE == parser.reference_type()) {
 158     if (class_name == vmSymbols::java_lang_Class()) {
 159       // mirror
 160       ik = new (loader_data, size, THREAD) InstanceMirrorKlass(parser);
 161     }
 162     else if (is_class_loader(class_name, parser)) {
 163       // class loader
 164       ik = new (loader_data, size, THREAD) InstanceClassLoaderKlass(parser);
 165     }
 166     else {
 167       // normal


 770     if (!HAS_PENDING_EXCEPTION && this_k->has_nonstatic_concrete_methods()) {
 771       this_k->initialize_super_interfaces(this_k, THREAD);
 772     }
 773 
 774     // If any exceptions, complete abruptly, throwing the same exception as above.
 775     if (HAS_PENDING_EXCEPTION) {
 776       Handle e(THREAD, PENDING_EXCEPTION);
 777       CLEAR_PENDING_EXCEPTION;
 778       {
 779         EXCEPTION_MARK;
 780         // Locks object, set state, and notify all waiting threads
 781         this_k->set_initialization_state_and_notify(initialization_error, THREAD);
 782         CLEAR_PENDING_EXCEPTION;
 783       }
 784       DTRACE_CLASSINIT_PROBE_WAIT(super__failed, this_k(), -1,wait);
 785       THROW_OOP(e());
 786     }
 787   }
 788 
 789 



 790   // Step 8
 791   {
 792     assert(THREAD->is_Java_thread(), "non-JavaThread in initialize_impl");
 793     JavaThread* jt = (JavaThread*)THREAD;
 794     DTRACE_CLASSINIT_PROBE_WAIT(clinit, this_k(), -1,wait);
 795     // Timer includes any side effects of class initialization (resolution,
 796     // etc), but not recursive entry into call_class_initializer().
 797     PerfClassTraceTime timer(ClassLoader::perf_class_init_time(),
 798                              ClassLoader::perf_class_init_selftime(),
 799                              ClassLoader::perf_classes_inited(),
 800                              jt->get_thread_stat()->perf_recursion_counts_addr(),
 801                              jt->get_thread_stat()->perf_timers_addr(),
 802                              PerfClassTraceTime::CLASS_CLINIT);
 803     this_k->call_class_initializer(THREAD);
 804   }
 805 
 806   // Step 9
 807   if (!HAS_PENDING_EXCEPTION) {
 808     this_k->set_initialization_state_and_notify(fully_initialized, CHECK);
 809     { ResourceMark rm(THREAD);


1933           Klass** klass = adr_implementor();
1934           assert(klass != NULL, "null klass");
1935           if (klass != NULL) {
1936             *klass = NULL;
1937           }
1938         }
1939       }
1940     }
1941   }
1942 }
1943 
1944 void InstanceKlass::clean_method_data(BoolObjectClosure* is_alive) {
1945   for (int m = 0; m < methods()->length(); m++) {
1946     MethodData* mdo = methods()->at(m)->method_data();
1947     if (mdo != NULL) {
1948       mdo->clean_method_data(is_alive);
1949     }
1950   }
1951 }
1952 



































































1953 
1954 static void remove_unshareable_in_class(Klass* k) {
1955   // remove klass's unshareable info
1956   k->remove_unshareable_info();
1957 }
1958 
1959 void InstanceKlass::remove_unshareable_info() {
1960   Klass::remove_unshareable_info();
1961   // Unlink the class
1962   if (is_linked()) {
1963     unlink_class();
1964   }
1965   init_implementor();
1966 
1967   constants()->remove_unshareable_info();
1968 
1969   assert(_dep_context == DependencyContext::EMPTY, "dependency context is not shareable");
1970 
1971   for (int i = 0; i < methods()->length(); i++) {
1972     Method* m = methods()->at(i);




   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "aot/aotLoader.hpp"
  27 #include "classfile/classFileParser.hpp"
  28 #include "classfile/classFileStream.hpp"
  29 #include "classfile/classLoader.hpp"
  30 #include "classfile/javaClasses.hpp"
  31 #include "classfile/systemDictionary.hpp"
  32 #include "classfile/systemDictionaryShared.hpp"
  33 #include "classfile/verifier.hpp"
  34 #include "classfile/vmSymbols.hpp"
  35 #include "code/dependencyContext.hpp"
  36 #include "compiler/compileBroker.hpp"
  37 #include "gc/shared/collectedHeap.inline.hpp"
  38 #include "gc/shared/specialized_oop_closures.hpp"
  39 #include "interpreter/oopMapCache.hpp"
  40 #include "interpreter/rewriter.hpp"
  41 #include "jvmtifiles/jvmti.h"
  42 #include "logging/log.hpp"
  43 #include "memory/heapInspection.hpp"
  44 #include "memory/iterator.inline.hpp"
  45 #include "memory/metadataFactory.hpp"
  46 #include "memory/metaspaceShared.hpp"
  47 #include "memory/oopFactory.hpp"
  48 #include "memory/resourceArea.hpp"
  49 #include "oops/fieldStreams.hpp"


 129   if (class_name == vmSymbols::java_lang_ClassLoader()) {
 130     return true;
 131   }
 132 
 133   if (SystemDictionary::ClassLoader_klass_loaded()) {
 134     const Klass* const super_klass = parser.super_klass();
 135     if (super_klass != NULL) {
 136       if (super_klass->is_subtype_of(SystemDictionary::ClassLoader_klass())) {
 137         return true;
 138       }
 139     }
 140   }
 141   return false;
 142 }
 143 
 144 InstanceKlass* InstanceKlass::allocate_instance_klass(const ClassFileParser& parser, TRAPS) {
 145   const int size = InstanceKlass::size(parser.vtable_size(),
 146                                        parser.itable_size(),
 147                                        nonstatic_oop_map_size(parser.total_oop_map_count()),
 148                                        parser.is_interface(),
 149                                        parser.is_anonymous(),
 150                                        should_store_fingerprint());
 151 
 152   const Symbol* const class_name = parser.class_name();
 153   assert(class_name != NULL, "invariant");
 154   ClassLoaderData* loader_data = parser.loader_data();
 155   assert(loader_data != NULL, "invariant");
 156 
 157   InstanceKlass* ik;
 158 
 159   // Allocation
 160   if (REF_NONE == parser.reference_type()) {
 161     if (class_name == vmSymbols::java_lang_Class()) {
 162       // mirror
 163       ik = new (loader_data, size, THREAD) InstanceMirrorKlass(parser);
 164     }
 165     else if (is_class_loader(class_name, parser)) {
 166       // class loader
 167       ik = new (loader_data, size, THREAD) InstanceClassLoaderKlass(parser);
 168     }
 169     else {
 170       // normal


 773     if (!HAS_PENDING_EXCEPTION && this_k->has_nonstatic_concrete_methods()) {
 774       this_k->initialize_super_interfaces(this_k, THREAD);
 775     }
 776 
 777     // If any exceptions, complete abruptly, throwing the same exception as above.
 778     if (HAS_PENDING_EXCEPTION) {
 779       Handle e(THREAD, PENDING_EXCEPTION);
 780       CLEAR_PENDING_EXCEPTION;
 781       {
 782         EXCEPTION_MARK;
 783         // Locks object, set state, and notify all waiting threads
 784         this_k->set_initialization_state_and_notify(initialization_error, THREAD);
 785         CLEAR_PENDING_EXCEPTION;
 786       }
 787       DTRACE_CLASSINIT_PROBE_WAIT(super__failed, this_k(), -1,wait);
 788       THROW_OOP(e());
 789     }
 790   }
 791 
 792 
 793   // Look for aot compiled methods for this klass, including class initializer.
 794   AOTLoader::load_for_klass(this_k, THREAD);
 795 
 796   // Step 8
 797   {
 798     assert(THREAD->is_Java_thread(), "non-JavaThread in initialize_impl");
 799     JavaThread* jt = (JavaThread*)THREAD;
 800     DTRACE_CLASSINIT_PROBE_WAIT(clinit, this_k(), -1,wait);
 801     // Timer includes any side effects of class initialization (resolution,
 802     // etc), but not recursive entry into call_class_initializer().
 803     PerfClassTraceTime timer(ClassLoader::perf_class_init_time(),
 804                              ClassLoader::perf_class_init_selftime(),
 805                              ClassLoader::perf_classes_inited(),
 806                              jt->get_thread_stat()->perf_recursion_counts_addr(),
 807                              jt->get_thread_stat()->perf_timers_addr(),
 808                              PerfClassTraceTime::CLASS_CLINIT);
 809     this_k->call_class_initializer(THREAD);
 810   }
 811 
 812   // Step 9
 813   if (!HAS_PENDING_EXCEPTION) {
 814     this_k->set_initialization_state_and_notify(fully_initialized, CHECK);
 815     { ResourceMark rm(THREAD);


1939           Klass** klass = adr_implementor();
1940           assert(klass != NULL, "null klass");
1941           if (klass != NULL) {
1942             *klass = NULL;
1943           }
1944         }
1945       }
1946     }
1947   }
1948 }
1949 
1950 void InstanceKlass::clean_method_data(BoolObjectClosure* is_alive) {
1951   for (int m = 0; m < methods()->length(); m++) {
1952     MethodData* mdo = methods()->at(m)->method_data();
1953     if (mdo != NULL) {
1954       mdo->clean_method_data(is_alive);
1955     }
1956   }
1957 }
1958 
1959 bool InstanceKlass::supers_have_passed_fingerprint_checks() {
1960   if (java_super() != NULL && !java_super()->has_passed_fingerprint_check()) {
1961     ResourceMark rm;
1962     log_trace(class, fingerprint)("%s : super %s not fingerprinted", external_name(), java_super()->external_name());
1963     return false;
1964   }
1965 
1966   Array<Klass*>* local_interfaces = this->local_interfaces();
1967   if (local_interfaces != NULL) {
1968     int length = local_interfaces->length();
1969     for (int i = 0; i < length; i++) {
1970       InstanceKlass* intf = InstanceKlass::cast(local_interfaces->at(i));
1971       if (!intf->has_passed_fingerprint_check()) {
1972         ResourceMark rm;
1973         log_trace(class, fingerprint)("%s : interface %s not fingerprinted", external_name(), intf->external_name());
1974         return false;
1975       }
1976     }
1977   }
1978 
1979   return true;
1980 }
1981 
1982 bool InstanceKlass::should_store_fingerprint() {
1983 #if INCLUDE_AOT
1984   // We store the fingerprint into the InstanceKlass only in the following 2 cases:
1985   if (EnableJVMCI && !UseJVMCICompiler) {
1986     // (1) We are running AOT to generate a shared library.
1987     return true;
1988   }
1989   if (DumpSharedSpaces) {
1990     // (2) We are running -Xshare:dump to create a shared archive
1991     return true;
1992   }
1993 #endif
1994 
1995   // In all other cases we might set the _misc_has_passed_fingerprint_check bit,
1996   // but do not store the 64-bit fingerprint to save space.
1997   return false;
1998 }
1999 
2000 bool InstanceKlass::has_stored_fingerprint() const {
2001 #if INCLUDE_AOT
2002   return should_store_fingerprint() || is_shared();
2003 #else
2004   return false;
2005 #endif
2006 }
2007 
2008 uint64_t InstanceKlass::get_stored_fingerprint() const {
2009   if (has_stored_fingerprint()) {
2010     address adr = adr_fingerprint();
2011     assert(adr != NULL, "sanity");
2012     return (uint64_t)Bytes::get_native_u8(adr); // adr may not be 64-bit aligned
2013   }
2014   return 0;
2015 }
2016 
2017 void InstanceKlass::store_fingerprint(uint64_t fingerprint) {
2018   assert(should_store_fingerprint(), "must be");
2019   address adr = adr_fingerprint();
2020   assert(adr != NULL, "sanity");
2021   Bytes::put_native_u8(adr, (u8)fingerprint); // adr may not be 64-bit aligned
2022 
2023   ResourceMark rm;
2024   log_trace(class, fingerprint)("stored as " PTR64_FORMAT " for class %s", fingerprint, external_name());
2025 }
2026 
2027 static void remove_unshareable_in_class(Klass* k) {
2028   // remove klass's unshareable info
2029   k->remove_unshareable_info();
2030 }
2031 
2032 void InstanceKlass::remove_unshareable_info() {
2033   Klass::remove_unshareable_info();
2034   // Unlink the class
2035   if (is_linked()) {
2036     unlink_class();
2037   }
2038   init_implementor();
2039 
2040   constants()->remove_unshareable_info();
2041 
2042   assert(_dep_context == DependencyContext::EMPTY, "dependency context is not shareable");
2043 
2044   for (int i = 0; i < methods()->length(); i++) {
2045     Method* m = methods()->at(i);


src/share/vm/oops/instanceKlass.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File