|
Java Class Encryption and License Management
Create evaluation versions, host- and user based licenses using the same installation package. FREE evaluation version available. www.jsecurity.net |
00001 #ifdef USE_PRAGMA_IDENT_SRC 00002 #pragma ident "@(#)interpreter.cpp 1.246 07/06/08 15:21:43 JVM" 00003 #endif 00004 /* 00005 * Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved. 00006 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 00007 * 00008 * This code is free software; you can redistribute it and/or modify it 00009 * under the terms of the GNU General Public License version 2 only, as 00010 * published by the Free Software Foundation. 00011 * 00012 * This code is distributed in the hope that it will be useful, but WITHOUT 00013 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00014 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00015 * version 2 for more details (a copy is included in the LICENSE file that 00016 * accompanied this code). 00017 * 00018 * You should have received a copy of the GNU General Public License version 00019 * 2 along with this work; if not, write to the Free Software Foundation, 00020 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 00021 * 00022 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 00023 * CA 95054 USA or visit www.sun.com if you need additional information or 00024 * have any questions. 00025 * 00026 */ 00027 00028 #include "incls/_precompiled.incl" 00029 #include "incls/_interpreter.cpp.incl" 00030 00031 # define __ _masm-> 00032 00033 00034 //------------------------------------------------------------------------------------------------------------------------ 00035 // Implementation of InterpreterCodelet 00036 00037 void InterpreterCodelet::initialize(const char* description, Bytecodes::Code bytecode) { 00038 _description = description; 00039 _bytecode = bytecode; 00040 } 00041 00042 00043 void InterpreterCodelet::verify() { 00044 } 00045 00046 00047 void InterpreterCodelet::print() { 00048 if (PrintInterpreter) { 00049 tty->cr(); 00050 tty->print_cr("----------------------------------------------------------------------"); 00051 } 00052 00053 if (description() != NULL) tty->print("%s ", description()); 00054 if (bytecode() >= 0 ) tty->print("%d %s ", bytecode(), Bytecodes::name(bytecode())); 00055 tty->print_cr("[" INTPTR_FORMAT ", " INTPTR_FORMAT "] %d bytes", 00056 code_begin(), code_end(), code_size()); 00057 00058 if (PrintInterpreter) { 00059 tty->cr(); 00060 Disassembler::decode(code_begin(), code_end(), tty); 00061 } 00062 } 00063 00064 00065 //------------------------------------------------------------------------------------------------------------------------ 00066 // Implementation of AbstractInterpreter 00067 00068 00069 // Define a prototype interface 00070 DEF_STUB_INTERFACE(InterpreterCodelet); 00071 00072 00073 void AbstractInterpreter::initialize() { 00074 if (_code != NULL) return; 00075 00076 // assertions 00077 #ifndef CC_INTERP 00078 assert((int)Bytecodes::number_of_codes <= (int)DispatchTable::length, 00079 "dispatch table too small"); 00080 #endif /* !CC_INTERP */ 00081 00082 // make sure 'imported' classes are initialized 00083 if (CountBytecodes || TraceBytecodes || StopInterpreterAt) BytecodeCounter::reset(); 00084 if (PrintBytecodeHistogram) BytecodeHistogram::reset(); 00085 if (PrintBytecodePairHistogram) BytecodePairHistogram::reset(); 00086 #ifndef CC_INTERP 00087 TemplateTable::initialize(); 00088 #endif /* !CC_INTERP */ 00089 InvocationCounter::reinitialize(DelayCompilationDuringStartup); 00090 00091 // generate interpreter 00092 { ResourceMark rm; 00093 TraceTime timer("Interpreter generation", TraceStartupTime); 00094 int code_size = Interpreter::InterpreterCodeSize; 00095 NOT_PRODUCT(code_size *= 4;) // debug uses extra interpreter code space 00096 _code = new StubQueue(new InterpreterCodeletInterface, code_size, NULL, 00097 "Interpreter"); 00098 InterpreterGenerator g(_code); 00099 if (PrintInterpreter) print(); 00100 } 00101 00102 #ifdef CC_INTERP 00103 { 00104 // Allow c++ interpreter to do one initialization now that switches are set, etc. 00105 cInterpreter start_msg(cInterpreter::initialize); 00106 if (JvmtiExport::can_post_interpreter_events()) 00107 cInterpreter::InterpretMethodWithChecks(&start_msg); 00108 else 00109 cInterpreter::InterpretMethod(&start_msg); 00110 } 00111 #else 00112 // initialize dispatch table 00113 _active_table = _normal_table; 00114 #endif // CC_INTERP 00115 } 00116 00117 00118 void AbstractInterpreter::print() { 00119 tty->cr(); 00120 tty->print_cr("----------------------------------------------------------------------"); 00121 tty->print_cr("Interpreter"); 00122 tty->cr(); 00123 tty->print_cr("code size = %6dK bytes", (int)_code->used_space()/1024); 00124 tty->print_cr("total space = %6dK bytes", (int)_code->total_space()/1024); 00125 tty->print_cr("wasted space = %6dK bytes", (int)_code->available_space()/1024); 00126 tty->cr(); 00127 tty->print_cr("# of codelets = %6d" , _code->number_of_stubs()); 00128 tty->print_cr("avg codelet size = %6d bytes", _code->used_space() / _code->number_of_stubs()); 00129 tty->cr(); 00130 _code->print(); 00131 tty->print_cr("----------------------------------------------------------------------"); 00132 tty->cr(); 00133 } 00134 00135 00136 void interpreter_init() { 00137 Interpreter::initialize(); 00138 #ifndef PRODUCT 00139 if (TraceBytecodes) BytecodeTracer::set_closure(BytecodeTracer::std_closure()); 00140 #endif // PRODUCT 00141 // need to hit every safepoint in order to call zapping routine 00142 // register the interpreter 00143 VTune::register_stub( 00144 "Interpreter", 00145 AbstractInterpreter::code()->code_start(), 00146 AbstractInterpreter::code()->code_end() 00147 ); 00148 Forte::register_stub( 00149 "Interpreter", 00150 AbstractInterpreter::code()->code_start(), 00151 AbstractInterpreter::code()->code_end() 00152 ); 00153 00154 // notify JVMTI profiler 00155 if (JvmtiExport::should_post_dynamic_code_generated()) { 00156 JvmtiExport::post_dynamic_code_generated("Interpreter", 00157 AbstractInterpreter::code()->code_start(), 00158 AbstractInterpreter::code()->code_end()); 00159 } 00160 } 00161 00162 00163 #ifndef CC_INTERP 00164 //------------------------------------------------------------------------------------------------------------------------ 00165 // Implementation of EntryPoint 00166 00167 EntryPoint::EntryPoint() { 00168 assert(number_of_states == 9, "check the code below"); 00169 _entry[btos] = NULL; 00170 _entry[ctos] = NULL; 00171 _entry[stos] = NULL; 00172 _entry[atos] = NULL; 00173 _entry[itos] = NULL; 00174 _entry[ltos] = NULL; 00175 _entry[ftos] = NULL; 00176 _entry[dtos] = NULL; 00177 _entry[vtos] = NULL; 00178 } 00179 00180 00181 EntryPoint::EntryPoint(address bentry, address centry, address sentry, address aentry, address ientry, address lentry, address fentry, address dentry, address ventry) { 00182 assert(number_of_states == 9, "check the code below"); 00183 _entry[btos] = bentry; 00184 _entry[ctos] = centry; 00185 _entry[stos] = sentry; 00186 _entry[atos] = aentry; 00187 _entry[itos] = ientry; 00188 _entry[ltos] = lentry; 00189 _entry[ftos] = fentry; 00190 _entry[dtos] = dentry; 00191 _entry[vtos] = ventry; 00192 } 00193 00194 00195 void EntryPoint::set_entry(TosState state, address entry) { 00196 assert(0 <= state && state < number_of_states, "state out of bounds"); 00197 _entry[state] = entry; 00198 } 00199 00200 00201 address EntryPoint::entry(TosState state) const { 00202 assert(0 <= state && state < number_of_states, "state out of bounds"); 00203 return _entry[state]; 00204 } 00205 00206 00207 void EntryPoint::print() { 00208 tty->print("["); 00209 for (int i = 0; i < number_of_states; i++) { 00210 if (i > 0) tty->print(", "); 00211 tty->print(INTPTR_FORMAT, _entry[i]); 00212 } 00213 tty->print("]"); 00214 } 00215 00216 00217 bool EntryPoint::operator == (const EntryPoint& y) { 00218 int i = number_of_states; 00219 while (i-- > 0) { 00220 if (_entry[i] != y._entry[i]) return false; 00221 } 00222 return true; 00223 } 00224 00225 00226 //------------------------------------------------------------------------------------------------------------------------ 00227 // Implementation of DispatchTable 00228 00229 EntryPoint DispatchTable::entry(int i) const { 00230 assert(0 <= i && i < length, "index out of bounds"); 00231 return 00232 EntryPoint( 00233 _table[btos][i], 00234 _table[ctos][i], 00235 _table[stos][i], 00236 _table[atos][i], 00237 _table[itos][i], 00238 _table[ltos][i], 00239 _table[ftos][i], 00240 _table[dtos][i], 00241 _table[vtos][i] 00242 ); 00243 } 00244 00245 00246 void DispatchTable::set_entry(int i, EntryPoint& entry) { 00247 assert(0 <= i && i < length, "index out of bounds"); 00248 assert(number_of_states == 9, "check the code below"); 00249 _table[btos][i] = entry.entry(btos); 00250 _table[ctos][i] = entry.entry(ctos); 00251 _table[stos][i] = entry.entry(stos); 00252 _table[atos][i] = entry.entry(atos); 00253 _table[itos][i] = entry.entry(itos); 00254 _table[ltos][i] = entry.entry(ltos); 00255 _table[ftos][i] = entry.entry(ftos); 00256 _table[dtos][i] = entry.entry(dtos); 00257 _table[vtos][i] = entry.entry(vtos); 00258 } 00259 00260 00261 bool DispatchTable::operator == (DispatchTable& y) { 00262 int i = length; 00263 while (i-- > 0) { 00264 EntryPoint t = y.entry(i); // for compiler compatibility (BugId 4150096) 00265 if (!(entry(i) == t)) return false; 00266 } 00267 return true; 00268 } 00269 #endif // CC_INTERP 00270 00271 00272 //------------------------------------------------------------------------------------------------------------------------ 00273 // Implementation of interpreter 00274 00275 StubQueue* AbstractInterpreter::_code = NULL; 00276 bool AbstractInterpreter::_notice_safepoints = false; 00277 00278 address AbstractInterpreter::_rethrow_exception_entry = NULL; 00279 #ifndef CC_INTERP 00280 address AbstractInterpreter::_remove_activation_entry = NULL; 00281 address AbstractInterpreter::_remove_activation_preserving_args_entry = NULL; 00282 00283 00284 address AbstractInterpreter::_throw_ArrayIndexOutOfBoundsException_entry = NULL; 00285 address AbstractInterpreter::_throw_ArrayStoreException_entry = NULL; 00286 address AbstractInterpreter::_throw_ArithmeticException_entry = NULL; 00287 address AbstractInterpreter::_throw_ClassCastException_entry = NULL; 00288 address AbstractInterpreter::_throw_NullPointerException_entry = NULL; 00289 address AbstractInterpreter::_throw_StackOverflowError_entry = NULL; 00290 address AbstractInterpreter::_throw_exception_entry = NULL; 00291 00292 #ifndef PRODUCT 00293 EntryPoint AbstractInterpreter::_trace_code; 00294 #endif // !PRODUCT 00295 EntryPoint AbstractInterpreter::_return_entry[AbstractInterpreter::number_of_return_entries]; 00296 EntryPoint AbstractInterpreter::_earlyret_entry; 00297 EntryPoint AbstractInterpreter::_deopt_entry [AbstractInterpreter::number_of_deopt_entries ]; 00298 EntryPoint AbstractInterpreter::_continuation_entry; 00299 EntryPoint AbstractInterpreter::_safept_entry; 00300 00301 address AbstractInterpreter::_return_3_addrs_by_index[AbstractInterpreter::number_of_return_addrs]; 00302 address AbstractInterpreter::_return_5_addrs_by_index[AbstractInterpreter::number_of_return_addrs]; 00303 00304 DispatchTable AbstractInterpreter::_active_table; 00305 DispatchTable AbstractInterpreter::_normal_table; 00306 DispatchTable AbstractInterpreter::_safept_table; 00307 address AbstractInterpreter::_wentry_point[DispatchTable::length]; 00308 #endif // CC_INTERP 00309 00310 address AbstractInterpreter::_native_entry_begin = NULL; 00311 address AbstractInterpreter::_native_entry_end = NULL; 00312 address AbstractInterpreter::_slow_signature_handler; 00313 address AbstractInterpreter::_entry_table [AbstractInterpreter::number_of_method_entries]; 00314 address AbstractInterpreter::_native_abi_to_tosca [AbstractInterpreter::number_of_result_handlers]; 00315 #ifdef CC_INTERP 00316 address AbstractInterpreter::_tosca_to_stack [AbstractInterpreter::number_of_result_handlers]; 00317 address AbstractInterpreter::_stack_to_stack [AbstractInterpreter::number_of_result_handlers]; 00318 address AbstractInterpreter::_stack_to_native_abi [AbstractInterpreter::number_of_result_handlers]; 00319 #endif 00320 00321 00322 //------------------------------------------------------------------------------------------------------------------------ 00323 // A CodeletMark serves as an automatic creator/initializer for Codelets 00324 // (As a subclass of ResourceMark it automatically GC's the allocated 00325 // code buffer and assemblers). 00326 00327 class CodeletMark: ResourceMark { 00328 private: 00329 InterpreterCodelet* _clet; 00330 InterpreterMacroAssembler** _masm; 00331 CodeBuffer _cb; 00332 00333 int codelet_size() { 00334 // Request the whole code buffer (minus a little for alignment). 00335 // The commit call below trims it back for each codelet. 00336 int codelet_size = AbstractInterpreter::code()->available_space() - 2*K; 00337 00338 // Guarantee there's a little bit of code space left. 00339 guarantee (codelet_size > 0 && (size_t)codelet_size > 2*K, 00340 "not enough space for interpreter generation"); 00341 00342 return codelet_size; 00343 } 00344 00345 public: 00346 CodeletMark( 00347 InterpreterMacroAssembler*& masm, 00348 const char* description, 00349 Bytecodes::Code bytecode = Bytecodes::_illegal): 00350 _clet((InterpreterCodelet*)AbstractInterpreter::code()->request(codelet_size())), 00351 _cb(_clet->code_begin(), _clet->code_size()) 00352 00353 { // request all space (add some slack for Codelet data) 00354 assert (_clet != NULL, "we checked not enough space already"); 00355 00356 // initialize Codelet attributes 00357 _clet->initialize(description, bytecode); 00358 // create assembler for code generation 00359 masm = new InterpreterMacroAssembler(&_cb); 00360 _masm = &masm; 00361 } 00362 00363 ~CodeletMark() { 00364 // align so printing shows nop's instead of random code at the end (Codelets are aligned) 00365 (*_masm)->align(wordSize); 00366 // make sure all code is in code buffer 00367 (*_masm)->flush(); 00368 00369 00370 // commit Codelet 00371 AbstractInterpreter::code()->commit((*_masm)->code()->pure_code_size()); 00372 // make sure nobody can use _masm outside a CodeletMark lifespan 00373 *_masm = NULL; 00374 } 00375 }; 00376 00377 00378 //------------------------------------------------------------------------------------------------------------------------ 00379 // Generation of complete interpreter 00380 00381 AbstractInterpreterGenerator::AbstractInterpreterGenerator(StubQueue* _code) { 00382 _masm = NULL; 00383 #ifndef CC_INTERP 00384 _unimplemented_bytecode = NULL; 00385 _illegal_bytecode_sequence = NULL; 00386 #endif // CC_INTERP 00387 } 00388 00389 00390 void AbstractInterpreterGenerator::generate_all() { 00391 #ifndef CC_INTERP 00392 { CodeletMark cm(_masm, "error exits"); 00393 _unimplemented_bytecode = generate_error_exit("unimplemented bytecode"); 00394 _illegal_bytecode_sequence = generate_error_exit("illegal bytecode sequence - method not verified"); 00395 } 00396 00397 #ifndef PRODUCT 00398 if (TraceBytecodes) { 00399 CodeletMark cm(_masm, "bytecode tracing support"); 00400 Interpreter::_trace_code = 00401 EntryPoint( 00402 generate_trace_code(btos), 00403 generate_trace_code(ctos), 00404 generate_trace_code(stos), 00405 generate_trace_code(atos), 00406 generate_trace_code(itos), 00407 generate_trace_code(ltos), 00408 generate_trace_code(ftos), 00409 generate_trace_code(dtos), 00410 generate_trace_code(vtos) 00411 ); 00412 } 00413 #endif // !PRODUCT 00414 00415 { CodeletMark cm(_masm, "return entry points"); 00416 for (int i = 0; i < Interpreter::number_of_return_entries; i++) { 00417 Interpreter::_return_entry[i] = 00418 EntryPoint( 00419 generate_return_entry_for(itos, i), 00420 generate_return_entry_for(itos, i), 00421 generate_return_entry_for(itos, i), 00422 generate_return_entry_for(atos, i), 00423 generate_return_entry_for(itos, i), 00424 generate_return_entry_for(ltos, i), 00425 generate_return_entry_for(ftos, i), 00426 generate_return_entry_for(dtos, i), 00427 generate_return_entry_for(vtos, i) 00428 ); 00429 } 00430 } 00431 00432 { CodeletMark cm(_masm, "earlyret entry points"); 00433 Interpreter::_earlyret_entry = 00434 EntryPoint( 00435 generate_earlyret_entry_for(btos), 00436 generate_earlyret_entry_for(ctos), 00437 generate_earlyret_entry_for(stos), 00438 generate_earlyret_entry_for(atos), 00439 generate_earlyret_entry_for(itos), 00440 generate_earlyret_entry_for(ltos), 00441 generate_earlyret_entry_for(ftos), 00442 generate_earlyret_entry_for(dtos), 00443 generate_earlyret_entry_for(vtos) 00444 ); 00445 } 00446 00447 { CodeletMark cm(_masm, "deoptimization entry points"); 00448 for (int i = 0; i < Interpreter::number_of_deopt_entries; i++) { 00449 Interpreter::_deopt_entry[i] = 00450 EntryPoint( 00451 generate_deopt_entry_for(itos, i), 00452 generate_deopt_entry_for(itos, i), 00453 generate_deopt_entry_for(itos, i), 00454 generate_deopt_entry_for(atos, i), 00455 generate_deopt_entry_for(itos, i), 00456 generate_deopt_entry_for(ltos, i), 00457 generate_deopt_entry_for(ftos, i), 00458 generate_deopt_entry_for(dtos, i), 00459 generate_deopt_entry_for(vtos, i) 00460 ); 00461 } 00462 } 00463 00464 #endif // !CC_INTERP 00465 00466 { CodeletMark cm(_masm, "result handlers for native calls"); 00467 const BasicType types[Interpreter::number_of_result_handlers] = { 00468 T_BOOLEAN, 00469 T_CHAR , 00470 T_BYTE , 00471 T_SHORT , 00472 T_INT , 00473 T_LONG , 00474 T_VOID , 00475 T_FLOAT , 00476 T_DOUBLE , 00477 T_OBJECT 00478 }; 00479 // The various result converter stublets. 00480 int is_generated[Interpreter::number_of_result_handlers]; 00481 memset(is_generated, 0, sizeof(is_generated)); 00482 #ifdef CC_INTERP 00483 int _tosca_to_stack_is_generated[Interpreter::number_of_result_handlers]; 00484 int _stack_to_stack_is_generated[Interpreter::number_of_result_handlers]; 00485 int _stack_to_native_abi_is_generated[Interpreter::number_of_result_handlers]; 00486 00487 memset(_tosca_to_stack_is_generated, 0, sizeof(_tosca_to_stack_is_generated)); 00488 memset(_stack_to_stack_is_generated, 0, sizeof(_stack_to_stack_is_generated)); 00489 memset(_stack_to_native_abi_is_generated, 0, sizeof(_stack_to_native_abi_is_generated)); 00490 #endif 00491 for (int i = 0; i < Interpreter::number_of_result_handlers; i++) { 00492 BasicType type = types[i]; 00493 if (!is_generated[Interpreter::BasicType_as_index(type)]++) { 00494 Interpreter::_native_abi_to_tosca[Interpreter::BasicType_as_index(type)] = generate_result_handler_for(type); 00495 } 00496 #ifdef CC_INTERP 00497 if (!_tosca_to_stack_is_generated[Interpreter::BasicType_as_index(type)]++) { 00498 Interpreter::_tosca_to_stack[Interpreter::BasicType_as_index(type)] = generate_tosca_to_stack_converter(type); 00499 } 00500 if (!_stack_to_stack_is_generated[Interpreter::BasicType_as_index(type)]++) { 00501 Interpreter::_stack_to_stack[Interpreter::BasicType_as_index(type)] = generate_stack_to_stack_converter(type); 00502 } 00503 if (!_stack_to_native_abi_is_generated[Interpreter::BasicType_as_index(type)]++) { 00504 Interpreter::_stack_to_native_abi[Interpreter::BasicType_as_index(type)] = generate_stack_to_native_abi_converter(type); 00505 } 00506 #endif 00507 } 00508 } 00509 00510 { CodeletMark cm(_masm, "slow signature handler"); 00511 Interpreter::_slow_signature_handler = generate_slow_signature_handler(); 00512 } 00513 00514 #ifndef CC_INTERP 00515 for (int j = 0; j < number_of_states; j++) { 00516 const TosState states[] = {btos, ctos, stos, itos, ltos, ftos, dtos, atos, vtos}; 00517 Interpreter::_return_3_addrs_by_index[Interpreter::TosState_as_index(states[j])] = Interpreter::return_entry(states[j], 3); 00518 Interpreter::_return_5_addrs_by_index[Interpreter::TosState_as_index(states[j])] = Interpreter::return_entry(states[j], 5); 00519 } 00520 00521 { CodeletMark cm(_masm, "continuation entry points"); 00522 Interpreter::_continuation_entry = 00523 EntryPoint( 00524 generate_continuation_for(btos), 00525 generate_continuation_for(ctos), 00526 generate_continuation_for(stos), 00527 generate_continuation_for(atos), 00528 generate_continuation_for(itos), 00529 generate_continuation_for(ltos), 00530 generate_continuation_for(ftos), 00531 generate_continuation_for(dtos), 00532 generate_continuation_for(vtos) 00533 ); 00534 } 00535 00536 { CodeletMark cm(_masm, "safepoint entry points"); 00537 Interpreter::_safept_entry = 00538 EntryPoint( 00539 generate_safept_entry_for(btos, CAST_FROM_FN_PTR(address, InterpreterRuntime::at_safepoint)), 00540 generate_safept_entry_for(ctos, CAST_FROM_FN_PTR(address, InterpreterRuntime::at_safepoint)), 00541 generate_safept_entry_for(stos, CAST_FROM_FN_PTR(address, InterpreterRuntime::at_safepoint)), 00542 generate_safept_entry_for(atos, CAST_FROM_FN_PTR(address, InterpreterRuntime::at_safepoint)), 00543 generate_safept_entry_for(itos, CAST_FROM_FN_PTR(address, InterpreterRuntime::at_safepoint)), 00544 generate_safept_entry_for(ltos, CAST_FROM_FN_PTR(address, InterpreterRuntime::at_safepoint)), 00545 generate_safept_entry_for(ftos, CAST_FROM_FN_PTR(address, InterpreterRuntime::at_safepoint)), 00546 generate_safept_entry_for(dtos, CAST_FROM_FN_PTR(address, InterpreterRuntime::at_safepoint)), 00547 generate_safept_entry_for(vtos, CAST_FROM_FN_PTR(address, InterpreterRuntime::at_safepoint)) 00548 ); 00549 } 00550 00551 { CodeletMark cm(_masm, "exception handling"); 00552 // (Note: this is not safepoint safe because thread may return to compiled code) 00553 generate_throw_exception(); 00554 } 00555 00556 { CodeletMark cm(_masm, "throw exception entrypoints"); 00557 Interpreter::_throw_ArrayIndexOutOfBoundsException_entry = generate_ArrayIndexOutOfBounds_handler("java/lang/ArrayIndexOutOfBoundsException"); 00558 Interpreter::_throw_ArrayStoreException_entry = generate_klass_exception_handler("java/lang/ArrayStoreException" ); 00559 Interpreter::_throw_ArithmeticException_entry = generate_exception_handler("java/lang/ArithmeticException" , "/ by zero"); 00560 Interpreter::_throw_ClassCastException_entry = generate_ClassCastException_handler(); 00561 Interpreter::_throw_NullPointerException_entry = generate_exception_handler("java/lang/NullPointerException" , NULL ); 00562 Interpreter::_throw_StackOverflowError_entry = generate_StackOverflowError_handler(); 00563 } 00564 #endif // !CC_INTERP 00565 00566 00567 #ifdef CC_INTERP 00568 00569 #define method_entry(kind) Interpreter::_entry_table[Interpreter::kind] = generate_method_entry(Interpreter::kind) 00570 00571 { CodeletMark cm(_masm, "(kind = frame_manager)"); 00572 // all non-native method kinds 00573 method_entry(zerolocals); 00574 method_entry(zerolocals_synchronized); 00575 method_entry(empty); 00576 method_entry(accessor); 00577 method_entry(abstract); 00578 method_entry(java_lang_math_sin ); 00579 method_entry(java_lang_math_cos ); 00580 method_entry(java_lang_math_tan ); 00581 method_entry(java_lang_math_abs ); 00582 method_entry(java_lang_math_sqrt ); 00583 method_entry(java_lang_math_log ); 00584 method_entry(java_lang_math_log10 ); 00585 Interpreter::_native_entry_begin = Interpreter::code()->code_end(); 00586 method_entry(native); 00587 method_entry(native_synchronized); 00588 Interpreter::_native_entry_end = Interpreter::code()->code_end(); 00589 } 00590 00591 #else 00592 00593 #define method_entry(kind) \ 00594 { CodeletMark cm(_masm, "method entry point (kind = " #kind ")"); \ 00595 Interpreter::_entry_table[Interpreter::kind] = generate_method_entry(Interpreter::kind); \ 00596 } 00597 00598 // all non-native method kinds 00599 method_entry(zerolocals) 00600 method_entry(zerolocals_synchronized) 00601 method_entry(empty) 00602 method_entry(accessor) 00603 method_entry(abstract) 00604 method_entry(java_lang_math_sin ) 00605 method_entry(java_lang_math_cos ) 00606 method_entry(java_lang_math_tan ) 00607 method_entry(java_lang_math_abs ) 00608 method_entry(java_lang_math_sqrt ) 00609 method_entry(java_lang_math_log ) 00610 method_entry(java_lang_math_log10) 00611 00612 // all native method kinds (must be one contiguous block) 00613 Interpreter::_native_entry_begin = Interpreter::code()->code_end(); 00614 method_entry(native) 00615 method_entry(native_synchronized) 00616 Interpreter::_native_entry_end = Interpreter::code()->code_end(); 00617 00618 #endif // !CC_INTERP 00619 00620 #undef method_entry 00621 00622 #ifndef CC_INTERP 00623 // Bytecodes 00624 set_entry_points_for_all_bytes(); 00625 set_safepoints_for_all_bytes(); 00626 #endif // !CC_INTERP 00627 } 00628 00629 00630 //------------------------------------------------------------------------------------------------------------------------ 00631 00632 #ifndef CC_INTERP 00633 address AbstractInterpreterGenerator::generate_error_exit(const char* msg) { 00634 address entry = __ pc(); 00635 __ stop(msg); 00636 return entry; 00637 } 00638 00639 00640 //------------------------------------------------------------------------------------------------------------------------ 00641 00642 void AbstractInterpreterGenerator::set_entry_points_for_all_bytes() { 00643 for (int i = 0; i < DispatchTable::length; i++) { 00644 Bytecodes::Code code = (Bytecodes::Code)i; 00645 if (Bytecodes::is_defined(code)) { 00646 set_entry_points(code); 00647 } else { 00648 set_unimplemented(i); 00649 } 00650 } 00651 } 00652 00653 00654 void AbstractInterpreterGenerator::set_safepoints_for_all_bytes() { 00655 for (int i = 0; i < DispatchTable::length; i++) { 00656 Bytecodes::Code code = (Bytecodes::Code)i; 00657 if (Bytecodes::is_defined(code)) Interpreter::_safept_table.set_entry(code, Interpreter::_safept_entry); 00658 } 00659 } 00660 00661 00662 void AbstractInterpreterGenerator::set_unimplemented(int i) { 00663 address e = _unimplemented_bytecode; 00664 EntryPoint entry(e, e, e, e, e, e, e, e, e); 00665 Interpreter::_normal_table.set_entry(i, entry); 00666 Interpreter::_wentry_point[i] = _unimplemented_bytecode; 00667 } 00668 00669 00670 void AbstractInterpreterGenerator::set_entry_points(Bytecodes::Code code) { 00671 CodeletMark cm(_masm, Bytecodes::name(code), code); 00672 // initialize entry points 00673 assert(_unimplemented_bytecode != NULL, "should have been generated before"); 00674 assert(_illegal_bytecode_sequence != NULL, "should have been generated before"); 00675 address bep = _illegal_bytecode_sequence; 00676 address cep = _illegal_bytecode_sequence; 00677 address sep = _illegal_bytecode_sequence; 00678 address aep = _illegal_bytecode_sequence; 00679 address iep = _illegal_bytecode_sequence; 00680 address lep = _illegal_bytecode_sequence; 00681 address fep = _illegal_bytecode_sequence; 00682 address dep = _illegal_bytecode_sequence; 00683 address vep = _unimplemented_bytecode; 00684 address wep = _unimplemented_bytecode; 00685 // code for short & wide version of bytecode 00686 if (Bytecodes::is_defined(code)) { 00687 Template* t = TemplateTable::template_for(code); 00688 assert(t->is_valid(), "just checking"); 00689 set_short_entry_points(t, bep, cep, sep, aep, iep, lep, fep, dep, vep); 00690 } 00691 if (Bytecodes::wide_is_defined(code)) { 00692 Template* t = TemplateTable::template_for_wide(code); 00693 assert(t->is_valid(), "just checking"); 00694 set_wide_entry_point(t, wep); 00695 } 00696 // set entry points 00697 EntryPoint entry(bep, cep, sep, aep, iep, lep, fep, dep, vep); 00698 Interpreter::_normal_table.set_entry(code, entry); 00699 Interpreter::_wentry_point[code] = wep; 00700 } 00701 00702 00703 void AbstractInterpreterGenerator::set_wide_entry_point(Template* t, address& wep) { 00704 assert(t->is_valid(), "template must exist"); 00705 assert(t->tos_in() == vtos, "only vtos tos_in supported for wide instructions") 00706 wep = __ pc(); generate_and_dispatch(t); 00707 } 00708 00709 00710 void AbstractInterpreterGenerator::set_short_entry_points(Template* t, address& bep, address& cep, address& sep, address& aep, address& iep, address& lep, address& fep, address& dep, address& vep) { 00711 assert(t->is_valid(), "template must exist"); 00712 switch (t->tos_in()) { 00713 case btos: vep = __ pc(); __ pop(btos); bep = __ pc(); generate_and_dispatch(t); break; 00714 case ctos: vep = __ pc(); __ pop(ctos); sep = __ pc(); generate_and_dispatch(t); break; 00715 case stos: vep = __ pc(); __ pop(stos); sep = __ pc(); generate_and_dispatch(t); break; 00716 case atos: vep = __ pc(); __ pop(atos); aep = __ pc(); generate_and_dispatch(t); break; 00717 case itos: vep = __ pc(); __ pop(itos); iep = __ pc(); generate_and_dispatch(t); break; 00718 case ltos: vep = __ pc(); __ pop(ltos); lep = __ pc(); generate_and_dispatch(t); break; 00719 case ftos: vep = __ pc(); __ pop(ftos); fep = __ pc(); generate_and_dispatch(t); break; 00720 case dtos: vep = __ pc(); __ pop(dtos); dep = __ pc(); generate_and_dispatch(t); break; 00721 case vtos: set_vtos_entry_points(t, bep, cep, sep, aep, iep, lep, fep, dep, vep); break; 00722 default : ShouldNotReachHere(); break; 00723 } 00724 } 00725 00726 00727 //------------------------------------------------------------------------------------------------------------------------ 00728 00729 void AbstractInterpreterGenerator::generate_and_dispatch(Template* t, TosState tos_out) { 00730 #ifndef CC_INTERP 00731 if (PrintBytecodeHistogram) histogram_bytecode(t); 00732 #ifndef PRODUCT 00733 // debugging code 00734 if (CountBytecodes || TraceBytecodes || StopInterpreterAt > 0) count_bytecode(); 00735 if (PrintBytecodePairHistogram) histogram_bytecode_pair(t); 00736 if (TraceBytecodes) trace_bytecode(t); 00737 if (StopInterpreterAt > 0) stop_interpreter_at(); 00738 __ verify_FPU(1, t->tos_in()); 00739 #endif // !PRODUCT 00740 int step; 00741 if (!t->does_dispatch()) { 00742 step = t->is_wide() ? Bytecodes::wide_length_for(t->bytecode()) : Bytecodes::length_for(t->bytecode()); 00743 if (tos_out == ilgl) tos_out = t->tos_out(); 00744 // compute bytecode size 00745 assert(step > 0, "just checkin'"); 00746 // setup stuff for dispatching next bytecode 00747 if (ProfileInterpreter && VerifyDataPointer 00748 && methodDataOopDesc::bytecode_has_profile(t->bytecode())) { 00749 __ verify_method_data_pointer(); 00750 } 00751 __ dispatch_prolog(tos_out, step); 00752 } 00753 // generate template 00754 t->generate(_masm); 00755 // advance 00756 if (t->does_dispatch()) { 00757 #ifdef ASSERT 00758 // make sure execution doesn't go beyond this point if code is broken 00759 __ should_not_reach_here(); 00760 #endif // ASSERT 00761 } else { 00762 // dispatch to next bytecode 00763 __ dispatch_epilog(tos_out, step); 00764 } 00765 #endif 00766 } 00767 #endif /* !CC_INTERP */ 00768 00769 00770 //------------------------------------------------------------------------------------------------------------------------ 00771 // Entry points 00772 00773 AbstractInterpreter::MethodKind AbstractInterpreter::method_kind(methodHandle m) { 00774 // Abstract method? 00775 if (m->is_abstract()) return abstract; 00776 00777 // Native method? 00778 // Note: This test must come _before_ the test for intrinsic 00779 // methods. See also comments below. 00780 if (m->is_native()) { 00781 return m->is_synchronized() ? native_synchronized : native; 00782 } 00783 00784 // Synchronized? 00785 if (m->is_synchronized()) { 00786 return zerolocals_synchronized; 00787 } 00788 00789 if (RegisterFinalizersAtInit && m->code_size() == 1 && 00790 m->intrinsic_id() == vmIntrinsics::_Object_init) { 00791 // We need to execute the special return bytecode to check for 00792 // finalizer registration so create a normal frame. 00793 return zerolocals; 00794 } 00795 00796 // Empty method? 00797 if (m->is_empty_method()) { 00798 return empty; 00799 } 00800 00801 // Accessor method? 00802 if (m->is_accessor()) { 00803 assert(m->size_of_parameters() == 1, "fast code for accessors assumes parameter size = 1"); 00804 return accessor; 00805 } 00806 00807 // Special intrinsic method? 00808 // Note: This test must come _after_ the test for native methods, 00809 // otherwise we will run into problems with JDK 1.2, see also 00810 // AbstractInterpreterGenerator::generate_method_entry() for 00811 // for details. 00812 switch (m->intrinsic_id()) { 00813 case vmIntrinsics::_dsin : return java_lang_math_sin ; 00814 case vmIntrinsics::_dcos : return java_lang_math_cos ; 00815 case vmIntrinsics::_dtan : return java_lang_math_tan ; 00816 case vmIntrinsics::_dabs : return java_lang_math_abs ; 00817 case vmIntrinsics::_dsqrt : return java_lang_math_sqrt ; 00818 case vmIntrinsics::_dlog : return java_lang_math_log ; 00819 case vmIntrinsics::_dlog10: return java_lang_math_log10; 00820 } 00821 00822 // Note: for now: zero locals for all non-empty methods 00823 return zerolocals; 00824 } 00825 00826 00827 // Return true if the interpreter can prove that the given bytecode has 00828 // not yet been executed (in Java semantics, not in actual operation). 00829 bool AbstractInterpreter::is_not_reached(methodHandle method, int bci) { 00830 address bcp = method->bcp_from(bci); 00831 00832 if (!Bytecode_at(bcp)->must_rewrite()) { 00833 // might have been reached 00834 return false; 00835 } 00836 00837 // the bytecode might not be rewritten if the method is an accessor, etc. 00838 address ientry = method->interpreter_entry(); 00839 if (ientry != entry_for_kind(AbstractInterpreter::zerolocals) && 00840 ientry != entry_for_kind(AbstractInterpreter::zerolocals_synchronized)) 00841 return false; // interpreter does not run this method! 00842 00843 // otherwise, we can be sure this bytecode has never been executed 00844 return true; 00845 } 00846 00847 00848 #ifndef PRODUCT 00849 void AbstractInterpreter::print_method_kind(MethodKind kind) { 00850 switch (kind) { 00851 case zerolocals : tty->print("zerolocals" ); break; 00852 case zerolocals_synchronized: tty->print("zerolocals_synchronized"); break; 00853 case native : tty->print("native" ); break; 00854 case native_synchronized : tty->print("native_synchronized" ); break; 00855 case empty : tty->print("empty" ); break; 00856 case accessor : tty->print("accessor" ); break; 00857 case abstract : tty->print("abstract" ); break; 00858 case java_lang_math_sin : tty->print("java_lang_math_sin" ); break; 00859 case java_lang_math_cos : tty->print("java_lang_math_cos" ); break; 00860 case java_lang_math_tan : tty->print("java_lang_math_tan" ); break; 00861 case java_lang_math_abs : tty->print("java_lang_math_abs" ); break; 00862 case java_lang_math_sqrt : tty->print("java_lang_math_sqrt" ); break; 00863 case java_lang_math_log : tty->print("java_lang_math_log" ); break; 00864 case java_lang_math_log10 : tty->print("java_lang_math_log10" ); break; 00865 default : ShouldNotReachHere(); 00866 } 00867 } 00868 #endif // PRODUCT 00869 00870 00871 #ifndef CC_INTERP 00872 address AbstractInterpreter::return_entry(TosState state, int length) { 00873 guarantee(0 <= length && length < Interpreter::number_of_return_entries, "illegal length"); 00874 return _return_entry[length].entry(state); 00875 } 00876 00877 00878 address AbstractInterpreter::deopt_entry(TosState state, int length) { 00879 guarantee(0 <= length && length < Interpreter::number_of_deopt_entries, "illegal length"); 00880 return _deopt_entry[length].entry(state); 00881 } 00882 00883 #endif /* CC_INTERP */ 00884 00885 static BasicType constant_pool_type(methodOop method, int index) { 00886 constantTag tag = method->constants()->tag_at(index); 00887 if (tag.is_int ()) return T_INT; 00888 else if (tag.is_float ()) return T_FLOAT; 00889 else if (tag.is_long ()) return T_LONG; 00890 else if (tag.is_double ()) return T_DOUBLE; 00891 else if (tag.is_string ()) return T_OBJECT; 00892 else if (tag.is_unresolved_string()) return T_OBJECT; 00893 else if (tag.is_klass ()) return T_OBJECT; 00894 else if (tag.is_unresolved_klass ()) return T_OBJECT; 00895 ShouldNotReachHere(); 00896 return T_ILLEGAL; 00897 } 00898 00899 00900 //------------------------------------------------------------------------------------------------------------------------ 00901 // Deoptimization support 00902 00903 // If deoptimization happens, this method returns the point where to continue in 00904 // interpreter. For calls (invokexxxx, newxxxx) the continuation is at next 00905 // bci and the top of stack is in eax/edx/FPU tos. 00906 // For putfield/getfield, put/getstatic, the continuation is at the same 00907 // bci and the TOS is on stack. 00908 00909 // Note: deopt_entry(type, 0) means reexecute bytecode 00910 // deopt_entry(type, length) means continue at next bytecode 00911 00912 address AbstractInterpreter::continuation_for(methodOop method, address bcp, int callee_parameters, bool is_top_frame, bool& use_next_mdp) { 00913 assert(method->contains(bcp), "just checkin'"); 00914 Bytecodes::Code code = Bytecodes::java_code_at(bcp); 00915 int bci = method->bci_from(bcp); 00916 int length = -1; // initial value for debugging 00917 // compute continuation length 00918 length = Bytecodes::length_at(bcp); 00919 // compute result type 00920 BasicType type = T_ILLEGAL; 00921 // when continuing after a compiler safepoint, re-execute the bytecode 00922 // (an invoke is continued after the safepoint) 00923 use_next_mdp = true; 00924 switch (code) { 00925 case Bytecodes::_lookupswitch: 00926 case Bytecodes::_tableswitch: 00927 case Bytecodes::_fast_binaryswitch: 00928 case Bytecodes::_fast_linearswitch: 00929 // recompute condtional expression folded into _if<cond> 00930 case Bytecodes::_lcmp : 00931 case Bytecodes::_fcmpl : 00932 case Bytecodes::_fcmpg : 00933 case Bytecodes::_dcmpl : 00934 case Bytecodes::_dcmpg : 00935 case Bytecodes::_ifnull : 00936 case Bytecodes::_ifnonnull : 00937 case Bytecodes::_goto : 00938 case Bytecodes::_goto_w : 00939 case Bytecodes::_ifeq : 00940 case Bytecodes::_ifne : 00941 case Bytecodes::_iflt : 00942 case Bytecodes::_ifge : 00943 case Bytecodes::_ifgt : 00944 case Bytecodes::_ifle : 00945 case Bytecodes::_if_icmpeq : 00946 case Bytecodes::_if_icmpne : 00947 case Bytecodes::_if_icmplt : 00948 case Bytecodes::_if_icmpge : 00949 case Bytecodes::_if_icmpgt : 00950 case Bytecodes::_if_icmple : 00951 case Bytecodes::_if_acmpeq : 00952 case Bytecodes::_if_acmpne : 00953 // special cases 00954 case Bytecodes::_getfield : 00955 case Bytecodes::_putfield : 00956 case Bytecodes::_getstatic : 00957 case Bytecodes::_putstatic : 00958 case Bytecodes::_aastore : 00959 // reexecute the operation and TOS value is on stack 00960 assert(is_top_frame, "must be top frame"); 00961 use_next_mdp = false; 00962 return deopt_entry(vtos, 0); 00963 break; 00964 00965 #ifdef COMPILER1 00966 case Bytecodes::_athrow : 00967 assert(is_top_frame, "must be top frame"); 00968 use_next_mdp = false; 00969 return Interpreter::rethrow_exception_entry(); 00970 break; 00971 #endif /* COMPILER1 */ 00972 00973 case Bytecodes::_invokevirtual : 00974 case Bytecodes::_invokespecial : 00975 case Bytecodes::_invokestatic : 00976 case Bytecodes::_invokeinterface: { 00977 Thread *thread = Thread::current(); 00978 ResourceMark rm(thread); 00979 methodHandle mh(thread, method); 00980 type = Bytecode_invoke_at(mh, bci)->result_type(thread); 00981 // since the cache entry might not be initialized: 00982 // (NOT needed for the old calling convension) 00983 if (!is_top_frame) { 00984 int index = Bytes::get_native_u2(bcp+1); 00985 method->constants()->cache()->entry_at(index)->set_parameter_size(callee_parameters); 00986 } 00987 break; 00988 } 00989 00990 case Bytecodes::_ldc : 00991 type = constant_pool_type( method, *(bcp+1) ); 00992 break; 00993 00994 case Bytecodes::_ldc_w : // fall through 00995 case Bytecodes::_ldc2_w: 00996 type = constant_pool_type( method, Bytes::get_Java_u2(bcp+1) ); 00997 break; 00998 00999 case Bytecodes::_return: { 01000 // This is used for deopt during registration of finalizers 01001 // during Object.<init>. We simply need to resume execution at 01002 // the standard return vtos bytecode to pop the frame normally. 01003 // reexecuting the real bytecode would cause double registration 01004 // of the finalizable object. 01005 #ifndef CC_INTERP 01006 assert(is_top_frame, "must be on top"); 01007 return _normal_table.entry(Bytecodes::_return).entry(vtos); 01008 #endif // CC_INTERP 01009 } 01010 01011 default: 01012 type = Bytecodes::result_type(code); 01013 break; 01014 } 01015 01016 // return entry point for computed continuation state & bytecode length 01017 return 01018 is_top_frame 01019 ? deopt_entry (as_TosState(type), length) 01020 : return_entry(as_TosState(type), length); 01021 } 01022 01023 01024 #ifndef CC_INTERP 01025 01026 //------------------------------------------------------------------------------------------------------------------------ 01027 // Suport for invokes 01028 01029 int AbstractInterpreter::TosState_as_index(TosState state) { 01030 assert( state < number_of_states , "Invalid state in TosState_as_index"); 01031 assert(0 <= (int)state && (int)state < AbstractInterpreter::number_of_return_addrs, "index out of bounds"); 01032 return (int)state; 01033 } 01034 01035 #endif // CC_INTERP 01036 01037 //------------------------------------------------------------------------------------------------------------------------ 01038 // Safepoint suppport 01039 01040 #ifndef CC_INTERP 01041 static inline void copy_table(address* from, address* to, int size) { 01042 // Copy non-overlapping tables. The copy has to occur word wise for MT safety. 01043 while (size-- > 0) *to++ = *from++; 01044 } 01045 #endif 01046 01047 void AbstractInterpreter::notice_safepoints() { 01048 if (!_notice_safepoints) { 01049 // switch to safepoint dispatch table 01050 _notice_safepoints = true; 01051 #ifndef CC_INTERP 01052 copy_table((address*)&_safept_table, (address*)&_active_table, sizeof(_active_table) / sizeof(address)); 01053 #endif 01054 } 01055 } 01056 01057 01058 // switch from the dispatch table which notices safepoints back to the 01059 // normal dispatch table. So that we can notice single stepping points, 01060 // keep the safepoint dispatch table if we are single stepping in JVMTI. 01061 // Note that the should_post_single_step test is exactly as fast as the 01062 // JvmtiExport::_enabled test and covers both cases. 01063 void AbstractInterpreter::ignore_safepoints() { 01064 if (_notice_safepoints) { 01065 if (!JvmtiExport::should_post_single_step()) { 01066 // switch to normal dispatch table 01067 _notice_safepoints = false; 01068 #ifndef CC_INTERP 01069 copy_table((address*)&_normal_table, (address*)&_active_table, sizeof(_active_table) / sizeof(address)); 01070 #endif 01071 } 01072 } 01073 } 01074 01075 void AbstractInterpreterGenerator::bang_stack_shadow_pages(bool native_call) { 01076 // Quick & dirty stack overflow checking: bang the stack & handle trap. 01077 // Note that we do the banging after the frame is setup, since the exception 01078 // handling code expects to find a valid interpreter frame on the stack. 01079 // Doing the banging earlier fails if the caller frame is not an interpreter 01080 // frame. 01081 // (Also, the exception throwing code expects to unlock any synchronized 01082 // method receiever, so do the banging after locking the receiver.) 01083 01084 // Bang each page in the shadow zone. We can't assume it's been done for 01085 // an interpreter frame with greater than a page of locals, so each page 01086 // needs to be checked. Only true for non-native. 01087 if (UseStackBanging) { 01088 const int start_page = native_call ? StackShadowPages : 1; 01089 const int page_size = os::vm_page_size(); 01090 for (int pages = start_page; pages <= StackShadowPages ; pages++) { 01091 __ bang_stack_with_offset(pages*page_size); 01092 } 01093 } 01094 }
