Print this page
Split |
Close |
Expand all |
Collapse all |
--- old/src/share/vm/interpreter/interpreterRuntime.cpp
+++ new/src/share/vm/interpreter/interpreterRuntime.cpp
1 1 /*
2 2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
3 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 4 *
5 5 * This code is free software; you can redistribute it and/or modify it
6 6 * under the terms of the GNU General Public License version 2 only, as
7 7 * published by the Free Software Foundation.
8 8 *
9 9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 12 * version 2 for more details (a copy is included in the LICENSE file that
13 13 * accompanied this code).
14 14 *
15 15 * You should have received a copy of the GNU General Public License version
16 16 * 2 along with this work; if not, write to the Free Software Foundation,
17 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 18 *
19 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 20 * or visit www.oracle.com if you need additional information or have any
21 21 * questions.
22 22 *
23 23 */
24 24
25 25 #include "precompiled.hpp"
26 26 #include "classfile/systemDictionary.hpp"
27 27 #include "classfile/vmSymbols.hpp"
28 28 #include "compiler/compileBroker.hpp"
29 29 #include "gc_interface/collectedHeap.hpp"
30 30 #include "interpreter/interpreter.hpp"
31 31 #include "interpreter/interpreterRuntime.hpp"
32 32 #include "interpreter/linkResolver.hpp"
33 33 #include "interpreter/templateTable.hpp"
34 34 #include "memory/oopFactory.hpp"
35 35 #include "memory/universe.inline.hpp"
36 36 #include "oops/constantPoolOop.hpp"
37 37 #include "oops/cpCacheOop.hpp"
38 38 #include "oops/instanceKlass.hpp"
39 39 #include "oops/methodDataOop.hpp"
40 40 #include "oops/objArrayKlass.hpp"
41 41 #include "oops/oop.inline.hpp"
42 42 #include "oops/symbol.hpp"
43 43 #include "prims/jvmtiExport.hpp"
44 44 #include "prims/nativeLookup.hpp"
45 45 #include "runtime/biasedLocking.hpp"
46 46 #include "runtime/compilationPolicy.hpp"
47 47 #include "runtime/deoptimization.hpp"
48 48 #include "runtime/fieldDescriptor.hpp"
49 49 #include "runtime/handles.inline.hpp"
50 50 #include "runtime/interfaceSupport.hpp"
51 51 #include "runtime/java.hpp"
52 52 #include "runtime/jfieldIDWorkaround.hpp"
53 53 #include "runtime/osThread.hpp"
54 54 #include "runtime/sharedRuntime.hpp"
55 55 #include "runtime/stubRoutines.hpp"
56 56 #include "runtime/synchronizer.hpp"
57 57 #include "runtime/threadCritical.hpp"
58 58 #include "utilities/events.hpp"
59 59 #ifdef TARGET_ARCH_x86
60 60 # include "vm_version_x86.hpp"
61 61 #endif
62 62 #ifdef TARGET_ARCH_sparc
63 63 # include "vm_version_sparc.hpp"
64 64 #endif
65 65 #ifdef TARGET_ARCH_zero
66 66 # include "vm_version_zero.hpp"
67 67 #endif
68 68 #ifdef TARGET_ARCH_arm
69 69 # include "vm_version_arm.hpp"
70 70 #endif
71 71 #ifdef TARGET_ARCH_ppc
72 72 # include "vm_version_ppc.hpp"
73 73 #endif
74 74 #ifdef COMPILER2
75 75 #include "opto/runtime.hpp"
76 76 #endif
77 77
78 78 class UnlockFlagSaver {
79 79 private:
80 80 JavaThread* _thread;
81 81 bool _do_not_unlock;
82 82 public:
83 83 UnlockFlagSaver(JavaThread* t) {
84 84 _thread = t;
85 85 _do_not_unlock = t->do_not_unlock_if_synchronized();
86 86 t->set_do_not_unlock_if_synchronized(false);
87 87 }
88 88 ~UnlockFlagSaver() {
89 89 _thread->set_do_not_unlock_if_synchronized(_do_not_unlock);
90 90 }
91 91 };
92 92
93 93 //------------------------------------------------------------------------------------------------------------------------
94 94 // State accessors
95 95
96 96 void InterpreterRuntime::set_bcp_and_mdp(address bcp, JavaThread *thread) {
97 97 last_frame(thread).interpreter_frame_set_bcp(bcp);
98 98 if (ProfileInterpreter) {
99 99 // ProfileTraps uses MDOs independently of ProfileInterpreter.
100 100 // That is why we must check both ProfileInterpreter and mdo != NULL.
101 101 methodDataOop mdo = last_frame(thread).interpreter_frame_method()->method_data();
102 102 if (mdo != NULL) {
103 103 NEEDS_CLEANUP;
104 104 last_frame(thread).interpreter_frame_set_mdp(mdo->bci_to_dp(last_frame(thread).interpreter_frame_bci()));
105 105 }
106 106 }
107 107 }
108 108
109 109 //------------------------------------------------------------------------------------------------------------------------
110 110 // Constants
111 111
112 112
113 113 IRT_ENTRY(void, InterpreterRuntime::ldc(JavaThread* thread, bool wide))
114 114 // access constant pool
115 115 constantPoolOop pool = method(thread)->constants();
116 116 int index = wide ? get_index_u2(thread, Bytecodes::_ldc_w) : get_index_u1(thread, Bytecodes::_ldc);
117 117 constantTag tag = pool->tag_at(index);
118 118
119 119 if (tag.is_unresolved_klass() || tag.is_klass()) {
120 120 klassOop klass = pool->klass_at(index, CHECK);
121 121 oop java_class = klass->java_mirror();
122 122 thread->set_vm_result(java_class);
123 123 } else {
124 124 #ifdef ASSERT
125 125 // If we entered this runtime routine, we believed the tag contained
126 126 // an unresolved string, an unresolved class or a resolved class.
127 127 // However, another thread could have resolved the unresolved string
128 128 // or class by the time we go there.
129 129 assert(tag.is_unresolved_string()|| tag.is_string(), "expected string");
130 130 #endif
131 131 oop s_oop = pool->string_at(index, CHECK);
132 132 thread->set_vm_result(s_oop);
133 133 }
134 134 IRT_END
135 135
136 136 IRT_ENTRY(void, InterpreterRuntime::resolve_ldc(JavaThread* thread, Bytecodes::Code bytecode)) {
137 137 assert(bytecode == Bytecodes::_fast_aldc ||
138 138 bytecode == Bytecodes::_fast_aldc_w, "wrong bc");
139 139 ResourceMark rm(thread);
140 140 methodHandle m (thread, method(thread));
141 141 Bytecode_loadconstant ldc(m, bci(thread));
142 142 oop result = ldc.resolve_constant(CHECK);
143 143 #ifdef ASSERT
144 144 {
145 145 // The bytecode wrappers aren't GC-safe so construct a new one
146 146 Bytecode_loadconstant ldc2(m, bci(thread));
147 147 ConstantPoolCacheEntry* cpce = m->constants()->cache()->entry_at(ldc2.cache_index());
148 148 assert(result == cpce->f1(), "expected result for assembly code");
149 149 }
150 150 #endif
151 151 }
152 152 IRT_END
153 153
154 154
155 155 //------------------------------------------------------------------------------------------------------------------------
156 156 // Allocation
157 157
158 158 IRT_ENTRY(void, InterpreterRuntime::_new(JavaThread* thread, constantPoolOopDesc* pool, int index))
159 159 klassOop k_oop = pool->klass_at(index, CHECK);
160 160 instanceKlassHandle klass (THREAD, k_oop);
161 161
162 162 // Make sure we are not instantiating an abstract klass
163 163 klass->check_valid_for_instantiation(true, CHECK);
164 164
165 165 // Make sure klass is initialized
166 166 klass->initialize(CHECK);
167 167
168 168 // At this point the class may not be fully initialized
169 169 // because of recursive initialization. If it is fully
170 170 // initialized & has_finalized is not set, we rewrite
171 171 // it into its fast version (Note: no locking is needed
172 172 // here since this is an atomic byte write and can be
173 173 // done more than once).
174 174 //
175 175 // Note: In case of classes with has_finalized we don't
176 176 // rewrite since that saves us an extra check in
177 177 // the fast version which then would call the
178 178 // slow version anyway (and do a call back into
179 179 // Java).
180 180 // If we have a breakpoint, then we don't rewrite
181 181 // because the _breakpoint bytecode would be lost.
182 182 oop obj = klass->allocate_instance(CHECK);
183 183 thread->set_vm_result(obj);
184 184 IRT_END
185 185
186 186
187 187 IRT_ENTRY(void, InterpreterRuntime::newarray(JavaThread* thread, BasicType type, jint size))
188 188 oop obj = oopFactory::new_typeArray(type, size, CHECK);
189 189 thread->set_vm_result(obj);
190 190 IRT_END
191 191
192 192
193 193 IRT_ENTRY(void, InterpreterRuntime::anewarray(JavaThread* thread, constantPoolOopDesc* pool, int index, jint size))
194 194 // Note: no oopHandle for pool & klass needed since they are not used
195 195 // anymore after new_objArray() and no GC can happen before.
196 196 // (This may have to change if this code changes!)
197 197 klassOop klass = pool->klass_at(index, CHECK);
198 198 objArrayOop obj = oopFactory::new_objArray(klass, size, CHECK);
199 199 thread->set_vm_result(obj);
200 200 IRT_END
201 201
202 202
203 203 IRT_ENTRY(void, InterpreterRuntime::multianewarray(JavaThread* thread, jint* first_size_address))
204 204 // We may want to pass in more arguments - could make this slightly faster
205 205 constantPoolOop constants = method(thread)->constants();
206 206 int i = get_index_u2(thread, Bytecodes::_multianewarray);
207 207 klassOop klass = constants->klass_at(i, CHECK);
208 208 int nof_dims = number_of_dimensions(thread);
209 209 assert(oop(klass)->is_klass(), "not a class");
210 210 assert(nof_dims >= 1, "multianewarray rank must be nonzero");
211 211
212 212 // We must create an array of jints to pass to multi_allocate.
213 213 ResourceMark rm(thread);
214 214 const int small_dims = 10;
215 215 jint dim_array[small_dims];
216 216 jint *dims = &dim_array[0];
217 217 if (nof_dims > small_dims) {
218 218 dims = (jint*) NEW_RESOURCE_ARRAY(jint, nof_dims);
219 219 }
220 220 for (int index = 0; index < nof_dims; index++) {
221 221 // offset from first_size_address is addressed as local[index]
222 222 int n = Interpreter::local_offset_in_bytes(index)/jintSize;
223 223 dims[index] = first_size_address[n];
224 224 }
225 225 oop obj = arrayKlass::cast(klass)->multi_allocate(nof_dims, dims, CHECK);
226 226 thread->set_vm_result(obj);
227 227 IRT_END
228 228
229 229
230 230 IRT_ENTRY(void, InterpreterRuntime::register_finalizer(JavaThread* thread, oopDesc* obj))
231 231 assert(obj->is_oop(), "must be a valid oop");
232 232 assert(obj->klass()->klass_part()->has_finalizer(), "shouldn't be here otherwise");
233 233 instanceKlass::register_finalizer(instanceOop(obj), CHECK);
234 234 IRT_END
235 235
236 236
237 237 // Quicken instance-of and check-cast bytecodes
238 238 IRT_ENTRY(void, InterpreterRuntime::quicken_io_cc(JavaThread* thread))
239 239 // Force resolving; quicken the bytecode
240 240 int which = get_index_u2(thread, Bytecodes::_checkcast);
241 241 constantPoolOop cpool = method(thread)->constants();
242 242 // We'd expect to assert that we're only here to quicken bytecodes, but in a multithreaded
243 243 // program we might have seen an unquick'd bytecode in the interpreter but have another
244 244 // thread quicken the bytecode before we get here.
245 245 // assert( cpool->tag_at(which).is_unresolved_klass(), "should only come here to quicken bytecodes" );
246 246 klassOop klass = cpool->klass_at(which, CHECK);
247 247 thread->set_vm_result(klass);
248 248 IRT_END
249 249
250 250
251 251 //------------------------------------------------------------------------------------------------------------------------
252 252 // Exceptions
253 253
254 254 // Assume the compiler is (or will be) interested in this event.
255 255 // If necessary, create an MDO to hold the information, and record it.
256 256 void InterpreterRuntime::note_trap(JavaThread* thread, int reason, TRAPS) {
257 257 assert(ProfileTraps, "call me only if profiling");
258 258 methodHandle trap_method(thread, method(thread));
259 259
260 260 if (trap_method.not_null()) {
261 261 methodDataHandle trap_mdo(thread, trap_method->method_data());
262 262 if (trap_mdo.is_null()) {
263 263 methodOopDesc::build_interpreter_method_data(trap_method, THREAD);
264 264 if (HAS_PENDING_EXCEPTION) {
265 265 assert((PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())), "we expect only an OOM error here");
266 266 CLEAR_PENDING_EXCEPTION;
267 267 }
268 268 trap_mdo = methodDataHandle(thread, trap_method->method_data());
269 269 // and fall through...
270 270 }
271 271 if (trap_mdo.not_null()) {
272 272 // Update per-method count of trap events. The interpreter
273 273 // is updating the MDO to simulate the effect of compiler traps.
274 274 int trap_bci = trap_method->bci_from(bcp(thread));
275 275 Deoptimization::update_method_data_from_interpreter(trap_mdo, trap_bci, reason);
276 276 }
277 277 }
278 278 }
279 279
280 280 static Handle get_preinitialized_exception(klassOop k, TRAPS) {
281 281 // get klass
282 282 instanceKlass* klass = instanceKlass::cast(k);
283 283 assert(klass->is_initialized(),
284 284 "this klass should have been initialized during VM initialization");
285 285 // create instance - do not call constructor since we may have no
286 286 // (java) stack space left (should assert constructor is empty)
287 287 Handle exception;
288 288 oop exception_oop = klass->allocate_instance(CHECK_(exception));
289 289 exception = Handle(THREAD, exception_oop);
290 290 if (StackTraceInThrowable) {
291 291 java_lang_Throwable::fill_in_stack_trace(exception);
292 292 }
293 293 return exception;
294 294 }
295 295
296 296 // Special handling for stack overflow: since we don't have any (java) stack
297 297 // space left we use the pre-allocated & pre-initialized StackOverflowError
298 298 // klass to create an stack overflow error instance. We do not call its
299 299 // constructor for the same reason (it is empty, anyway).
300 300 IRT_ENTRY(void, InterpreterRuntime::throw_StackOverflowError(JavaThread* thread))
301 301 Handle exception = get_preinitialized_exception(
302 302 SystemDictionary::StackOverflowError_klass(),
303 303 CHECK);
304 304 THROW_HANDLE(exception);
305 305 IRT_END
306 306
307 307
308 308 IRT_ENTRY(void, InterpreterRuntime::create_exception(JavaThread* thread, char* name, char* message))
309 309 // lookup exception klass
310 310 TempNewSymbol s = SymbolTable::new_symbol(name, CHECK);
311 311 if (ProfileTraps) {
312 312 if (s == vmSymbols::java_lang_ArithmeticException()) {
313 313 note_trap(thread, Deoptimization::Reason_div0_check, CHECK);
314 314 } else if (s == vmSymbols::java_lang_NullPointerException()) {
315 315 note_trap(thread, Deoptimization::Reason_null_check, CHECK);
316 316 }
317 317 }
318 318 // create exception
319 319 Handle exception = Exceptions::new_exception(thread, s, message);
320 320 thread->set_vm_result(exception());
321 321 IRT_END
322 322
323 323
324 324 IRT_ENTRY(void, InterpreterRuntime::create_klass_exception(JavaThread* thread, char* name, oopDesc* obj))
325 325 ResourceMark rm(thread);
326 326 const char* klass_name = Klass::cast(obj->klass())->external_name();
327 327 // lookup exception klass
328 328 TempNewSymbol s = SymbolTable::new_symbol(name, CHECK);
329 329 if (ProfileTraps) {
330 330 note_trap(thread, Deoptimization::Reason_class_check, CHECK);
331 331 }
332 332 // create exception, with klass name as detail message
333 333 Handle exception = Exceptions::new_exception(thread, s, klass_name);
334 334 thread->set_vm_result(exception());
335 335 IRT_END
336 336
337 337
338 338 IRT_ENTRY(void, InterpreterRuntime::throw_ArrayIndexOutOfBoundsException(JavaThread* thread, char* name, jint index))
339 339 char message[jintAsStringSize];
340 340 // lookup exception klass
341 341 TempNewSymbol s = SymbolTable::new_symbol(name, CHECK);
342 342 if (ProfileTraps) {
343 343 note_trap(thread, Deoptimization::Reason_range_check, CHECK);
344 344 }
345 345 // create exception
346 346 sprintf(message, "%d", index);
347 347 THROW_MSG(s, message);
348 348 IRT_END
349 349
350 350 IRT_ENTRY(void, InterpreterRuntime::throw_ClassCastException(
351 351 JavaThread* thread, oopDesc* obj))
352 352
353 353 ResourceMark rm(thread);
354 354 char* message = SharedRuntime::generate_class_cast_message(
355 355 thread, Klass::cast(obj->klass())->external_name());
356 356
357 357 if (ProfileTraps) {
358 358 note_trap(thread, Deoptimization::Reason_class_check, CHECK);
359 359 }
360 360
361 361 // create exception
362 362 THROW_MSG(vmSymbols::java_lang_ClassCastException(), message);
363 363 IRT_END
364 364
365 365 // exception_handler_for_exception(...) returns the continuation address,
366 366 // the exception oop (via TLS) and sets the bci/bcp for the continuation.
367 367 // The exception oop is returned to make sure it is preserved over GC (it
368 368 // is only on the stack if the exception was thrown explicitly via athrow).
369 369 // During this operation, the expression stack contains the values for the
370 370 // bci where the exception happened. If the exception was propagated back
371 371 // from a call, the expression stack contains the values for the bci at the
372 372 // invoke w/o arguments (i.e., as if one were inside the call).
373 373 IRT_ENTRY(address, InterpreterRuntime::exception_handler_for_exception(JavaThread* thread, oopDesc* exception))
374 374
375 375 Handle h_exception(thread, exception);
376 376 methodHandle h_method (thread, method(thread));
377 377 constantPoolHandle h_constants(thread, h_method->constants());
378 378 typeArrayHandle h_extable (thread, h_method->exception_table());
379 379 bool should_repeat;
380 380 int handler_bci;
381 381 int current_bci = bci(thread);
382 382
383 383 // Need to do this check first since when _do_not_unlock_if_synchronized
384 384 // is set, we don't want to trigger any classloading which may make calls
385 385 // into java, or surprisingly find a matching exception handler for bci 0
386 386 // since at this moment the method hasn't been "officially" entered yet.
387 387 if (thread->do_not_unlock_if_synchronized()) {
388 388 ResourceMark rm;
389 389 assert(current_bci == 0, "bci isn't zero for do_not_unlock_if_synchronized");
390 390 thread->set_vm_result(exception);
391 391 #ifdef CC_INTERP
392 392 return (address) -1;
393 393 #else
394 394 return Interpreter::remove_activation_entry();
395 395 #endif
396 396 }
397 397
398 398 do {
399 399 should_repeat = false;
400 400
401 401 // assertions
402 402 #ifdef ASSERT
403 403 assert(h_exception.not_null(), "NULL exceptions should be handled by athrow");
404 404 assert(h_exception->is_oop(), "just checking");
405 405 // Check that exception is a subclass of Throwable, otherwise we have a VerifyError
406 406 if (!(h_exception->is_a(SystemDictionary::Throwable_klass()))) {
407 407 if (ExitVMOnVerifyError) vm_exit(-1);
408 408 ShouldNotReachHere();
409 409 }
410 410 #endif
411 411
412 412 // tracing
413 413 if (TraceExceptions) {
414 414 ttyLocker ttyl;
415 415 ResourceMark rm(thread);
416 416 tty->print_cr("Exception <%s> (" INTPTR_FORMAT ")", h_exception->print_value_string(), (address)h_exception());
417 417 tty->print_cr(" thrown in interpreter method <%s>", h_method->print_value_string());
418 418 tty->print_cr(" at bci %d for thread " INTPTR_FORMAT, current_bci, thread);
419 419 }
420 420 // Don't go paging in something which won't be used.
421 421 // else if (h_extable->length() == 0) {
422 422 // // disabled for now - interpreter is not using shortcut yet
423 423 // // (shortcut is not to call runtime if we have no exception handlers)
424 424 // // warning("performance bug: should not call runtime if method has no exception handlers");
425 425 // }
426 426 // for AbortVMOnException flag
427 427 NOT_PRODUCT(Exceptions::debug_check_abort(h_exception));
428 428
429 429 // exception handler lookup
430 430 KlassHandle h_klass(THREAD, h_exception->klass());
431 431 handler_bci = h_method->fast_exception_handler_bci_for(h_klass, current_bci, THREAD);
432 432 if (HAS_PENDING_EXCEPTION) {
433 433 // We threw an exception while trying to find the exception handler.
434 434 // Transfer the new exception to the exception handle which will
435 435 // be set into thread local storage, and do another lookup for an
436 436 // exception handler for this exception, this time starting at the
437 437 // BCI of the exception handler which caused the exception to be
438 438 // thrown (bug 4307310).
439 439 h_exception = Handle(THREAD, PENDING_EXCEPTION);
440 440 CLEAR_PENDING_EXCEPTION;
441 441 if (handler_bci >= 0) {
442 442 current_bci = handler_bci;
443 443 should_repeat = true;
444 444 }
445 445 }
446 446 } while (should_repeat == true);
447 447
448 448 // notify JVMTI of an exception throw; JVMTI will detect if this is a first
449 449 // time throw or a stack unwinding throw and accordingly notify the debugger
450 450 if (JvmtiExport::can_post_on_exceptions()) {
451 451 JvmtiExport::post_exception_throw(thread, h_method(), bcp(thread), h_exception());
452 452 }
453 453
454 454 #ifdef CC_INTERP
455 455 address continuation = (address)(intptr_t) handler_bci;
456 456 #else
457 457 address continuation = NULL;
458 458 #endif
459 459 address handler_pc = NULL;
460 460 if (handler_bci < 0 || !thread->reguard_stack((address) &continuation)) {
461 461 // Forward exception to callee (leaving bci/bcp untouched) because (a) no
462 462 // handler in this method, or (b) after a stack overflow there is not yet
463 463 // enough stack space available to reprotect the stack.
464 464 #ifndef CC_INTERP
465 465 continuation = Interpreter::remove_activation_entry();
466 466 #endif
467 467 // Count this for compilation purposes
468 468 h_method->interpreter_throwout_increment();
469 469 } else {
470 470 // handler in this method => change bci/bcp to handler bci/bcp and continue there
471 471 handler_pc = h_method->code_base() + handler_bci;
472 472 #ifndef CC_INTERP
473 473 set_bcp_and_mdp(handler_pc, thread);
474 474 continuation = Interpreter::dispatch_table(vtos)[*handler_pc];
475 475 #endif
476 476 }
477 477 // notify debugger of an exception catch
478 478 // (this is good for exceptions caught in native methods as well)
479 479 if (JvmtiExport::can_post_on_exceptions()) {
480 480 JvmtiExport::notice_unwind_due_to_exception(thread, h_method(), handler_pc, h_exception(), (handler_pc != NULL));
481 481 }
482 482
483 483 thread->set_vm_result(h_exception());
484 484 return continuation;
485 485 IRT_END
486 486
487 487
488 488 IRT_ENTRY(void, InterpreterRuntime::throw_pending_exception(JavaThread* thread))
489 489 assert(thread->has_pending_exception(), "must only ne called if there's an exception pending");
490 490 // nothing to do - eventually we should remove this code entirely (see comments @ call sites)
491 491 IRT_END
492 492
493 493
494 494 IRT_ENTRY(void, InterpreterRuntime::throw_AbstractMethodError(JavaThread* thread))
495 495 THROW(vmSymbols::java_lang_AbstractMethodError());
496 496 IRT_END
497 497
498 498
499 499 IRT_ENTRY(void, InterpreterRuntime::throw_IncompatibleClassChangeError(JavaThread* thread))
500 500 THROW(vmSymbols::java_lang_IncompatibleClassChangeError());
501 501 IRT_END
↓ open down ↓ |
501 lines elided |
↑ open up ↑ |
502 502
503 503
504 504 //------------------------------------------------------------------------------------------------------------------------
505 505 // Fields
506 506 //
507 507
508 508 IRT_ENTRY(void, InterpreterRuntime::resolve_get_put(JavaThread* thread, Bytecodes::Code bytecode))
509 509 // resolve field
510 510 FieldAccessInfo info;
511 511 constantPoolHandle pool(thread, method(thread)->constants());
512 + bool is_put = (bytecode == Bytecodes::_putfield || bytecode == Bytecodes::_putstatic);
512 513 bool is_static = (bytecode == Bytecodes::_getstatic || bytecode == Bytecodes::_putstatic);
513 514
514 515 {
515 516 JvmtiHideSingleStepping jhss(thread);
516 517 LinkResolver::resolve_field(info, pool, get_index_u2_cpcache(thread, bytecode),
517 518 bytecode, false, CHECK);
518 519 } // end JvmtiHideSingleStepping
519 520
520 521 // check if link resolution caused cpCache to be updated
521 522 if (already_resolved(thread)) return;
522 523
523 524 // compute auxiliary field attributes
524 525 TosState state = as_TosState(info.field_type());
525 526
526 527 // We need to delay resolving put instructions on final fields
527 528 // until we actually invoke one. This is required so we throw
528 529 // exceptions at the correct place. If we do not resolve completely
529 530 // in the current pass, leaving the put_code set to zero will
530 531 // cause the next put instruction to reresolve.
531 - bool is_put = (bytecode == Bytecodes::_putfield ||
532 - bytecode == Bytecodes::_putstatic);
533 532 Bytecodes::Code put_code = (Bytecodes::Code)0;
534 533
535 534 // We also need to delay resolving getstatic instructions until the
536 535 // class is intitialized. This is required so that access to the static
537 536 // field will call the initialization function every time until the class
538 537 // is completely initialized ala. in 2.17.5 in JVM Specification.
539 538 instanceKlass *klass = instanceKlass::cast(info.klass()->as_klassOop());
540 539 bool uninitialized_static = ((bytecode == Bytecodes::_getstatic || bytecode == Bytecodes::_putstatic) &&
541 540 !klass->is_initialized());
542 541 Bytecodes::Code get_code = (Bytecodes::Code)0;
543 542
544 -
545 543 if (!uninitialized_static) {
546 544 get_code = ((is_static) ? Bytecodes::_getstatic : Bytecodes::_getfield);
547 545 if (is_put || !info.access_flags().is_final()) {
548 546 put_code = ((is_static) ? Bytecodes::_putstatic : Bytecodes::_putfield);
549 547 }
550 548 }
551 549
550 + if (is_put && !is_static && klass->is_subclass_of(SystemDictionary::CallSite_klass()) && (info.name() == vmSymbols::target_name())) {
551 + const jint direction = frame::interpreter_frame_expression_stack_direction();
552 + oop call_site = *((oop*) thread->last_frame().interpreter_frame_tos_at(-1 * direction));
553 + oop method_handle = *((oop*) thread->last_frame().interpreter_frame_tos_at( 0 * direction));
554 + assert(call_site ->is_a(SystemDictionary::CallSite_klass()), "must be");
555 + assert(method_handle->is_a(SystemDictionary::MethodHandle_klass()), "must be");
556 +
557 + {
558 + // Walk all nmethods depending on CallSite
559 + MutexLocker mu(Compile_lock, thread);
560 + Universe::flush_dependents_on(call_site, method_handle);
561 + }
562 +
563 + // Don't allow fast path for setting CallSite.target and sub-classes.
564 + put_code = (Bytecodes::Code) 0;
565 + }
566 +
552 567 cache_entry(thread)->set_field(
553 568 get_code,
554 569 put_code,
555 570 info.klass(),
556 571 info.field_index(),
557 572 info.field_offset(),
558 573 state,
559 574 info.access_flags().is_final(),
560 575 info.access_flags().is_volatile()
561 576 );
562 577 IRT_END
563 578
564 579
565 580 //------------------------------------------------------------------------------------------------------------------------
566 581 // Synchronization
567 582 //
568 583 // The interpreter's synchronization code is factored out so that it can
569 584 // be shared by method invocation and synchronized blocks.
570 585 //%note synchronization_3
571 586
572 587 static void trace_locking(Handle& h_locking_obj, bool is_locking) {
573 588 ObjectSynchronizer::trace_locking(h_locking_obj, false, true, is_locking);
574 589 }
575 590
576 591
577 592 //%note monitor_1
578 593 IRT_ENTRY_NO_ASYNC(void, InterpreterRuntime::monitorenter(JavaThread* thread, BasicObjectLock* elem))
579 594 #ifdef ASSERT
580 595 thread->last_frame().interpreter_frame_verify_monitor(elem);
581 596 #endif
582 597 if (PrintBiasedLockingStatistics) {
583 598 Atomic::inc(BiasedLocking::slow_path_entry_count_addr());
584 599 }
585 600 Handle h_obj(thread, elem->obj());
586 601 assert(Universe::heap()->is_in_reserved_or_null(h_obj()),
587 602 "must be NULL or an object");
588 603 if (UseBiasedLocking) {
589 604 // Retry fast entry if bias is revoked to avoid unnecessary inflation
590 605 ObjectSynchronizer::fast_enter(h_obj, elem->lock(), true, CHECK);
591 606 } else {
592 607 ObjectSynchronizer::slow_enter(h_obj, elem->lock(), CHECK);
593 608 }
594 609 assert(Universe::heap()->is_in_reserved_or_null(elem->obj()),
595 610 "must be NULL or an object");
596 611 #ifdef ASSERT
597 612 thread->last_frame().interpreter_frame_verify_monitor(elem);
598 613 #endif
599 614 IRT_END
600 615
601 616
602 617 //%note monitor_1
603 618 IRT_ENTRY_NO_ASYNC(void, InterpreterRuntime::monitorexit(JavaThread* thread, BasicObjectLock* elem))
604 619 #ifdef ASSERT
605 620 thread->last_frame().interpreter_frame_verify_monitor(elem);
606 621 #endif
607 622 Handle h_obj(thread, elem->obj());
608 623 assert(Universe::heap()->is_in_reserved_or_null(h_obj()),
609 624 "must be NULL or an object");
610 625 if (elem == NULL || h_obj()->is_unlocked()) {
611 626 THROW(vmSymbols::java_lang_IllegalMonitorStateException());
612 627 }
613 628 ObjectSynchronizer::slow_exit(h_obj(), elem->lock(), thread);
614 629 // Free entry. This must be done here, since a pending exception might be installed on
615 630 // exit. If it is not cleared, the exception handling code will try to unlock the monitor again.
616 631 elem->set_obj(NULL);
617 632 #ifdef ASSERT
618 633 thread->last_frame().interpreter_frame_verify_monitor(elem);
619 634 #endif
620 635 IRT_END
621 636
622 637
623 638 IRT_ENTRY(void, InterpreterRuntime::throw_illegal_monitor_state_exception(JavaThread* thread))
624 639 THROW(vmSymbols::java_lang_IllegalMonitorStateException());
625 640 IRT_END
626 641
627 642
628 643 IRT_ENTRY(void, InterpreterRuntime::new_illegal_monitor_state_exception(JavaThread* thread))
629 644 // Returns an illegal exception to install into the current thread. The
630 645 // pending_exception flag is cleared so normal exception handling does not
631 646 // trigger. Any current installed exception will be overwritten. This
632 647 // method will be called during an exception unwind.
633 648
634 649 assert(!HAS_PENDING_EXCEPTION, "no pending exception");
635 650 Handle exception(thread, thread->vm_result());
636 651 assert(exception() != NULL, "vm result should be set");
637 652 thread->set_vm_result(NULL); // clear vm result before continuing (may cause memory leaks and assert failures)
638 653 if (!exception->is_a(SystemDictionary::ThreadDeath_klass())) {
639 654 exception = get_preinitialized_exception(
640 655 SystemDictionary::IllegalMonitorStateException_klass(),
641 656 CATCH);
642 657 }
643 658 thread->set_vm_result(exception());
644 659 IRT_END
645 660
646 661
647 662 //------------------------------------------------------------------------------------------------------------------------
648 663 // Invokes
649 664
650 665 IRT_ENTRY(Bytecodes::Code, InterpreterRuntime::get_original_bytecode_at(JavaThread* thread, methodOopDesc* method, address bcp))
651 666 return method->orig_bytecode_at(method->bci_from(bcp));
652 667 IRT_END
653 668
654 669 IRT_ENTRY(void, InterpreterRuntime::set_original_bytecode_at(JavaThread* thread, methodOopDesc* method, address bcp, Bytecodes::Code new_code))
655 670 method->set_orig_bytecode_at(method->bci_from(bcp), new_code);
656 671 IRT_END
657 672
658 673 IRT_ENTRY(void, InterpreterRuntime::_breakpoint(JavaThread* thread, methodOopDesc* method, address bcp))
659 674 JvmtiExport::post_raw_breakpoint(thread, method, bcp);
660 675 IRT_END
661 676
662 677 IRT_ENTRY(void, InterpreterRuntime::resolve_invoke(JavaThread* thread, Bytecodes::Code bytecode))
663 678 // extract receiver from the outgoing argument list if necessary
664 679 Handle receiver(thread, NULL);
665 680 if (bytecode == Bytecodes::_invokevirtual || bytecode == Bytecodes::_invokeinterface) {
666 681 ResourceMark rm(thread);
667 682 methodHandle m (thread, method(thread));
668 683 Bytecode_invoke call(m, bci(thread));
669 684 Symbol* signature = call.signature();
670 685 receiver = Handle(thread,
671 686 thread->last_frame().interpreter_callee_receiver(signature));
672 687 assert(Universe::heap()->is_in_reserved_or_null(receiver()),
673 688 "sanity check");
674 689 assert(receiver.is_null() ||
675 690 Universe::heap()->is_in_reserved(receiver->klass()),
676 691 "sanity check");
677 692 }
678 693
679 694 // resolve method
680 695 CallInfo info;
681 696 constantPoolHandle pool(thread, method(thread)->constants());
682 697
683 698 {
684 699 JvmtiHideSingleStepping jhss(thread);
685 700 LinkResolver::resolve_invoke(info, receiver, pool,
686 701 get_index_u2_cpcache(thread, bytecode), bytecode, CHECK);
687 702 if (JvmtiExport::can_hotswap_or_post_breakpoint()) {
688 703 int retry_count = 0;
689 704 while (info.resolved_method()->is_old()) {
690 705 // It is very unlikely that method is redefined more than 100 times
691 706 // in the middle of resolve. If it is looping here more than 100 times
692 707 // means then there could be a bug here.
693 708 guarantee((retry_count++ < 100),
694 709 "Could not resolve to latest version of redefined method");
695 710 // method is redefined in the middle of resolve so re-try.
696 711 LinkResolver::resolve_invoke(info, receiver, pool,
697 712 get_index_u2_cpcache(thread, bytecode), bytecode, CHECK);
698 713 }
699 714 }
700 715 } // end JvmtiHideSingleStepping
701 716
702 717 // check if link resolution caused cpCache to be updated
703 718 if (already_resolved(thread)) return;
704 719
705 720 if (bytecode == Bytecodes::_invokeinterface) {
706 721
707 722 if (TraceItables && Verbose) {
708 723 ResourceMark rm(thread);
709 724 tty->print_cr("Resolving: klass: %s to method: %s", info.resolved_klass()->name()->as_C_string(), info.resolved_method()->name()->as_C_string());
710 725 }
711 726 if (info.resolved_method()->method_holder() ==
712 727 SystemDictionary::Object_klass()) {
713 728 // NOTE: THIS IS A FIX FOR A CORNER CASE in the JVM spec
714 729 // (see also cpCacheOop.cpp for details)
715 730 methodHandle rm = info.resolved_method();
716 731 assert(rm->is_final() || info.has_vtable_index(),
717 732 "should have been set already");
718 733 cache_entry(thread)->set_method(bytecode, rm, info.vtable_index());
719 734 } else {
720 735 // Setup itable entry
721 736 int index = klassItable::compute_itable_index(info.resolved_method()());
722 737 cache_entry(thread)->set_interface_call(info.resolved_method(), index);
723 738 }
724 739 } else {
725 740 cache_entry(thread)->set_method(
726 741 bytecode,
727 742 info.resolved_method(),
728 743 info.vtable_index());
729 744 }
730 745 IRT_END
731 746
732 747
733 748 // First time execution: Resolve symbols, create a permanent CallSite object.
734 749 IRT_ENTRY(void, InterpreterRuntime::resolve_invokedynamic(JavaThread* thread)) {
735 750 ResourceMark rm(thread);
736 751
737 752 assert(EnableInvokeDynamic, "");
738 753
739 754 const Bytecodes::Code bytecode = Bytecodes::_invokedynamic;
740 755
741 756 methodHandle caller_method(thread, method(thread));
742 757
743 758 constantPoolHandle pool(thread, caller_method->constants());
744 759 pool->set_invokedynamic(); // mark header to flag active call sites
745 760
746 761 int caller_bci = 0;
747 762 int site_index = 0;
748 763 { address caller_bcp = bcp(thread);
749 764 caller_bci = caller_method->bci_from(caller_bcp);
750 765 site_index = Bytes::get_native_u4(caller_bcp+1);
751 766 }
752 767 assert(site_index == InterpreterRuntime::bytecode(thread).get_index_u4(bytecode), "");
753 768 assert(constantPoolCacheOopDesc::is_secondary_index(site_index), "proper format");
754 769 // there is a second CPC entries that is of interest; it caches signature info:
755 770 int main_index = pool->cache()->secondary_entry_at(site_index)->main_entry_index();
756 771 int pool_index = pool->cache()->entry_at(main_index)->constant_pool_index();
757 772
758 773 // first resolve the signature to a MH.invoke methodOop
759 774 if (!pool->cache()->entry_at(main_index)->is_resolved(bytecode)) {
760 775 JvmtiHideSingleStepping jhss(thread);
761 776 CallInfo callinfo;
762 777 LinkResolver::resolve_invoke(callinfo, Handle(), pool,
763 778 site_index, bytecode, CHECK);
764 779 // The main entry corresponds to a JVM_CONSTANT_InvokeDynamic, and serves
765 780 // as a common reference point for all invokedynamic call sites with
766 781 // that exact call descriptor. We will link it in the CP cache exactly
767 782 // as if it were an invokevirtual of MethodHandle.invoke.
768 783 pool->cache()->entry_at(main_index)->set_method(
769 784 bytecode,
770 785 callinfo.resolved_method(),
771 786 callinfo.vtable_index());
772 787 }
773 788
774 789 // The method (f2 entry) of the main entry is the MH.invoke for the
775 790 // invokedynamic target call signature.
776 791 oop f1_value = pool->cache()->entry_at(main_index)->f1();
777 792 methodHandle signature_invoker(THREAD, (methodOop) f1_value);
778 793 assert(signature_invoker.not_null() && signature_invoker->is_method() && signature_invoker->is_method_handle_invoke(),
779 794 "correct result from LinkResolver::resolve_invokedynamic");
780 795
781 796 Handle info; // optional argument(s) in JVM_CONSTANT_InvokeDynamic
782 797 Handle bootm = SystemDictionary::find_bootstrap_method(caller_method, caller_bci,
783 798 main_index, info, CHECK);
784 799 if (!java_lang_invoke_MethodHandle::is_instance(bootm())) {
785 800 THROW_MSG(vmSymbols::java_lang_IllegalStateException(),
786 801 "no bootstrap method found for invokedynamic");
787 802 }
788 803
789 804 // Short circuit if CallSite has been bound already:
790 805 if (!pool->cache()->secondary_entry_at(site_index)->is_f1_null())
791 806 return;
792 807
793 808 Symbol* call_site_name = pool->name_ref_at(site_index);
794 809
795 810 Handle call_site
796 811 = SystemDictionary::make_dynamic_call_site(bootm,
797 812 // Callee information:
798 813 call_site_name,
799 814 signature_invoker,
800 815 info,
801 816 // Caller information:
802 817 caller_method,
803 818 caller_bci,
804 819 CHECK);
805 820
806 821 // In the secondary entry, the f1 field is the call site, and the f2 (index)
807 822 // field is some data about the invoke site. Currently, it is just the BCI.
808 823 // Later, it might be changed to help manage inlining dependencies.
809 824 pool->cache()->secondary_entry_at(site_index)->set_dynamic_call(call_site, signature_invoker);
810 825 }
811 826 IRT_END
812 827
813 828
814 829 //------------------------------------------------------------------------------------------------------------------------
815 830 // Miscellaneous
816 831
817 832
818 833 nmethod* InterpreterRuntime::frequency_counter_overflow(JavaThread* thread, address branch_bcp) {
819 834 nmethod* nm = frequency_counter_overflow_inner(thread, branch_bcp);
820 835 assert(branch_bcp != NULL || nm == NULL, "always returns null for non OSR requests");
821 836 if (branch_bcp != NULL && nm != NULL) {
822 837 // This was a successful request for an OSR nmethod. Because
823 838 // frequency_counter_overflow_inner ends with a safepoint check,
824 839 // nm could have been unloaded so look it up again. It's unsafe
825 840 // to examine nm directly since it might have been freed and used
826 841 // for something else.
827 842 frame fr = thread->last_frame();
828 843 methodOop method = fr.interpreter_frame_method();
829 844 int bci = method->bci_from(fr.interpreter_frame_bcp());
830 845 nm = method->lookup_osr_nmethod_for(bci, CompLevel_none, false);
831 846 }
832 847 return nm;
833 848 }
834 849
835 850 IRT_ENTRY(nmethod*,
836 851 InterpreterRuntime::frequency_counter_overflow_inner(JavaThread* thread, address branch_bcp))
837 852 // use UnlockFlagSaver to clear and restore the _do_not_unlock_if_synchronized
838 853 // flag, in case this method triggers classloading which will call into Java.
839 854 UnlockFlagSaver fs(thread);
840 855
841 856 frame fr = thread->last_frame();
842 857 assert(fr.is_interpreted_frame(), "must come from interpreter");
843 858 methodHandle method(thread, fr.interpreter_frame_method());
844 859 const int branch_bci = branch_bcp != NULL ? method->bci_from(branch_bcp) : InvocationEntryBci;
845 860 const int bci = branch_bcp != NULL ? method->bci_from(fr.interpreter_frame_bcp()) : InvocationEntryBci;
846 861
847 862 nmethod* osr_nm = CompilationPolicy::policy()->event(method, method, branch_bci, bci, CompLevel_none, NULL, thread);
848 863
849 864 if (osr_nm != NULL) {
850 865 // We may need to do on-stack replacement which requires that no
851 866 // monitors in the activation are biased because their
852 867 // BasicObjectLocks will need to migrate during OSR. Force
853 868 // unbiasing of all monitors in the activation now (even though
854 869 // the OSR nmethod might be invalidated) because we don't have a
855 870 // safepoint opportunity later once the migration begins.
856 871 if (UseBiasedLocking) {
857 872 ResourceMark rm;
858 873 GrowableArray<Handle>* objects_to_revoke = new GrowableArray<Handle>();
859 874 for( BasicObjectLock *kptr = fr.interpreter_frame_monitor_end();
860 875 kptr < fr.interpreter_frame_monitor_begin();
861 876 kptr = fr.next_monitor_in_interpreter_frame(kptr) ) {
862 877 if( kptr->obj() != NULL ) {
863 878 objects_to_revoke->append(Handle(THREAD, kptr->obj()));
864 879 }
865 880 }
866 881 BiasedLocking::revoke(objects_to_revoke);
867 882 }
868 883 }
869 884 return osr_nm;
870 885 IRT_END
871 886
872 887 IRT_LEAF(jint, InterpreterRuntime::bcp_to_di(methodOopDesc* method, address cur_bcp))
873 888 assert(ProfileInterpreter, "must be profiling interpreter");
874 889 int bci = method->bci_from(cur_bcp);
875 890 methodDataOop mdo = method->method_data();
876 891 if (mdo == NULL) return 0;
877 892 return mdo->bci_to_di(bci);
878 893 IRT_END
879 894
880 895 IRT_ENTRY(void, InterpreterRuntime::profile_method(JavaThread* thread))
881 896 // use UnlockFlagSaver to clear and restore the _do_not_unlock_if_synchronized
882 897 // flag, in case this method triggers classloading which will call into Java.
883 898 UnlockFlagSaver fs(thread);
884 899
885 900 assert(ProfileInterpreter, "must be profiling interpreter");
886 901 frame fr = thread->last_frame();
887 902 assert(fr.is_interpreted_frame(), "must come from interpreter");
888 903 methodHandle method(thread, fr.interpreter_frame_method());
889 904 methodOopDesc::build_interpreter_method_data(method, THREAD);
890 905 if (HAS_PENDING_EXCEPTION) {
891 906 assert((PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())), "we expect only an OOM error here");
892 907 CLEAR_PENDING_EXCEPTION;
893 908 // and fall through...
894 909 }
895 910 IRT_END
896 911
897 912
898 913 #ifdef ASSERT
899 914 IRT_LEAF(void, InterpreterRuntime::verify_mdp(methodOopDesc* method, address bcp, address mdp))
900 915 assert(ProfileInterpreter, "must be profiling interpreter");
901 916
902 917 methodDataOop mdo = method->method_data();
903 918 assert(mdo != NULL, "must not be null");
904 919
905 920 int bci = method->bci_from(bcp);
906 921
907 922 address mdp2 = mdo->bci_to_dp(bci);
908 923 if (mdp != mdp2) {
909 924 ResourceMark rm;
910 925 ResetNoHandleMark rnm; // In a LEAF entry.
911 926 HandleMark hm;
912 927 tty->print_cr("FAILED verify : actual mdp %p expected mdp %p @ bci %d", mdp, mdp2, bci);
913 928 int current_di = mdo->dp_to_di(mdp);
914 929 int expected_di = mdo->dp_to_di(mdp2);
915 930 tty->print_cr(" actual di %d expected di %d", current_di, expected_di);
916 931 int expected_approx_bci = mdo->data_at(expected_di)->bci();
917 932 int approx_bci = -1;
918 933 if (current_di >= 0) {
919 934 approx_bci = mdo->data_at(current_di)->bci();
920 935 }
921 936 tty->print_cr(" actual bci is %d expected bci %d", approx_bci, expected_approx_bci);
922 937 mdo->print_on(tty);
923 938 method->print_codes();
924 939 }
925 940 assert(mdp == mdp2, "wrong mdp");
926 941 IRT_END
927 942 #endif // ASSERT
928 943
929 944 IRT_ENTRY(void, InterpreterRuntime::update_mdp_for_ret(JavaThread* thread, int return_bci))
930 945 assert(ProfileInterpreter, "must be profiling interpreter");
931 946 ResourceMark rm(thread);
932 947 HandleMark hm(thread);
933 948 frame fr = thread->last_frame();
934 949 assert(fr.is_interpreted_frame(), "must come from interpreter");
935 950 methodDataHandle h_mdo(thread, fr.interpreter_frame_method()->method_data());
936 951
937 952 // Grab a lock to ensure atomic access to setting the return bci and
938 953 // the displacement. This can block and GC, invalidating all naked oops.
939 954 MutexLocker ml(RetData_lock);
940 955
941 956 // ProfileData is essentially a wrapper around a derived oop, so we
942 957 // need to take the lock before making any ProfileData structures.
943 958 ProfileData* data = h_mdo->data_at(h_mdo->dp_to_di(fr.interpreter_frame_mdp()));
944 959 RetData* rdata = data->as_RetData();
945 960 address new_mdp = rdata->fixup_ret(return_bci, h_mdo);
946 961 fr.interpreter_frame_set_mdp(new_mdp);
947 962 IRT_END
948 963
949 964
950 965 IRT_ENTRY(void, InterpreterRuntime::at_safepoint(JavaThread* thread))
951 966 // We used to need an explict preserve_arguments here for invoke bytecodes. However,
952 967 // stack traversal automatically takes care of preserving arguments for invoke, so
953 968 // this is no longer needed.
954 969
955 970 // IRT_END does an implicit safepoint check, hence we are guaranteed to block
956 971 // if this is called during a safepoint
957 972
958 973 if (JvmtiExport::should_post_single_step()) {
959 974 // We are called during regular safepoints and when the VM is
960 975 // single stepping. If any thread is marked for single stepping,
961 976 // then we may have JVMTI work to do.
962 977 JvmtiExport::at_single_stepping_point(thread, method(thread), bcp(thread));
963 978 }
964 979 IRT_END
965 980
966 981 IRT_ENTRY(void, InterpreterRuntime::post_field_access(JavaThread *thread, oopDesc* obj,
967 982 ConstantPoolCacheEntry *cp_entry))
968 983
969 984 // check the access_flags for the field in the klass
970 985
971 986 instanceKlass* ik = instanceKlass::cast(java_lang_Class::as_klassOop(cp_entry->f1()));
972 987 typeArrayOop fields = ik->fields();
973 988 int index = cp_entry->field_index();
974 989 assert(index < fields->length(), "holders field index is out of range");
975 990 // bail out if field accesses are not watched
976 991 if ((fields->ushort_at(index) & JVM_ACC_FIELD_ACCESS_WATCHED) == 0) return;
977 992
978 993 switch(cp_entry->flag_state()) {
979 994 case btos: // fall through
980 995 case ctos: // fall through
981 996 case stos: // fall through
982 997 case itos: // fall through
983 998 case ftos: // fall through
984 999 case ltos: // fall through
985 1000 case dtos: // fall through
986 1001 case atos: break;
987 1002 default: ShouldNotReachHere(); return;
988 1003 }
989 1004 bool is_static = (obj == NULL);
990 1005 HandleMark hm(thread);
991 1006
992 1007 Handle h_obj;
993 1008 if (!is_static) {
994 1009 // non-static field accessors have an object, but we need a handle
995 1010 h_obj = Handle(thread, obj);
996 1011 }
997 1012 instanceKlassHandle h_cp_entry_f1(thread, java_lang_Class::as_klassOop(cp_entry->f1()));
998 1013 jfieldID fid = jfieldIDWorkaround::to_jfieldID(h_cp_entry_f1, cp_entry->f2(), is_static);
999 1014 JvmtiExport::post_field_access(thread, method(thread), bcp(thread), h_cp_entry_f1, h_obj, fid);
1000 1015 IRT_END
1001 1016
1002 1017 IRT_ENTRY(void, InterpreterRuntime::post_field_modification(JavaThread *thread,
1003 1018 oopDesc* obj, ConstantPoolCacheEntry *cp_entry, jvalue *value))
1004 1019
1005 1020 klassOop k = java_lang_Class::as_klassOop(cp_entry->f1());
1006 1021
1007 1022 // check the access_flags for the field in the klass
1008 1023 instanceKlass* ik = instanceKlass::cast(k);
1009 1024 typeArrayOop fields = ik->fields();
1010 1025 int index = cp_entry->field_index();
1011 1026 assert(index < fields->length(), "holders field index is out of range");
1012 1027 // bail out if field modifications are not watched
1013 1028 if ((fields->ushort_at(index) & JVM_ACC_FIELD_MODIFICATION_WATCHED) == 0) return;
1014 1029
1015 1030 char sig_type = '\0';
1016 1031
1017 1032 switch(cp_entry->flag_state()) {
1018 1033 case btos: sig_type = 'Z'; break;
1019 1034 case ctos: sig_type = 'C'; break;
1020 1035 case stos: sig_type = 'S'; break;
1021 1036 case itos: sig_type = 'I'; break;
1022 1037 case ftos: sig_type = 'F'; break;
1023 1038 case atos: sig_type = 'L'; break;
1024 1039 case ltos: sig_type = 'J'; break;
1025 1040 case dtos: sig_type = 'D'; break;
1026 1041 default: ShouldNotReachHere(); return;
1027 1042 }
1028 1043 bool is_static = (obj == NULL);
1029 1044
1030 1045 HandleMark hm(thread);
1031 1046 instanceKlassHandle h_klass(thread, k);
1032 1047 jfieldID fid = jfieldIDWorkaround::to_jfieldID(h_klass, cp_entry->f2(), is_static);
1033 1048 jvalue fvalue;
1034 1049 #ifdef _LP64
1035 1050 fvalue = *value;
1036 1051 #else
1037 1052 // Long/double values are stored unaligned and also noncontiguously with
1038 1053 // tagged stacks. We can't just do a simple assignment even in the non-
1039 1054 // J/D cases because a C++ compiler is allowed to assume that a jvalue is
1040 1055 // 8-byte aligned, and interpreter stack slots are only 4-byte aligned.
1041 1056 // We assume that the two halves of longs/doubles are stored in interpreter
1042 1057 // stack slots in platform-endian order.
1043 1058 jlong_accessor u;
1044 1059 jint* newval = (jint*)value;
1045 1060 u.words[0] = newval[0];
1046 1061 u.words[1] = newval[Interpreter::stackElementWords]; // skip if tag
1047 1062 fvalue.j = u.long_value;
1048 1063 #endif // _LP64
1049 1064
1050 1065 Handle h_obj;
1051 1066 if (!is_static) {
1052 1067 // non-static field accessors have an object, but we need a handle
1053 1068 h_obj = Handle(thread, obj);
1054 1069 }
1055 1070
1056 1071 JvmtiExport::post_raw_field_modification(thread, method(thread), bcp(thread), h_klass, h_obj,
1057 1072 fid, sig_type, &fvalue);
1058 1073 IRT_END
1059 1074
1060 1075 IRT_ENTRY(void, InterpreterRuntime::post_method_entry(JavaThread *thread))
1061 1076 JvmtiExport::post_method_entry(thread, InterpreterRuntime::method(thread), InterpreterRuntime::last_frame(thread));
1062 1077 IRT_END
1063 1078
1064 1079
1065 1080 IRT_ENTRY(void, InterpreterRuntime::post_method_exit(JavaThread *thread))
1066 1081 JvmtiExport::post_method_exit(thread, InterpreterRuntime::method(thread), InterpreterRuntime::last_frame(thread));
1067 1082 IRT_END
1068 1083
1069 1084 IRT_LEAF(int, InterpreterRuntime::interpreter_contains(address pc))
1070 1085 {
1071 1086 return (Interpreter::contains(pc) ? 1 : 0);
1072 1087 }
1073 1088 IRT_END
1074 1089
1075 1090
1076 1091 // Implementation of SignatureHandlerLibrary
1077 1092
1078 1093 address SignatureHandlerLibrary::set_handler_blob() {
1079 1094 BufferBlob* handler_blob = BufferBlob::create("native signature handlers", blob_size);
1080 1095 if (handler_blob == NULL) {
1081 1096 return NULL;
1082 1097 }
1083 1098 address handler = handler_blob->code_begin();
1084 1099 _handler_blob = handler_blob;
1085 1100 _handler = handler;
1086 1101 return handler;
1087 1102 }
1088 1103
1089 1104 void SignatureHandlerLibrary::initialize() {
1090 1105 if (_fingerprints != NULL) {
1091 1106 return;
1092 1107 }
1093 1108 if (set_handler_blob() == NULL) {
1094 1109 vm_exit_out_of_memory(blob_size, "native signature handlers");
1095 1110 }
1096 1111
1097 1112 BufferBlob* bb = BufferBlob::create("Signature Handler Temp Buffer",
1098 1113 SignatureHandlerLibrary::buffer_size);
1099 1114 _buffer = bb->code_begin();
1100 1115
1101 1116 _fingerprints = new(ResourceObj::C_HEAP)GrowableArray<uint64_t>(32, true);
1102 1117 _handlers = new(ResourceObj::C_HEAP)GrowableArray<address>(32, true);
1103 1118 }
1104 1119
1105 1120 address SignatureHandlerLibrary::set_handler(CodeBuffer* buffer) {
1106 1121 address handler = _handler;
1107 1122 int insts_size = buffer->pure_insts_size();
1108 1123 if (handler + insts_size > _handler_blob->code_end()) {
1109 1124 // get a new handler blob
1110 1125 handler = set_handler_blob();
1111 1126 }
1112 1127 if (handler != NULL) {
1113 1128 memcpy(handler, buffer->insts_begin(), insts_size);
1114 1129 pd_set_handler(handler);
1115 1130 ICache::invalidate_range(handler, insts_size);
1116 1131 _handler = handler + insts_size;
1117 1132 }
1118 1133 return handler;
1119 1134 }
1120 1135
1121 1136 void SignatureHandlerLibrary::add(methodHandle method) {
1122 1137 if (method->signature_handler() == NULL) {
1123 1138 // use slow signature handler if we can't do better
1124 1139 int handler_index = -1;
1125 1140 // check if we can use customized (fast) signature handler
1126 1141 if (UseFastSignatureHandlers && method->size_of_parameters() <= Fingerprinter::max_size_of_parameters) {
1127 1142 // use customized signature handler
1128 1143 MutexLocker mu(SignatureHandlerLibrary_lock);
1129 1144 // make sure data structure is initialized
1130 1145 initialize();
1131 1146 // lookup method signature's fingerprint
1132 1147 uint64_t fingerprint = Fingerprinter(method).fingerprint();
1133 1148 handler_index = _fingerprints->find(fingerprint);
1134 1149 // create handler if necessary
1135 1150 if (handler_index < 0) {
1136 1151 ResourceMark rm;
1137 1152 ptrdiff_t align_offset = (address)
1138 1153 round_to((intptr_t)_buffer, CodeEntryAlignment) - (address)_buffer;
1139 1154 CodeBuffer buffer((address)(_buffer + align_offset),
1140 1155 SignatureHandlerLibrary::buffer_size - align_offset);
1141 1156 InterpreterRuntime::SignatureHandlerGenerator(method, &buffer).generate(fingerprint);
1142 1157 // copy into code heap
1143 1158 address handler = set_handler(&buffer);
1144 1159 if (handler == NULL) {
1145 1160 // use slow signature handler
1146 1161 } else {
1147 1162 // debugging suppport
1148 1163 if (PrintSignatureHandlers) {
1149 1164 tty->cr();
1150 1165 tty->print_cr("argument handler #%d for: %s %s (fingerprint = " UINT64_FORMAT ", %d bytes generated)",
1151 1166 _handlers->length(),
1152 1167 (method->is_static() ? "static" : "receiver"),
1153 1168 method->name_and_sig_as_C_string(),
1154 1169 fingerprint,
1155 1170 buffer.insts_size());
1156 1171 Disassembler::decode(handler, handler + buffer.insts_size());
1157 1172 #ifndef PRODUCT
1158 1173 tty->print_cr(" --- associated result handler ---");
1159 1174 address rh_begin = Interpreter::result_handler(method()->result_type());
1160 1175 address rh_end = rh_begin;
1161 1176 while (*(int*)rh_end != 0) {
1162 1177 rh_end += sizeof(int);
1163 1178 }
1164 1179 Disassembler::decode(rh_begin, rh_end);
1165 1180 #endif
1166 1181 }
1167 1182 // add handler to library
1168 1183 _fingerprints->append(fingerprint);
1169 1184 _handlers->append(handler);
1170 1185 // set handler index
1171 1186 assert(_fingerprints->length() == _handlers->length(), "sanity check");
1172 1187 handler_index = _fingerprints->length() - 1;
1173 1188 }
1174 1189 }
1175 1190 // Set handler under SignatureHandlerLibrary_lock
1176 1191 if (handler_index < 0) {
1177 1192 // use generic signature handler
1178 1193 method->set_signature_handler(Interpreter::slow_signature_handler());
1179 1194 } else {
1180 1195 // set handler
1181 1196 method->set_signature_handler(_handlers->at(handler_index));
1182 1197 }
1183 1198 } else {
1184 1199 CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops());
1185 1200 // use generic signature handler
1186 1201 method->set_signature_handler(Interpreter::slow_signature_handler());
1187 1202 }
1188 1203 }
1189 1204 #ifdef ASSERT
1190 1205 int handler_index = -1;
1191 1206 int fingerprint_index = -2;
1192 1207 {
1193 1208 // '_handlers' and '_fingerprints' are 'GrowableArray's and are NOT synchronized
1194 1209 // in any way if accessed from multiple threads. To avoid races with another
1195 1210 // thread which may change the arrays in the above, mutex protected block, we
1196 1211 // have to protect this read access here with the same mutex as well!
1197 1212 MutexLocker mu(SignatureHandlerLibrary_lock);
1198 1213 if (_handlers != NULL) {
1199 1214 handler_index = _handlers->find(method->signature_handler());
1200 1215 fingerprint_index = _fingerprints->find(Fingerprinter(method).fingerprint());
1201 1216 }
1202 1217 }
1203 1218 assert(method->signature_handler() == Interpreter::slow_signature_handler() ||
1204 1219 handler_index == fingerprint_index, "sanity check");
1205 1220 #endif // ASSERT
1206 1221 }
1207 1222
1208 1223
1209 1224 BufferBlob* SignatureHandlerLibrary::_handler_blob = NULL;
1210 1225 address SignatureHandlerLibrary::_handler = NULL;
1211 1226 GrowableArray<uint64_t>* SignatureHandlerLibrary::_fingerprints = NULL;
1212 1227 GrowableArray<address>* SignatureHandlerLibrary::_handlers = NULL;
1213 1228 address SignatureHandlerLibrary::_buffer = NULL;
1214 1229
1215 1230
1216 1231 IRT_ENTRY(void, InterpreterRuntime::prepare_native_call(JavaThread* thread, methodOopDesc* method))
1217 1232 methodHandle m(thread, method);
1218 1233 assert(m->is_native(), "sanity check");
1219 1234 // lookup native function entry point if it doesn't exist
1220 1235 bool in_base_library;
1221 1236 if (!m->has_native_function()) {
1222 1237 NativeLookup::lookup(m, in_base_library, CHECK);
1223 1238 }
1224 1239 // make sure signature handler is installed
1225 1240 SignatureHandlerLibrary::add(m);
1226 1241 // The interpreter entry point checks the signature handler first,
1227 1242 // before trying to fetch the native entry point and klass mirror.
1228 1243 // We must set the signature handler last, so that multiple processors
1229 1244 // preparing the same method will be sure to see non-null entry & mirror.
1230 1245 IRT_END
1231 1246
1232 1247 #if defined(IA32) || defined(AMD64)
1233 1248 IRT_LEAF(void, InterpreterRuntime::popframe_move_outgoing_args(JavaThread* thread, void* src_address, void* dest_address))
1234 1249 if (src_address == dest_address) {
1235 1250 return;
1236 1251 }
1237 1252 ResetNoHandleMark rnm; // In a LEAF entry.
1238 1253 HandleMark hm;
1239 1254 ResourceMark rm;
1240 1255 frame fr = thread->last_frame();
1241 1256 assert(fr.is_interpreted_frame(), "");
1242 1257 jint bci = fr.interpreter_frame_bci();
1243 1258 methodHandle mh(thread, fr.interpreter_frame_method());
1244 1259 Bytecode_invoke invoke(mh, bci);
1245 1260 ArgumentSizeComputer asc(invoke.signature());
1246 1261 int size_of_arguments = (asc.size() + (invoke.has_receiver() ? 1 : 0)); // receiver
1247 1262 Copy::conjoint_jbytes(src_address, dest_address,
1248 1263 size_of_arguments * Interpreter::stackElementSize);
1249 1264 IRT_END
1250 1265 #endif
↓ open down ↓ |
689 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX