src/share/vm/oops/constMethodKlass.cpp

Tue, 23 Nov 2010 13:22:55 -0800

author
stefank
date
Tue, 23 Nov 2010 13:22:55 -0800
changeset 2314
f95d63e2154a
parent 2068
7fcd5f39bd7a
child 2534
e5383553fd4e
permissions
-rw-r--r--

6989984: Use standard include model for Hospot
Summary: Replaced MakeDeps and the includeDB files with more standardized solutions.
Reviewed-by: coleenp, kvn, kamg

     1 /*
     2  * Copyright (c) 2003, 2010, 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 "gc_implementation/shared/markSweep.inline.hpp"
    27 #include "interpreter/interpreter.hpp"
    28 #include "memory/gcLocker.hpp"
    29 #include "memory/resourceArea.hpp"
    30 #include "oops/constMethodKlass.hpp"
    31 #include "oops/constMethodOop.hpp"
    32 #include "oops/oop.inline.hpp"
    33 #include "oops/oop.inline2.hpp"
    34 #include "runtime/handles.inline.hpp"
    37 klassOop constMethodKlass::create_klass(TRAPS) {
    38   constMethodKlass o;
    39   KlassHandle h_this_klass(THREAD, Universe::klassKlassObj());
    40   KlassHandle k = base_create_klass(h_this_klass, header_size(),
    41                                     o.vtbl_value(), CHECK_NULL);
    42   // Make sure size calculation is right
    43   assert(k()->size() == align_object_size(header_size()),
    44          "wrong size for object");
    45   //java_lang_Class::create_mirror(k, CHECK_NULL); // Allocate mirror
    46   return k();
    47 }
    50 int constMethodKlass::oop_size(oop obj) const {
    51   assert(obj->is_constMethod(), "must be constMethod oop");
    52   return constMethodOop(obj)->object_size();
    53 }
    55 bool constMethodKlass::oop_is_parsable(oop obj) const {
    56   assert(obj->is_constMethod(), "must be constMethod oop");
    57   return constMethodOop(obj)->object_is_parsable();
    58 }
    60 bool constMethodKlass::oop_is_conc_safe(oop obj) const {
    61   assert(obj->is_constMethod(), "must be constMethod oop");
    62   return constMethodOop(obj)->is_conc_safe();
    63 }
    65 constMethodOop constMethodKlass::allocate(int byte_code_size,
    66                                           int compressed_line_number_size,
    67                                           int localvariable_table_length,
    68                                           int checked_exceptions_length,
    69                                           bool is_conc_safe,
    70                                           TRAPS) {
    72   int size = constMethodOopDesc::object_size(byte_code_size,
    73                                              compressed_line_number_size,
    74                                              localvariable_table_length,
    75                                              checked_exceptions_length);
    76   KlassHandle h_k(THREAD, as_klassOop());
    77   constMethodOop cm = (constMethodOop)
    78     CollectedHeap::permanent_obj_allocate(h_k, size, CHECK_NULL);
    79   assert(!cm->is_parsable(), "Not yet safely parsable");
    80   No_Safepoint_Verifier no_safepoint;
    81   cm->set_interpreter_kind(Interpreter::invalid);
    82   cm->init_fingerprint();
    83   cm->set_method(NULL);
    84   cm->set_stackmap_data(NULL);
    85   cm->set_exception_table(NULL);
    86   cm->set_code_size(byte_code_size);
    87   cm->set_constMethod_size(size);
    88   cm->set_inlined_tables_length(checked_exceptions_length,
    89                                 compressed_line_number_size,
    90                                 localvariable_table_length);
    91   assert(cm->size() == size, "wrong size for object");
    92   cm->set_is_conc_safe(is_conc_safe);
    93   cm->set_partially_loaded();
    94   assert(cm->is_parsable(), "Is safely parsable by gc");
    95   return cm;
    96 }
    98 void constMethodKlass::oop_follow_contents(oop obj) {
    99   assert (obj->is_constMethod(), "object must be constMethod");
   100   constMethodOop cm = constMethodOop(obj);
   101   MarkSweep::mark_and_push(cm->adr_method());
   102   MarkSweep::mark_and_push(cm->adr_stackmap_data());
   103   MarkSweep::mark_and_push(cm->adr_exception_table());
   104   // Performance tweak: We skip iterating over the klass pointer since we
   105   // know that Universe::constMethodKlassObj never moves.
   106 }
   108 #ifndef SERIALGC
   109 void constMethodKlass::oop_follow_contents(ParCompactionManager* cm,
   110                                            oop obj) {
   111   assert (obj->is_constMethod(), "object must be constMethod");
   112   constMethodOop cm_oop = constMethodOop(obj);
   113   PSParallelCompact::mark_and_push(cm, cm_oop->adr_method());
   114   PSParallelCompact::mark_and_push(cm, cm_oop->adr_stackmap_data());
   115   PSParallelCompact::mark_and_push(cm, cm_oop->adr_exception_table());
   116   // Performance tweak: We skip iterating over the klass pointer since we
   117   // know that Universe::constMethodKlassObj never moves.
   118 }
   119 #endif // SERIALGC
   121 int constMethodKlass::oop_oop_iterate(oop obj, OopClosure* blk) {
   122   assert (obj->is_constMethod(), "object must be constMethod");
   123   constMethodOop cm = constMethodOop(obj);
   124   blk->do_oop(cm->adr_method());
   125   blk->do_oop(cm->adr_stackmap_data());
   126   blk->do_oop(cm->adr_exception_table());
   127   // Get size before changing pointers.
   128   // Don't call size() or oop_size() since that is a virtual call.
   129   int size = cm->object_size();
   130   return size;
   131 }
   134 int constMethodKlass::oop_oop_iterate_m(oop obj, OopClosure* blk, MemRegion mr) {
   135   assert (obj->is_constMethod(), "object must be constMethod");
   136   constMethodOop cm = constMethodOop(obj);
   137   oop* adr;
   138   adr = cm->adr_method();
   139   if (mr.contains(adr)) blk->do_oop(adr);
   140   adr = cm->adr_stackmap_data();
   141   if (mr.contains(adr)) blk->do_oop(adr);
   142   adr = cm->adr_exception_table();
   143   if (mr.contains(adr)) blk->do_oop(adr);
   144   // Get size before changing pointers.
   145   // Don't call size() or oop_size() since that is a virtual call.
   146   int size = cm->object_size();
   147   // Performance tweak: We skip iterating over the klass pointer since we
   148   // know that Universe::constMethodKlassObj never moves.
   149   return size;
   150 }
   153 int constMethodKlass::oop_adjust_pointers(oop obj) {
   154   assert(obj->is_constMethod(), "should be constMethod");
   155   constMethodOop cm = constMethodOop(obj);
   156   MarkSweep::adjust_pointer(cm->adr_method());
   157   MarkSweep::adjust_pointer(cm->adr_stackmap_data());
   158   MarkSweep::adjust_pointer(cm->adr_exception_table());
   159   // Get size before changing pointers.
   160   // Don't call size() or oop_size() since that is a virtual call.
   161   int size = cm->object_size();
   162   // Performance tweak: We skip iterating over the klass pointer since we
   163   // know that Universe::constMethodKlassObj never moves.
   164   return size;
   165 }
   167 #ifndef SERIALGC
   168 void constMethodKlass::oop_push_contents(PSPromotionManager* pm, oop obj) {
   169   assert(obj->is_constMethod(), "should be constMethod");
   170 }
   172 int constMethodKlass::oop_update_pointers(ParCompactionManager* cm, oop obj) {
   173   assert(obj->is_constMethod(), "should be constMethod");
   174   constMethodOop cm_oop = constMethodOop(obj);
   175 #if 0
   176   PSParallelCompact::adjust_pointer(cm_oop->adr_method());
   177   PSParallelCompact::adjust_pointer(cm_oop->adr_exception_table());
   178   PSParallelCompact::adjust_pointer(cm_oop->adr_stackmap_data());
   179 #endif
   180   oop* const beg_oop = cm_oop->oop_block_beg();
   181   oop* const end_oop = cm_oop->oop_block_end();
   182   for (oop* cur_oop = beg_oop; cur_oop < end_oop; ++cur_oop) {
   183     PSParallelCompact::adjust_pointer(cur_oop);
   184   }
   185   return cm_oop->object_size();
   186 }
   188 int constMethodKlass::oop_update_pointers(ParCompactionManager* cm, oop obj,
   189                                           HeapWord* beg_addr,
   190                                           HeapWord* end_addr) {
   191   assert(obj->is_constMethod(), "should be constMethod");
   192   constMethodOop cm_oop = constMethodOop(obj);
   194   oop* const beg_oop = MAX2((oop*)beg_addr, cm_oop->oop_block_beg());
   195   oop* const end_oop = MIN2((oop*)end_addr, cm_oop->oop_block_end());
   196   for (oop* cur_oop = beg_oop; cur_oop < end_oop; ++cur_oop) {
   197     PSParallelCompact::adjust_pointer(cur_oop);
   198   }
   200   return cm_oop->object_size();
   201 }
   202 #endif // SERIALGC
   204 // Printing
   206 void constMethodKlass::oop_print_on(oop obj, outputStream* st) {
   207   ResourceMark rm;
   208   assert(obj->is_constMethod(), "must be constMethod");
   209   Klass::oop_print_on(obj, st);
   210   constMethodOop m = constMethodOop(obj);
   211   st->print(" - method:       " INTPTR_FORMAT " ", (address)m->method());
   212   m->method()->print_value_on(st); st->cr();
   213   st->print(" - exceptions:   " INTPTR_FORMAT "\n", (address)m->exception_table());
   214   if (m->has_stackmap_table()) {
   215     st->print(" - stackmap data:       ");
   216     m->stackmap_data()->print_value_on(st);
   217     st->cr();
   218   }
   219 }
   221 // Short version of printing constMethodOop - just print the name of the
   222 // method it belongs to.
   223 void constMethodKlass::oop_print_value_on(oop obj, outputStream* st) {
   224   assert(obj->is_constMethod(), "must be constMethod");
   225   constMethodOop m = constMethodOop(obj);
   226   st->print(" const part of method " );
   227   m->method()->print_value_on(st);
   228 }
   230 const char* constMethodKlass::internal_name() const {
   231   return "{constMethod}";
   232 }
   235 // Verification
   237 void constMethodKlass::oop_verify_on(oop obj, outputStream* st) {
   238   Klass::oop_verify_on(obj, st);
   239   guarantee(obj->is_constMethod(), "object must be constMethod");
   240   constMethodOop m = constMethodOop(obj);
   241   guarantee(m->is_perm(),                            "should be in permspace");
   243   // Verification can occur during oop construction before the method or
   244   // other fields have been initialized.
   245   if (!obj->partially_loaded()) {
   246     guarantee(m->method()->is_perm(), "should be in permspace");
   247     guarantee(m->method()->is_method(), "should be method");
   248     typeArrayOop stackmap_data = m->stackmap_data();
   249     guarantee(stackmap_data == NULL ||
   250               stackmap_data->is_perm(),  "should be in permspace");
   251     guarantee(m->exception_table()->is_perm(), "should be in permspace");
   252     guarantee(m->exception_table()->is_typeArray(), "should be type array");
   254     address m_end = (address)((oop*) m + m->size());
   255     address compressed_table_start = m->code_end();
   256     guarantee(compressed_table_start <= m_end, "invalid method layout");
   257     address compressed_table_end = compressed_table_start;
   258     // Verify line number table
   259     if (m->has_linenumber_table()) {
   260       CompressedLineNumberReadStream stream(m->compressed_linenumber_table());
   261       while (stream.read_pair()) {
   262         guarantee(stream.bci() >= 0 && stream.bci() <= m->code_size(), "invalid bci in line number table");
   263       }
   264       compressed_table_end += stream.position();
   265     }
   266     guarantee(compressed_table_end <= m_end, "invalid method layout");
   267     // Verify checked exceptions and local variable tables
   268     if (m->has_checked_exceptions()) {
   269       u2* addr = m->checked_exceptions_length_addr();
   270       guarantee(*addr > 0 && (address) addr >= compressed_table_end && (address) addr < m_end, "invalid method layout");
   271     }
   272     if (m->has_localvariable_table()) {
   273       u2* addr = m->localvariable_table_length_addr();
   274       guarantee(*addr > 0 && (address) addr >= compressed_table_end && (address) addr < m_end, "invalid method layout");
   275     }
   276     // Check compressed_table_end relative to uncompressed_table_start
   277     u2* uncompressed_table_start;
   278     if (m->has_localvariable_table()) {
   279       uncompressed_table_start = (u2*) m->localvariable_table_start();
   280     } else {
   281       if (m->has_checked_exceptions()) {
   282         uncompressed_table_start = (u2*) m->checked_exceptions_start();
   283       } else {
   284         uncompressed_table_start = (u2*) m_end;
   285       }
   286     }
   287     int gap = (intptr_t) uncompressed_table_start - (intptr_t) compressed_table_end;
   288     int max_gap = align_object_size(1)*BytesPerWord;
   289     guarantee(gap >= 0 && gap < max_gap, "invalid method layout");
   290   }
   291 }
   293 bool constMethodKlass::oop_partially_loaded(oop obj) const {
   294   assert(obj->is_constMethod(), "object must be klass");
   295   constMethodOop m = constMethodOop(obj);
   296   // check whether exception_table points to self (flag for partially loaded)
   297   return m->exception_table() == (typeArrayOop)obj;
   298 }
   301 // The exception_table is the last field set when loading an object.
   302 void constMethodKlass::oop_set_partially_loaded(oop obj) {
   303   assert(obj->is_constMethod(), "object must be klass");
   304   constMethodOop m = constMethodOop(obj);
   305   // Temporarily set exception_table to point to self
   306   m->set_exception_table((typeArrayOop)obj);
   307 }

mercurial