src/share/vm/oops/methodKlass.cpp

Mon, 25 Jun 2012 21:33:35 -0400

author
coleenp
date
Mon, 25 Jun 2012 21:33:35 -0400
changeset 3875
246d977b51f2
parent 3826
2fe087c3e814
child 3969
1d7922586cf6
permissions
-rw-r--r--

7178670: runtime/7158800/BadUtf8.java fails in SymbolTable::rehash_table
Summary: Cannot delete _buckets and HashtableEntries in shared space (CDS)
Reviewed-by: acorn, kvn, dlong, dcubed, kamg

     1 /*
     2  * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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  */
    25 #include "precompiled.hpp"
    26 #include "classfile/javaClasses.hpp"
    27 #include "gc_implementation/shared/markSweep.inline.hpp"
    28 #include "gc_interface/collectedHeap.inline.hpp"
    29 #include "interpreter/interpreter.hpp"
    30 #include "memory/gcLocker.hpp"
    31 #include "memory/resourceArea.hpp"
    32 #include "memory/universe.inline.hpp"
    33 #include "oops/constMethodKlass.hpp"
    34 #include "oops/klassOop.hpp"
    35 #include "oops/methodDataOop.hpp"
    36 #include "oops/methodKlass.hpp"
    37 #include "oops/oop.inline.hpp"
    38 #include "oops/oop.inline2.hpp"
    39 #include "oops/symbol.hpp"
    40 #include "runtime/handles.inline.hpp"
    42 klassOop methodKlass::create_klass(TRAPS) {
    43   methodKlass o;
    44   KlassHandle h_this_klass(THREAD, Universe::klassKlassObj());
    45   KlassHandle k = base_create_klass(h_this_klass, header_size(), o.vtbl_value(), CHECK_NULL);
    46   // Make sure size calculation is right
    47   assert(k()->size() == align_object_size(header_size()), "wrong size for object");
    48   java_lang_Class::create_mirror(k, CHECK_NULL); // Allocate mirror
    49   return k();
    50 }
    53 int methodKlass::oop_size(oop obj) const {
    54   assert(obj->is_method(), "must be method oop");
    55   return methodOop(obj)->object_size();
    56 }
    59 bool methodKlass::oop_is_parsable(oop obj) const {
    60   assert(obj->is_method(), "must be method oop");
    61   return methodOop(obj)->object_is_parsable();
    62 }
    65 methodOop methodKlass::allocate(constMethodHandle xconst,
    66                                 AccessFlags access_flags, TRAPS) {
    67   int size = methodOopDesc::object_size(access_flags.is_native());
    68   KlassHandle h_k(THREAD, as_klassOop());
    69   assert(xconst()->is_parsable(), "possible publication protocol violation");
    70   methodOop m = (methodOop)CollectedHeap::permanent_obj_allocate(h_k, size, CHECK_NULL);
    71   assert(!m->is_parsable(), "not expecting parsability yet.");
    73   No_Safepoint_Verifier no_safepoint;  // until m becomes parsable below
    74   m->set_constMethod(xconst());
    75   m->set_access_flags(access_flags);
    76   m->set_method_size(size);
    77   m->set_name_index(0);
    78   m->set_signature_index(0);
    79 #ifdef CC_INTERP
    80   m->set_result_index(T_VOID);
    81 #endif
    82   m->set_constants(NULL);
    83   m->set_max_stack(0);
    84   m->set_max_locals(0);
    85   m->set_intrinsic_id(vmIntrinsics::_none);
    86   m->set_jfr_towrite(false);
    87   m->set_method_data(NULL);
    88   m->set_interpreter_throwout_count(0);
    89   m->set_vtable_index(methodOopDesc::garbage_vtable_index);
    91   // Fix and bury in methodOop
    92   m->set_interpreter_entry(NULL); // sets i2i entry and from_int
    93   m->set_adapter_entry(NULL);
    94   m->clear_code(); // from_c/from_i get set to c2i/i2i
    96   if (access_flags.is_native()) {
    97     m->clear_native_function();
    98     m->set_signature_handler(NULL);
    99   }
   101   NOT_PRODUCT(m->set_compiled_invocation_count(0);)
   102   m->set_interpreter_invocation_count(0);
   103   m->invocation_counter()->init();
   104   m->backedge_counter()->init();
   105   m->clear_number_of_breakpoints();
   107 #ifdef TIERED
   108   m->set_rate(0);
   109   m->set_prev_event_count(0);
   110   m->set_prev_time(0);
   111 #endif
   113   assert(m->is_parsable(), "must be parsable here.");
   114   assert(m->size() == size, "wrong size for object");
   115   return m;
   116 }
   119 void methodKlass::oop_follow_contents(oop obj) {
   120   assert (obj->is_method(), "object must be method");
   121   methodOop m = methodOop(obj);
   122   // Performance tweak: We skip iterating over the klass pointer since we
   123   // know that Universe::methodKlassObj never moves.
   124   MarkSweep::mark_and_push(m->adr_constMethod());
   125   if (m->method_data() != NULL) {
   126     MarkSweep::mark_and_push(m->adr_method_data());
   127   }
   128 }
   130 #ifndef SERIALGC
   131 void methodKlass::oop_follow_contents(ParCompactionManager* cm,
   132                                       oop obj) {
   133   assert (obj->is_method(), "object must be method");
   134   methodOop m = methodOop(obj);
   135   // Performance tweak: We skip iterating over the klass pointer since we
   136   // know that Universe::methodKlassObj never moves.
   137   PSParallelCompact::mark_and_push(cm, m->adr_constMethod());
   138 #ifdef COMPILER2
   139   if (m->method_data() != NULL) {
   140     PSParallelCompact::mark_and_push(cm, m->adr_method_data());
   141   }
   142 #endif // COMPILER2
   143 }
   144 #endif // SERIALGC
   146 int methodKlass::oop_oop_iterate(oop obj, OopClosure* blk) {
   147   assert (obj->is_method(), "object must be method");
   148   methodOop m = methodOop(obj);
   149   // Get size before changing pointers.
   150   // Don't call size() or oop_size() since that is a virtual call.
   151   int size = m->object_size();
   152   // Performance tweak: We skip iterating over the klass pointer since we
   153   // know that Universe::methodKlassObj never moves
   154   blk->do_oop(m->adr_constMethod());
   155   if (m->method_data() != NULL) {
   156     blk->do_oop(m->adr_method_data());
   157   }
   158   return size;
   159 }
   162 int methodKlass::oop_oop_iterate_m(oop obj, OopClosure* blk, MemRegion mr) {
   163   assert (obj->is_method(), "object must be method");
   164   methodOop m = methodOop(obj);
   165   // Get size before changing pointers.
   166   // Don't call size() or oop_size() since that is a virtual call.
   167   int size = m->object_size();
   168   // Performance tweak: We skip iterating over the klass pointer since we
   169   // know that Universe::methodKlassObj never moves.
   170   oop* adr;
   171   adr = m->adr_constMethod();
   172   if (mr.contains(adr)) blk->do_oop(adr);
   173   if (m->method_data() != NULL) {
   174     adr = m->adr_method_data();
   175     if (mr.contains(adr)) blk->do_oop(adr);
   176   }
   177   return size;
   178 }
   181 int methodKlass::oop_adjust_pointers(oop obj) {
   182   assert(obj->is_method(), "should be method");
   183   methodOop m = methodOop(obj);
   184   // Get size before changing pointers.
   185   // Don't call size() or oop_size() since that is a virtual call.
   186   int size = m->object_size();
   187   // Performance tweak: We skip iterating over the klass pointer since we
   188   // know that Universe::methodKlassObj never moves.
   189   MarkSweep::adjust_pointer(m->adr_constMethod());
   190   if (m->method_data() != NULL) {
   191     MarkSweep::adjust_pointer(m->adr_method_data());
   192   }
   193   return size;
   194 }
   196 #ifndef SERIALGC
   197 void methodKlass::oop_push_contents(PSPromotionManager* pm, oop obj) {
   198   assert(obj->is_method(), "should be method");
   199 }
   201 int methodKlass::oop_update_pointers(ParCompactionManager* cm, oop obj) {
   202   assert(obj->is_method(), "should be method");
   203   methodOop m = methodOop(obj);
   204   PSParallelCompact::adjust_pointer(m->adr_constMethod());
   205 #ifdef COMPILER2
   206   if (m->method_data() != NULL) {
   207     PSParallelCompact::adjust_pointer(m->adr_method_data());
   208   }
   209 #endif // COMPILER2
   210   return m->object_size();
   211 }
   212 #endif // SERIALGC
   214 #ifndef PRODUCT
   216 // Printing
   218 void methodKlass::oop_print_on(oop obj, outputStream* st) {
   219   ResourceMark rm;
   220   assert(obj->is_method(), "must be method");
   221   Klass::oop_print_on(obj, st);
   222   methodOop m = methodOop(obj);
   223   // get the effect of PrintOopAddress, always, for methods:
   224   st->print_cr(" - this oop:          "INTPTR_FORMAT, (intptr_t)m);
   225   st->print   (" - method holder:     ");    m->method_holder()->print_value_on(st); st->cr();
   226   st->print   (" - constants:         "INTPTR_FORMAT" ", (address)m->constants());
   227   m->constants()->print_value_on(st); st->cr();
   228   st->print   (" - access:            0x%x  ", m->access_flags().as_int()); m->access_flags().print_on(st); st->cr();
   229   st->print   (" - name:              ");    m->name()->print_value_on(st); st->cr();
   230   st->print   (" - signature:         ");    m->signature()->print_value_on(st); st->cr();
   231   st->print_cr(" - max stack:         %d",   m->max_stack());
   232   st->print_cr(" - max locals:        %d",   m->max_locals());
   233   st->print_cr(" - size of params:    %d",   m->size_of_parameters());
   234   st->print_cr(" - method size:       %d",   m->method_size());
   235   if (m->intrinsic_id() != vmIntrinsics::_none)
   236     st->print_cr(" - intrinsic id:      %d %s", m->intrinsic_id(), vmIntrinsics::name_at(m->intrinsic_id()));
   237   if (m->highest_comp_level() != CompLevel_none)
   238     st->print_cr(" - highest level:     %d", m->highest_comp_level());
   239   st->print_cr(" - vtable index:      %d",   m->_vtable_index);
   240   st->print_cr(" - i2i entry:         " INTPTR_FORMAT, m->interpreter_entry());
   241   st->print_cr(" - adapter:           " INTPTR_FORMAT, m->adapter());
   242   st->print_cr(" - compiled entry     " INTPTR_FORMAT, m->from_compiled_entry());
   243   st->print_cr(" - code size:         %d",   m->code_size());
   244   if (m->code_size() != 0) {
   245     st->print_cr(" - code start:        " INTPTR_FORMAT, m->code_base());
   246     st->print_cr(" - code end (excl):   " INTPTR_FORMAT, m->code_base() + m->code_size());
   247   }
   248   if (m->method_data() != NULL) {
   249     st->print_cr(" - method data:       " INTPTR_FORMAT, (address)m->method_data());
   250   }
   251   st->print_cr(" - checked ex length: %d",   m->checked_exceptions_length());
   252   if (m->checked_exceptions_length() > 0) {
   253     CheckedExceptionElement* table = m->checked_exceptions_start();
   254     st->print_cr(" - checked ex start:  " INTPTR_FORMAT, table);
   255     if (Verbose) {
   256       for (int i = 0; i < m->checked_exceptions_length(); i++) {
   257         st->print_cr("   - throws %s", m->constants()->printable_name_at(table[i].class_cp_index));
   258       }
   259     }
   260   }
   261   if (m->has_linenumber_table()) {
   262     u_char* table = m->compressed_linenumber_table();
   263     st->print_cr(" - linenumber start:  " INTPTR_FORMAT, table);
   264     if (Verbose) {
   265       CompressedLineNumberReadStream stream(table);
   266       while (stream.read_pair()) {
   267         st->print_cr("   - line %d: %d", stream.line(), stream.bci());
   268       }
   269     }
   270   }
   271   st->print_cr(" - localvar length:   %d",   m->localvariable_table_length());
   272   if (m->localvariable_table_length() > 0) {
   273     LocalVariableTableElement* table = m->localvariable_table_start();
   274     st->print_cr(" - localvar start:    " INTPTR_FORMAT, table);
   275     if (Verbose) {
   276       for (int i = 0; i < m->localvariable_table_length(); i++) {
   277         int bci = table[i].start_bci;
   278         int len = table[i].length;
   279         const char* name = m->constants()->printable_name_at(table[i].name_cp_index);
   280         const char* desc = m->constants()->printable_name_at(table[i].descriptor_cp_index);
   281         int slot = table[i].slot;
   282         st->print_cr("   - %s %s bci=%d len=%d slot=%d", desc, name, bci, len, slot);
   283       }
   284     }
   285   }
   286   if (m->code() != NULL) {
   287     st->print   (" - compiled code: ");
   288     m->code()->print_value_on(st);
   289     st->cr();
   290   }
   291   if (m->is_method_handle_invoke()) {
   292     st->print_cr(" - invoke method type: " INTPTR_FORMAT, (address) m->method_handle_type());
   293     // m is classified as native, but it does not have an interesting
   294     // native_function or signature handler
   295   } else if (m->is_native()) {
   296     st->print_cr(" - native function:   " INTPTR_FORMAT, m->native_function());
   297     st->print_cr(" - signature handler: " INTPTR_FORMAT, m->signature_handler());
   298   }
   299 }
   301 #endif //PRODUCT
   303 void methodKlass::oop_print_value_on(oop obj, outputStream* st) {
   304   assert(obj->is_method(), "must be method");
   305   Klass::oop_print_value_on(obj, st);
   306   methodOop m = methodOop(obj);
   307   st->print(" ");
   308   m->name()->print_value_on(st);
   309   st->print(" ");
   310   m->signature()->print_value_on(st);
   311   st->print(" in ");
   312   m->method_holder()->print_value_on(st);
   313   if (WizardMode) st->print("[%d,%d]", m->size_of_parameters(), m->max_locals());
   314   if (WizardMode && m->code() != NULL) st->print(" ((nmethod*)%p)", m->code());
   315 }
   317 const char* methodKlass::internal_name() const {
   318   return "{method}";
   319 }
   322 // Verification
   324 void methodKlass::oop_verify_on(oop obj, outputStream* st) {
   325   Klass::oop_verify_on(obj, st);
   326   guarantee(obj->is_method(), "object must be method");
   327   if (!obj->partially_loaded()) {
   328     methodOop m = methodOop(obj);
   329     guarantee(m->is_perm(),  "should be in permspace");
   330     guarantee(m->constMethod()->is_constMethod(), "should be constMethodOop");
   331     guarantee(m->constMethod()->is_perm(), "should be in permspace");
   332     methodDataOop method_data = m->method_data();
   333     guarantee(method_data == NULL ||
   334               method_data->is_perm(), "should be in permspace");
   335     guarantee(method_data == NULL ||
   336               method_data->is_methodData(), "should be method data");
   337   }
   338 }
   340 bool methodKlass::oop_partially_loaded(oop obj) const {
   341   assert(obj->is_method(), "object must be method");
   342   methodOop m = methodOop(obj);
   343   constMethodOop xconst = m->constMethod();
   344   assert(xconst != NULL, "const method must be set");
   345   constMethodKlass* ck = constMethodKlass::cast(xconst->klass());
   346   return ck->oop_partially_loaded(xconst);
   347 }
   350 void methodKlass::oop_set_partially_loaded(oop obj) {
   351   assert(obj->is_method(), "object must be method");
   352   methodOop m = methodOop(obj);
   353   constMethodOop xconst = m->constMethod();
   354   assert(xconst != NULL, "const method must be set");
   355   constMethodKlass* ck = constMethodKlass::cast(xconst->klass());
   356   ck->oop_set_partially_loaded(xconst);
   357 }

mercurial