src/share/vm/oops/constMethodKlass.cpp

Tue, 26 Jun 2012 19:08:44 -0400

author
jiangli
date
Tue, 26 Jun 2012 19:08:44 -0400
changeset 3917
8150fa46d2ed
parent 3826
2fe087c3e814
permissions
-rw-r--r--

7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
Summary: Change constMethodOop::_exception_table to optionally inlined u2 table.
Reviewed-by: bdelsart, coleenp, kamg

duke@435 1 /*
jiangli@3826 2 * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #include "precompiled.hpp"
stefank@2314 26 #include "gc_implementation/shared/markSweep.inline.hpp"
stefank@2314 27 #include "interpreter/interpreter.hpp"
stefank@2314 28 #include "memory/gcLocker.hpp"
stefank@2314 29 #include "memory/resourceArea.hpp"
stefank@2314 30 #include "oops/constMethodKlass.hpp"
stefank@2314 31 #include "oops/constMethodOop.hpp"
stefank@2314 32 #include "oops/oop.inline.hpp"
stefank@2314 33 #include "oops/oop.inline2.hpp"
stefank@2314 34 #include "runtime/handles.inline.hpp"
duke@435 35
duke@435 36
duke@435 37 klassOop constMethodKlass::create_klass(TRAPS) {
duke@435 38 constMethodKlass o;
duke@435 39 KlassHandle h_this_klass(THREAD, Universe::klassKlassObj());
duke@435 40 KlassHandle k = base_create_klass(h_this_klass, header_size(),
duke@435 41 o.vtbl_value(), CHECK_NULL);
duke@435 42 // Make sure size calculation is right
duke@435 43 assert(k()->size() == align_object_size(header_size()),
duke@435 44 "wrong size for object");
duke@435 45 //java_lang_Class::create_mirror(k, CHECK_NULL); // Allocate mirror
duke@435 46 return k();
duke@435 47 }
duke@435 48
duke@435 49
duke@435 50 int constMethodKlass::oop_size(oop obj) const {
duke@435 51 assert(obj->is_constMethod(), "must be constMethod oop");
duke@435 52 return constMethodOop(obj)->object_size();
duke@435 53 }
duke@435 54
duke@435 55 bool constMethodKlass::oop_is_parsable(oop obj) const {
duke@435 56 assert(obj->is_constMethod(), "must be constMethod oop");
duke@435 57 return constMethodOop(obj)->object_is_parsable();
duke@435 58 }
duke@435 59
jmasa@953 60 bool constMethodKlass::oop_is_conc_safe(oop obj) const {
jmasa@953 61 assert(obj->is_constMethod(), "must be constMethod oop");
jmasa@953 62 return constMethodOop(obj)->is_conc_safe();
jmasa@953 63 }
jmasa@953 64
duke@435 65 constMethodOop constMethodKlass::allocate(int byte_code_size,
duke@435 66 int compressed_line_number_size,
duke@435 67 int localvariable_table_length,
jiangli@3917 68 int exception_table_length,
duke@435 69 int checked_exceptions_length,
jmasa@953 70 bool is_conc_safe,
duke@435 71 TRAPS) {
duke@435 72
duke@435 73 int size = constMethodOopDesc::object_size(byte_code_size,
duke@435 74 compressed_line_number_size,
duke@435 75 localvariable_table_length,
jiangli@3917 76 exception_table_length,
duke@435 77 checked_exceptions_length);
duke@435 78 KlassHandle h_k(THREAD, as_klassOop());
duke@435 79 constMethodOop cm = (constMethodOop)
duke@435 80 CollectedHeap::permanent_obj_allocate(h_k, size, CHECK_NULL);
duke@435 81 assert(!cm->is_parsable(), "Not yet safely parsable");
duke@435 82 No_Safepoint_Verifier no_safepoint;
duke@435 83 cm->set_interpreter_kind(Interpreter::invalid);
duke@435 84 cm->init_fingerprint();
jiangli@3826 85 cm->set_constants(NULL);
duke@435 86 cm->set_stackmap_data(NULL);
duke@435 87 cm->set_code_size(byte_code_size);
duke@435 88 cm->set_constMethod_size(size);
duke@435 89 cm->set_inlined_tables_length(checked_exceptions_length,
duke@435 90 compressed_line_number_size,
jiangli@3917 91 localvariable_table_length,
jiangli@3917 92 exception_table_length);
duke@435 93 assert(cm->size() == size, "wrong size for object");
jmasa@953 94 cm->set_is_conc_safe(is_conc_safe);
duke@435 95 cm->set_partially_loaded();
duke@435 96 assert(cm->is_parsable(), "Is safely parsable by gc");
duke@435 97 return cm;
duke@435 98 }
duke@435 99
duke@435 100 void constMethodKlass::oop_follow_contents(oop obj) {
duke@435 101 assert (obj->is_constMethod(), "object must be constMethod");
duke@435 102 constMethodOop cm = constMethodOop(obj);
jiangli@3826 103 MarkSweep::mark_and_push(cm->adr_constants());
duke@435 104 MarkSweep::mark_and_push(cm->adr_stackmap_data());
duke@435 105 // Performance tweak: We skip iterating over the klass pointer since we
duke@435 106 // know that Universe::constMethodKlassObj never moves.
duke@435 107 }
duke@435 108
duke@435 109 #ifndef SERIALGC
duke@435 110 void constMethodKlass::oop_follow_contents(ParCompactionManager* cm,
duke@435 111 oop obj) {
duke@435 112 assert (obj->is_constMethod(), "object must be constMethod");
duke@435 113 constMethodOop cm_oop = constMethodOop(obj);
jiangli@3826 114 PSParallelCompact::mark_and_push(cm, cm_oop->adr_constants());
duke@435 115 PSParallelCompact::mark_and_push(cm, cm_oop->adr_stackmap_data());
duke@435 116 // Performance tweak: We skip iterating over the klass pointer since we
duke@435 117 // know that Universe::constMethodKlassObj never moves.
duke@435 118 }
duke@435 119 #endif // SERIALGC
duke@435 120
duke@435 121 int constMethodKlass::oop_oop_iterate(oop obj, OopClosure* blk) {
duke@435 122 assert (obj->is_constMethod(), "object must be constMethod");
duke@435 123 constMethodOop cm = constMethodOop(obj);
jiangli@3826 124 blk->do_oop(cm->adr_constants());
duke@435 125 blk->do_oop(cm->adr_stackmap_data());
duke@435 126 // Get size before changing pointers.
duke@435 127 // Don't call size() or oop_size() since that is a virtual call.
duke@435 128 int size = cm->object_size();
duke@435 129 return size;
duke@435 130 }
duke@435 131
duke@435 132
duke@435 133 int constMethodKlass::oop_oop_iterate_m(oop obj, OopClosure* blk, MemRegion mr) {
duke@435 134 assert (obj->is_constMethod(), "object must be constMethod");
duke@435 135 constMethodOop cm = constMethodOop(obj);
duke@435 136 oop* adr;
jiangli@3826 137 adr = cm->adr_constants();
duke@435 138 if (mr.contains(adr)) blk->do_oop(adr);
duke@435 139 adr = cm->adr_stackmap_data();
duke@435 140 if (mr.contains(adr)) blk->do_oop(adr);
duke@435 141 // Get size before changing pointers.
duke@435 142 // Don't call size() or oop_size() since that is a virtual call.
duke@435 143 int size = cm->object_size();
duke@435 144 // Performance tweak: We skip iterating over the klass pointer since we
duke@435 145 // know that Universe::constMethodKlassObj never moves.
duke@435 146 return size;
duke@435 147 }
duke@435 148
duke@435 149
duke@435 150 int constMethodKlass::oop_adjust_pointers(oop obj) {
duke@435 151 assert(obj->is_constMethod(), "should be constMethod");
duke@435 152 constMethodOop cm = constMethodOop(obj);
jiangli@3826 153 MarkSweep::adjust_pointer(cm->adr_constants());
duke@435 154 MarkSweep::adjust_pointer(cm->adr_stackmap_data());
duke@435 155 // Get size before changing pointers.
duke@435 156 // Don't call size() or oop_size() since that is a virtual call.
duke@435 157 int size = cm->object_size();
duke@435 158 // Performance tweak: We skip iterating over the klass pointer since we
duke@435 159 // know that Universe::constMethodKlassObj never moves.
duke@435 160 return size;
duke@435 161 }
duke@435 162
duke@435 163 #ifndef SERIALGC
duke@435 164 void constMethodKlass::oop_push_contents(PSPromotionManager* pm, oop obj) {
duke@435 165 assert(obj->is_constMethod(), "should be constMethod");
duke@435 166 }
duke@435 167
duke@435 168 int constMethodKlass::oop_update_pointers(ParCompactionManager* cm, oop obj) {
duke@435 169 assert(obj->is_constMethod(), "should be constMethod");
duke@435 170 constMethodOop cm_oop = constMethodOop(obj);
duke@435 171 oop* const beg_oop = cm_oop->oop_block_beg();
duke@435 172 oop* const end_oop = cm_oop->oop_block_end();
duke@435 173 for (oop* cur_oop = beg_oop; cur_oop < end_oop; ++cur_oop) {
duke@435 174 PSParallelCompact::adjust_pointer(cur_oop);
duke@435 175 }
duke@435 176 return cm_oop->object_size();
duke@435 177 }
duke@435 178 #endif // SERIALGC
duke@435 179
duke@435 180 // Printing
duke@435 181
duke@435 182 void constMethodKlass::oop_print_on(oop obj, outputStream* st) {
duke@435 183 ResourceMark rm;
duke@435 184 assert(obj->is_constMethod(), "must be constMethod");
duke@435 185 Klass::oop_print_on(obj, st);
duke@435 186 constMethodOop m = constMethodOop(obj);
jiangli@3826 187 st->print(" - constants: " INTPTR_FORMAT " ", (address)m->constants());
jiangli@3826 188 m->constants()->print_value_on(st); st->cr();
duke@435 189 if (m->has_stackmap_table()) {
duke@435 190 st->print(" - stackmap data: ");
duke@435 191 m->stackmap_data()->print_value_on(st);
duke@435 192 st->cr();
duke@435 193 }
duke@435 194 }
duke@435 195
duke@435 196 // Short version of printing constMethodOop - just print the name of the
duke@435 197 // method it belongs to.
duke@435 198 void constMethodKlass::oop_print_value_on(oop obj, outputStream* st) {
duke@435 199 assert(obj->is_constMethod(), "must be constMethod");
duke@435 200 constMethodOop m = constMethodOop(obj);
duke@435 201 st->print(" const part of method " );
duke@435 202 m->method()->print_value_on(st);
duke@435 203 }
duke@435 204
duke@435 205 const char* constMethodKlass::internal_name() const {
duke@435 206 return "{constMethod}";
duke@435 207 }
duke@435 208
duke@435 209
duke@435 210 // Verification
duke@435 211
duke@435 212 void constMethodKlass::oop_verify_on(oop obj, outputStream* st) {
duke@435 213 Klass::oop_verify_on(obj, st);
duke@435 214 guarantee(obj->is_constMethod(), "object must be constMethod");
duke@435 215 constMethodOop m = constMethodOop(obj);
duke@435 216 guarantee(m->is_perm(), "should be in permspace");
duke@435 217
duke@435 218 // Verification can occur during oop construction before the method or
duke@435 219 // other fields have been initialized.
duke@435 220 if (!obj->partially_loaded()) {
jiangli@3826 221 guarantee(m->constants()->is_perm(), "should be in permspace");
jiangli@3826 222 guarantee(m->constants()->is_constantPool(), "should be constant pool");
duke@435 223 typeArrayOop stackmap_data = m->stackmap_data();
duke@435 224 guarantee(stackmap_data == NULL ||
duke@435 225 stackmap_data->is_perm(), "should be in permspace");
duke@435 226
duke@435 227 address m_end = (address)((oop*) m + m->size());
duke@435 228 address compressed_table_start = m->code_end();
duke@435 229 guarantee(compressed_table_start <= m_end, "invalid method layout");
duke@435 230 address compressed_table_end = compressed_table_start;
duke@435 231 // Verify line number table
duke@435 232 if (m->has_linenumber_table()) {
duke@435 233 CompressedLineNumberReadStream stream(m->compressed_linenumber_table());
duke@435 234 while (stream.read_pair()) {
duke@435 235 guarantee(stream.bci() >= 0 && stream.bci() <= m->code_size(), "invalid bci in line number table");
duke@435 236 }
duke@435 237 compressed_table_end += stream.position();
duke@435 238 }
duke@435 239 guarantee(compressed_table_end <= m_end, "invalid method layout");
jiangli@3917 240 // Verify checked exceptions, exception table and local variable tables
duke@435 241 if (m->has_checked_exceptions()) {
duke@435 242 u2* addr = m->checked_exceptions_length_addr();
duke@435 243 guarantee(*addr > 0 && (address) addr >= compressed_table_end && (address) addr < m_end, "invalid method layout");
duke@435 244 }
jiangli@3917 245 if (m->has_exception_handler()) {
jiangli@3917 246 u2* addr = m->exception_table_length_addr();
jiangli@3917 247 guarantee(*addr > 0 && (address) addr >= compressed_table_end && (address) addr < m_end, "invalid method layout");
jiangli@3917 248 }
duke@435 249 if (m->has_localvariable_table()) {
duke@435 250 u2* addr = m->localvariable_table_length_addr();
duke@435 251 guarantee(*addr > 0 && (address) addr >= compressed_table_end && (address) addr < m_end, "invalid method layout");
duke@435 252 }
duke@435 253 // Check compressed_table_end relative to uncompressed_table_start
duke@435 254 u2* uncompressed_table_start;
duke@435 255 if (m->has_localvariable_table()) {
duke@435 256 uncompressed_table_start = (u2*) m->localvariable_table_start();
jiangli@3917 257 } else if (m->has_exception_handler()) {
jiangli@3917 258 uncompressed_table_start = (u2*) m->exception_table_start();
jiangli@3917 259 } else if (m->has_checked_exceptions()) {
jiangli@3917 260 uncompressed_table_start = (u2*) m->checked_exceptions_start();
duke@435 261 } else {
duke@435 262 uncompressed_table_start = (u2*) m_end;
duke@435 263 }
duke@435 264 int gap = (intptr_t) uncompressed_table_start - (intptr_t) compressed_table_end;
duke@435 265 int max_gap = align_object_size(1)*BytesPerWord;
duke@435 266 guarantee(gap >= 0 && gap < max_gap, "invalid method layout");
duke@435 267 }
duke@435 268 }
duke@435 269
duke@435 270 bool constMethodKlass::oop_partially_loaded(oop obj) const {
duke@435 271 assert(obj->is_constMethod(), "object must be klass");
duke@435 272 constMethodOop m = constMethodOop(obj);
jiangli@3917 273 // check whether stackmap_data points to self (flag for partially loaded)
jiangli@3917 274 return m->stackmap_data() == (typeArrayOop)obj;
duke@435 275 }
duke@435 276
duke@435 277
duke@435 278 // The exception_table is the last field set when loading an object.
duke@435 279 void constMethodKlass::oop_set_partially_loaded(oop obj) {
duke@435 280 assert(obj->is_constMethod(), "object must be klass");
duke@435 281 constMethodOop m = constMethodOop(obj);
jiangli@3917 282 // Temporarily set stackmap_data to point to self
jiangli@3917 283 m->set_stackmap_data((typeArrayOop)obj);
duke@435 284 }

mercurial