Mercurial > hg > truffle
annotate src/cpu/zero/vm/cppInterpreter_zero.cpp @ 1325:98ba8ca25feb
6936168: Recent fix for unmapping stack guard pages doesn't close /proc/self/maps
Summary: Add close to returns (fix for 6929067 also contributed by aph)
Reviewed-by: aph, dcubed, andrew, acorn
Contributed-by: aph@redhat.com, andreas.kohn@fredhopper.com
author | coleenp |
---|---|
date | Thu, 18 Mar 2010 16:47:37 -0400 |
parents | c09ee209b65c |
children | 747d26efc5fa |
rev | line source |
---|---|
1010 | 1 /* |
2 * Copyright 2003-2007 Sun Microsystems, Inc. All Rights Reserved. | |
1256 | 3 * Copyright 2007, 2008, 2009, 2010 Red Hat, Inc. |
1010 | 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
5 * | |
6 * This code is free software; you can redistribute it and/or modify it | |
7 * under the terms of the GNU General Public License version 2 only, as | |
8 * published by the Free Software Foundation. | |
9 * | |
10 * This code is distributed in the hope that it will be useful, but WITHOUT | |
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
13 * version 2 for more details (a copy is included in the LICENSE file that | |
14 * accompanied this code). | |
15 * | |
16 * You should have received a copy of the GNU General Public License version | |
17 * 2 along with this work; if not, write to the Free Software Foundation, | |
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
19 * | |
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
21 * CA 95054 USA or visit www.sun.com if you need additional information or | |
22 * have any questions. | |
23 * | |
24 */ | |
25 | |
26 #include "incls/_precompiled.incl" | |
27 #include "incls/_cppInterpreter_zero.cpp.incl" | |
28 | |
29 #ifdef CC_INTERP | |
30 | |
31 #define fixup_after_potential_safepoint() \ | |
32 method = istate->method() | |
33 | |
34 #define CALL_VM_NOCHECK(func) \ | |
35 thread->set_last_Java_frame(); \ | |
36 func; \ | |
37 thread->reset_last_Java_frame(); \ | |
38 fixup_after_potential_safepoint() | |
39 | |
40 void CppInterpreter::normal_entry(methodOop method, intptr_t UNUSED, TRAPS) { | |
41 JavaThread *thread = (JavaThread *) THREAD; | |
42 ZeroStack *stack = thread->zero_stack(); | |
43 | |
44 // Adjust the caller's stack frame to accomodate any additional | |
45 // local variables we have contiguously with our parameters. | |
46 int extra_locals = method->max_locals() - method->size_of_parameters(); | |
47 if (extra_locals > 0) { | |
48 if (extra_locals > stack->available_words()) { | |
49 Unimplemented(); | |
50 } | |
51 for (int i = 0; i < extra_locals; i++) | |
52 stack->push(0); | |
53 } | |
54 | |
55 // Allocate and initialize our frame. | |
56 InterpreterFrame *frame = InterpreterFrame::build(stack, method, thread); | |
57 thread->push_zero_frame(frame); | |
58 | |
59 // Execute those bytecodes! | |
60 main_loop(0, THREAD); | |
61 } | |
62 | |
63 void CppInterpreter::main_loop(int recurse, TRAPS) { | |
64 JavaThread *thread = (JavaThread *) THREAD; | |
65 ZeroStack *stack = thread->zero_stack(); | |
66 | |
67 // If we are entering from a deopt we may need to call | |
68 // ourself a few times in order to get to our frame. | |
69 if (recurse) | |
70 main_loop(recurse - 1, THREAD); | |
71 | |
72 InterpreterFrame *frame = thread->top_zero_frame()->as_interpreter_frame(); | |
73 interpreterState istate = frame->interpreter_state(); | |
74 methodOop method = istate->method(); | |
75 | |
76 intptr_t *result = NULL; | |
77 int result_slots = 0; | |
78 | |
79 // Check we're not about to run out of stack | |
80 if (stack_overflow_imminent(thread)) { | |
81 CALL_VM_NOCHECK(InterpreterRuntime::throw_StackOverflowError(thread)); | |
82 goto unwind_and_return; | |
83 } | |
84 | |
85 while (true) { | |
86 // We can set up the frame anchor with everything we want at | |
87 // this point as we are thread_in_Java and no safepoints can | |
88 // occur until we go to vm mode. We do have to clear flags | |
89 // on return from vm but that is it. | |
90 thread->set_last_Java_frame(); | |
91 | |
92 // Call the interpreter | |
93 if (JvmtiExport::can_post_interpreter_events()) | |
94 BytecodeInterpreter::runWithChecks(istate); | |
95 else | |
96 BytecodeInterpreter::run(istate); | |
97 fixup_after_potential_safepoint(); | |
98 | |
99 // Clear the frame anchor | |
100 thread->reset_last_Java_frame(); | |
101 | |
102 // Examine the message from the interpreter to decide what to do | |
103 if (istate->msg() == BytecodeInterpreter::call_method) { | |
104 methodOop callee = istate->callee(); | |
105 | |
106 // Trim back the stack to put the parameters at the top | |
107 stack->set_sp(istate->stack() + 1); | |
108 | |
109 // Make the call | |
110 Interpreter::invoke_method(callee, istate->callee_entry_point(), THREAD); | |
111 fixup_after_potential_safepoint(); | |
112 | |
113 // Convert the result | |
114 istate->set_stack(stack->sp() - 1); | |
115 | |
116 // Restore the stack | |
117 stack->set_sp(istate->stack_limit() + 1); | |
118 | |
119 // Resume the interpreter | |
120 istate->set_msg(BytecodeInterpreter::method_resume); | |
121 } | |
122 else if (istate->msg() == BytecodeInterpreter::more_monitors) { | |
123 int monitor_words = frame::interpreter_frame_monitor_size(); | |
124 | |
125 // Allocate the space | |
126 if (monitor_words > stack->available_words()) { | |
127 Unimplemented(); | |
128 } | |
129 stack->alloc(monitor_words * wordSize); | |
130 | |
131 // Move the expression stack contents | |
132 for (intptr_t *p = istate->stack() + 1; p < istate->stack_base(); p++) | |
133 *(p - monitor_words) = *p; | |
134 | |
135 // Move the expression stack pointers | |
136 istate->set_stack_limit(istate->stack_limit() - monitor_words); | |
137 istate->set_stack(istate->stack() - monitor_words); | |
138 istate->set_stack_base(istate->stack_base() - monitor_words); | |
139 | |
140 // Zero the new monitor so the interpreter can find it. | |
141 ((BasicObjectLock *) istate->stack_base())->set_obj(NULL); | |
142 | |
143 // Resume the interpreter | |
144 istate->set_msg(BytecodeInterpreter::got_monitors); | |
145 } | |
146 else if (istate->msg() == BytecodeInterpreter::return_from_method) { | |
147 // Copy the result into the caller's frame | |
1256 | 148 result_slots = type2size[result_type_of(method)]; |
1010 | 149 assert(result_slots >= 0 && result_slots <= 2, "what?"); |
150 result = istate->stack() + result_slots; | |
151 break; | |
152 } | |
153 else if (istate->msg() == BytecodeInterpreter::throwing_exception) { | |
154 assert(HAS_PENDING_EXCEPTION, "should do"); | |
155 break; | |
156 } | |
157 else if (istate->msg() == BytecodeInterpreter::do_osr) { | |
158 // Unwind the current frame | |
159 thread->pop_zero_frame(); | |
160 | |
161 // Remove any extension of the previous frame | |
162 int extra_locals = method->max_locals() - method->size_of_parameters(); | |
163 stack->set_sp(stack->sp() + extra_locals); | |
164 | |
165 // Jump into the OSR method | |
166 Interpreter::invoke_osr( | |
167 method, istate->osr_entry(), istate->osr_buf(), THREAD); | |
168 return; | |
169 } | |
170 else { | |
171 ShouldNotReachHere(); | |
172 } | |
173 } | |
174 | |
175 unwind_and_return: | |
176 | |
177 // Unwind the current frame | |
178 thread->pop_zero_frame(); | |
179 | |
180 // Pop our local variables | |
181 stack->set_sp(stack->sp() + method->max_locals()); | |
182 | |
183 // Push our result | |
184 for (int i = 0; i < result_slots; i++) | |
185 stack->push(result[-i]); | |
186 } | |
187 | |
188 void CppInterpreter::native_entry(methodOop method, intptr_t UNUSED, TRAPS) { | |
189 // Make sure method is native and not abstract | |
190 assert(method->is_native() && !method->is_abstract(), "should be"); | |
191 | |
192 JavaThread *thread = (JavaThread *) THREAD; | |
193 ZeroStack *stack = thread->zero_stack(); | |
194 | |
195 // Allocate and initialize our frame | |
196 InterpreterFrame *frame = InterpreterFrame::build(stack, method, thread); | |
197 thread->push_zero_frame(frame); | |
198 interpreterState istate = frame->interpreter_state(); | |
199 intptr_t *locals = istate->locals(); | |
200 | |
201 // Check we're not about to run out of stack | |
202 if (stack_overflow_imminent(thread)) { | |
203 CALL_VM_NOCHECK(InterpreterRuntime::throw_StackOverflowError(thread)); | |
204 goto unwind_and_return; | |
205 } | |
206 | |
1078 | 207 // Update the invocation counter |
208 if ((UseCompiler || CountCompiledCalls) && !method->is_synchronized()) { | |
209 thread->set_do_not_unlock(); | |
210 InvocationCounter *counter = method->invocation_counter(); | |
211 counter->increment(); | |
212 if (counter->reached_InvocationLimit()) { | |
213 CALL_VM_NOCHECK( | |
214 InterpreterRuntime::frequency_counter_overflow(thread, NULL)); | |
215 if (HAS_PENDING_EXCEPTION) | |
216 goto unwind_and_return; | |
217 } | |
218 thread->clr_do_not_unlock(); | |
219 } | |
220 | |
1010 | 221 // Lock if necessary |
222 BasicObjectLock *monitor; | |
223 monitor = NULL; | |
224 if (method->is_synchronized()) { | |
225 monitor = (BasicObjectLock*) istate->stack_base(); | |
226 oop lockee = monitor->obj(); | |
227 markOop disp = lockee->mark()->set_unlocked(); | |
228 | |
229 monitor->lock()->set_displaced_header(disp); | |
230 if (Atomic::cmpxchg_ptr(monitor, lockee->mark_addr(), disp) != disp) { | |
231 if (thread->is_lock_owned((address) disp->clear_lock_bits())) { | |
232 monitor->lock()->set_displaced_header(NULL); | |
233 } | |
234 else { | |
235 CALL_VM_NOCHECK(InterpreterRuntime::monitorenter(thread, monitor)); | |
236 if (HAS_PENDING_EXCEPTION) | |
237 goto unwind_and_return; | |
238 } | |
239 } | |
240 } | |
241 | |
242 // Get the signature handler | |
243 InterpreterRuntime::SignatureHandler *handler; { | |
244 address handlerAddr = method->signature_handler(); | |
245 if (handlerAddr == NULL) { | |
246 CALL_VM_NOCHECK(InterpreterRuntime::prepare_native_call(thread, method)); | |
247 if (HAS_PENDING_EXCEPTION) | |
1139
b6f06e395428
6908267: Zero fails to unlock synchronized native methods on exception
never
parents:
1078
diff
changeset
|
248 goto unlock_unwind_and_return; |
1010 | 249 |
250 handlerAddr = method->signature_handler(); | |
251 assert(handlerAddr != NULL, "eh?"); | |
252 } | |
253 if (handlerAddr == (address) InterpreterRuntime::slow_signature_handler) { | |
254 CALL_VM_NOCHECK(handlerAddr = | |
255 InterpreterRuntime::slow_signature_handler(thread, method, NULL,NULL)); | |
256 if (HAS_PENDING_EXCEPTION) | |
1139
b6f06e395428
6908267: Zero fails to unlock synchronized native methods on exception
never
parents:
1078
diff
changeset
|
257 goto unlock_unwind_and_return; |
1010 | 258 } |
259 handler = \ | |
260 InterpreterRuntime::SignatureHandler::from_handlerAddr(handlerAddr); | |
261 } | |
262 | |
263 // Get the native function entry point | |
264 address function; | |
265 function = method->native_function(); | |
266 assert(function != NULL, "should be set if signature handler is"); | |
267 | |
268 // Build the argument list | |
269 if (handler->argument_count() * 2 > stack->available_words()) { | |
270 Unimplemented(); | |
271 } | |
272 void **arguments; | |
273 void *mirror; { | |
274 arguments = | |
275 (void **) stack->alloc(handler->argument_count() * sizeof(void **)); | |
276 void **dst = arguments; | |
277 | |
278 void *env = thread->jni_environment(); | |
279 *(dst++) = &env; | |
280 | |
281 if (method->is_static()) { | |
282 istate->set_oop_temp( | |
283 method->constants()->pool_holder()->klass_part()->java_mirror()); | |
284 mirror = istate->oop_temp_addr(); | |
285 *(dst++) = &mirror; | |
286 } | |
287 | |
288 intptr_t *src = locals; | |
289 for (int i = dst - arguments; i < handler->argument_count(); i++) { | |
290 ffi_type *type = handler->argument_type(i); | |
291 if (type == &ffi_type_pointer) { | |
292 if (*src) { | |
293 stack->push((intptr_t) src); | |
294 *(dst++) = stack->sp(); | |
295 } | |
296 else { | |
297 *(dst++) = src; | |
298 } | |
299 src--; | |
300 } | |
301 else if (type->size == 4) { | |
302 *(dst++) = src--; | |
303 } | |
304 else if (type->size == 8) { | |
305 src--; | |
306 *(dst++) = src--; | |
307 } | |
308 else { | |
309 ShouldNotReachHere(); | |
310 } | |
311 } | |
312 } | |
313 | |
314 // Set up the Java frame anchor | |
315 thread->set_last_Java_frame(); | |
316 | |
317 // Change the thread state to _thread_in_native | |
318 ThreadStateTransition::transition_from_java(thread, _thread_in_native); | |
319 | |
320 // Make the call | |
321 intptr_t result[4 - LogBytesPerWord]; | |
322 ffi_call(handler->cif(), (void (*)()) function, result, arguments); | |
323 | |
324 // Change the thread state back to _thread_in_Java. | |
325 // ThreadStateTransition::transition_from_native() cannot be used | |
326 // here because it does not check for asynchronous exceptions. | |
327 // We have to manage the transition ourself. | |
328 thread->set_thread_state(_thread_in_native_trans); | |
329 | |
330 // Make sure new state is visible in the GC thread | |
331 if (os::is_MP()) { | |
332 if (UseMembar) { | |
333 OrderAccess::fence(); | |
334 } | |
335 else { | |
336 InterfaceSupport::serialize_memory(thread); | |
337 } | |
338 } | |
339 | |
340 // Handle safepoint operations, pending suspend requests, | |
341 // and pending asynchronous exceptions. | |
342 if (SafepointSynchronize::do_call_back() || | |
343 thread->has_special_condition_for_native_trans()) { | |
344 JavaThread::check_special_condition_for_native_trans(thread); | |
345 CHECK_UNHANDLED_OOPS_ONLY(thread->clear_unhandled_oops()); | |
346 } | |
347 | |
348 // Finally we can change the thread state to _thread_in_Java. | |
349 thread->set_thread_state(_thread_in_Java); | |
350 fixup_after_potential_safepoint(); | |
351 | |
352 // Clear the frame anchor | |
353 thread->reset_last_Java_frame(); | |
354 | |
355 // If the result was an oop then unbox it and store it in | |
356 // oop_temp where the garbage collector can see it before | |
357 // we release the handle it might be protected by. | |
358 if (handler->result_type() == &ffi_type_pointer) { | |
359 if (result[0]) | |
360 istate->set_oop_temp(*(oop *) result[0]); | |
361 else | |
362 istate->set_oop_temp(NULL); | |
363 } | |
364 | |
365 // Reset handle block | |
366 thread->active_handles()->clear(); | |
367 | |
1139
b6f06e395428
6908267: Zero fails to unlock synchronized native methods on exception
never
parents:
1078
diff
changeset
|
368 unlock_unwind_and_return: |
b6f06e395428
6908267: Zero fails to unlock synchronized native methods on exception
never
parents:
1078
diff
changeset
|
369 |
b6f06e395428
6908267: Zero fails to unlock synchronized native methods on exception
never
parents:
1078
diff
changeset
|
370 // Unlock if necessary |
b6f06e395428
6908267: Zero fails to unlock synchronized native methods on exception
never
parents:
1078
diff
changeset
|
371 if (monitor) { |
1010 | 372 BasicLock *lock = monitor->lock(); |
373 markOop header = lock->displaced_header(); | |
374 oop rcvr = monitor->obj(); | |
375 monitor->set_obj(NULL); | |
376 | |
377 if (header != NULL) { | |
378 if (Atomic::cmpxchg_ptr(header, rcvr->mark_addr(), lock) != lock) { | |
379 monitor->set_obj(rcvr); { | |
380 HandleMark hm(thread); | |
381 CALL_VM_NOCHECK(InterpreterRuntime::monitorexit(thread, monitor)); | |
382 } | |
383 } | |
384 } | |
385 } | |
386 | |
387 unwind_and_return: | |
388 | |
389 // Unwind the current activation | |
390 thread->pop_zero_frame(); | |
391 | |
392 // Pop our parameters | |
393 stack->set_sp(stack->sp() + method->size_of_parameters()); | |
394 | |
395 // Push our result | |
396 if (!HAS_PENDING_EXCEPTION) { | |
1256 | 397 BasicType type = result_type_of(method); |
398 stack->set_sp(stack->sp() - type2size[type]); | |
1010 | 399 |
1256 | 400 switch (type) { |
1010 | 401 case T_VOID: |
402 break; | |
403 | |
404 case T_BOOLEAN: | |
405 #ifndef VM_LITTLE_ENDIAN | |
406 result[0] <<= (BitsPerWord - BitsPerByte); | |
407 #endif | |
408 SET_LOCALS_INT(*(jboolean *) result != 0, 0); | |
409 break; | |
410 | |
411 case T_CHAR: | |
412 #ifndef VM_LITTLE_ENDIAN | |
413 result[0] <<= (BitsPerWord - BitsPerShort); | |
414 #endif | |
415 SET_LOCALS_INT(*(jchar *) result, 0); | |
416 break; | |
417 | |
418 case T_BYTE: | |
419 #ifndef VM_LITTLE_ENDIAN | |
420 result[0] <<= (BitsPerWord - BitsPerByte); | |
421 #endif | |
422 SET_LOCALS_INT(*(jbyte *) result, 0); | |
423 break; | |
424 | |
425 case T_SHORT: | |
426 #ifndef VM_LITTLE_ENDIAN | |
427 result[0] <<= (BitsPerWord - BitsPerShort); | |
428 #endif | |
429 SET_LOCALS_INT(*(jshort *) result, 0); | |
430 break; | |
431 | |
432 case T_INT: | |
433 #ifndef VM_LITTLE_ENDIAN | |
434 result[0] <<= (BitsPerWord - BitsPerInt); | |
435 #endif | |
436 SET_LOCALS_INT(*(jint *) result, 0); | |
437 break; | |
438 | |
439 case T_LONG: | |
440 SET_LOCALS_LONG(*(jlong *) result, 0); | |
441 break; | |
442 | |
443 case T_FLOAT: | |
444 SET_LOCALS_FLOAT(*(jfloat *) result, 0); | |
445 break; | |
446 | |
447 case T_DOUBLE: | |
448 SET_LOCALS_DOUBLE(*(jdouble *) result, 0); | |
449 break; | |
450 | |
451 case T_OBJECT: | |
452 case T_ARRAY: | |
453 SET_LOCALS_OBJECT(istate->oop_temp(), 0); | |
454 break; | |
455 | |
456 default: | |
457 ShouldNotReachHere(); | |
458 } | |
459 } | |
460 } | |
461 | |
462 void CppInterpreter::accessor_entry(methodOop method, intptr_t UNUSED, TRAPS) { | |
463 JavaThread *thread = (JavaThread *) THREAD; | |
464 ZeroStack *stack = thread->zero_stack(); | |
465 intptr_t *locals = stack->sp(); | |
466 | |
467 // Drop into the slow path if we need a safepoint check | |
468 if (SafepointSynchronize::do_call_back()) { | |
469 normal_entry(method, 0, THREAD); | |
470 return; | |
471 } | |
472 | |
473 // Load the object pointer and drop into the slow path | |
474 // if we have a NullPointerException | |
475 oop object = LOCALS_OBJECT(0); | |
476 if (object == NULL) { | |
477 normal_entry(method, 0, THREAD); | |
478 return; | |
479 } | |
480 | |
481 // Read the field index from the bytecode, which looks like this: | |
482 // 0: aload_0 | |
483 // 1: getfield | |
484 // 2: index | |
485 // 3: index | |
486 // 4: ireturn/areturn | |
487 // NB this is not raw bytecode: index is in machine order | |
488 u1 *code = method->code_base(); | |
489 assert(code[0] == Bytecodes::_aload_0 && | |
490 code[1] == Bytecodes::_getfield && | |
491 (code[4] == Bytecodes::_ireturn || | |
492 code[4] == Bytecodes::_areturn), "should do"); | |
493 u2 index = Bytes::get_native_u2(&code[2]); | |
494 | |
495 // Get the entry from the constant pool cache, and drop into | |
496 // the slow path if it has not been resolved | |
497 constantPoolCacheOop cache = method->constants()->cache(); | |
498 ConstantPoolCacheEntry* entry = cache->entry_at(index); | |
499 if (!entry->is_resolved(Bytecodes::_getfield)) { | |
500 normal_entry(method, 0, THREAD); | |
501 return; | |
502 } | |
503 | |
504 // Get the result and push it onto the stack | |
505 switch (entry->flag_state()) { | |
506 case ltos: | |
507 case dtos: | |
508 if (stack->available_words() < 1) { | |
509 Unimplemented(); | |
510 } | |
511 stack->alloc(wordSize); | |
512 break; | |
513 } | |
514 if (entry->is_volatile()) { | |
515 switch (entry->flag_state()) { | |
516 case ctos: | |
517 SET_LOCALS_INT(object->char_field_acquire(entry->f2()), 0); | |
518 break; | |
519 | |
520 case btos: | |
521 SET_LOCALS_INT(object->byte_field_acquire(entry->f2()), 0); | |
522 break; | |
523 | |
524 case stos: | |
525 SET_LOCALS_INT(object->short_field_acquire(entry->f2()), 0); | |
526 break; | |
527 | |
528 case itos: | |
529 SET_LOCALS_INT(object->int_field_acquire(entry->f2()), 0); | |
530 break; | |
531 | |
532 case ltos: | |
533 SET_LOCALS_LONG(object->long_field_acquire(entry->f2()), 0); | |
534 break; | |
535 | |
536 case ftos: | |
537 SET_LOCALS_FLOAT(object->float_field_acquire(entry->f2()), 0); | |
538 break; | |
539 | |
540 case dtos: | |
541 SET_LOCALS_DOUBLE(object->double_field_acquire(entry->f2()), 0); | |
542 break; | |
543 | |
544 case atos: | |
545 SET_LOCALS_OBJECT(object->obj_field_acquire(entry->f2()), 0); | |
546 break; | |
547 | |
548 default: | |
549 ShouldNotReachHere(); | |
550 } | |
551 } | |
552 else { | |
553 switch (entry->flag_state()) { | |
554 case ctos: | |
555 SET_LOCALS_INT(object->char_field(entry->f2()), 0); | |
556 break; | |
557 | |
558 case btos: | |
559 SET_LOCALS_INT(object->byte_field(entry->f2()), 0); | |
560 break; | |
561 | |
562 case stos: | |
563 SET_LOCALS_INT(object->short_field(entry->f2()), 0); | |
564 break; | |
565 | |
566 case itos: | |
567 SET_LOCALS_INT(object->int_field(entry->f2()), 0); | |
568 break; | |
569 | |
570 case ltos: | |
571 SET_LOCALS_LONG(object->long_field(entry->f2()), 0); | |
572 break; | |
573 | |
574 case ftos: | |
575 SET_LOCALS_FLOAT(object->float_field(entry->f2()), 0); | |
576 break; | |
577 | |
578 case dtos: | |
579 SET_LOCALS_DOUBLE(object->double_field(entry->f2()), 0); | |
580 break; | |
581 | |
582 case atos: | |
583 SET_LOCALS_OBJECT(object->obj_field(entry->f2()), 0); | |
584 break; | |
585 | |
586 default: | |
587 ShouldNotReachHere(); | |
588 } | |
589 } | |
590 } | |
591 | |
592 void CppInterpreter::empty_entry(methodOop method, intptr_t UNUSED, TRAPS) { | |
593 JavaThread *thread = (JavaThread *) THREAD; | |
594 ZeroStack *stack = thread->zero_stack(); | |
595 | |
596 // Drop into the slow path if we need a safepoint check | |
597 if (SafepointSynchronize::do_call_back()) { | |
598 normal_entry(method, 0, THREAD); | |
599 return; | |
600 } | |
601 | |
602 // Pop our parameters | |
603 stack->set_sp(stack->sp() + method->size_of_parameters()); | |
604 } | |
605 | |
606 bool CppInterpreter::stack_overflow_imminent(JavaThread *thread) { | |
607 // How is the ABI stack? | |
608 address stack_top = thread->stack_base() - thread->stack_size(); | |
609 int free_stack = os::current_stack_pointer() - stack_top; | |
610 if (free_stack < StackShadowPages * os::vm_page_size()) { | |
611 return true; | |
612 } | |
613 | |
614 // How is the Zero stack? | |
615 // Throwing a StackOverflowError involves a VM call, which means | |
616 // we need a frame on the stack. We should be checking here to | |
617 // ensure that methods we call have enough room to install the | |
618 // largest possible frame, but that's more than twice the size | |
619 // of the entire Zero stack we get by default, so we just check | |
620 // we have *some* space instead... | |
621 free_stack = thread->zero_stack()->available_words() * wordSize; | |
622 if (free_stack < StackShadowPages * os::vm_page_size()) { | |
623 return true; | |
624 } | |
625 | |
626 return false; | |
627 } | |
628 | |
629 InterpreterFrame *InterpreterFrame::build(ZeroStack* stack, | |
630 const methodOop method, | |
631 JavaThread* thread) { | |
632 int monitor_words = | |
633 method->is_synchronized() ? frame::interpreter_frame_monitor_size() : 0; | |
634 int stack_words = method->is_native() ? 0 : method->max_stack(); | |
635 | |
636 if (header_words + monitor_words + stack_words > stack->available_words()) { | |
637 Unimplemented(); | |
638 } | |
639 | |
640 intptr_t *locals; | |
641 if (method->is_native()) | |
642 locals = stack->sp() + (method->size_of_parameters() - 1); | |
643 else | |
644 locals = stack->sp() + (method->max_locals() - 1); | |
645 | |
646 stack->push(0); // next_frame, filled in later | |
647 intptr_t *fp = stack->sp(); | |
648 assert(fp - stack->sp() == next_frame_off, "should be"); | |
649 | |
650 stack->push(INTERPRETER_FRAME); | |
651 assert(fp - stack->sp() == frame_type_off, "should be"); | |
652 | |
653 interpreterState istate = | |
654 (interpreterState) stack->alloc(sizeof(BytecodeInterpreter)); | |
655 assert(fp - stack->sp() == istate_off, "should be"); | |
656 | |
657 istate->set_locals(locals); | |
658 istate->set_method(method); | |
659 istate->set_self_link(istate); | |
660 istate->set_prev_link(NULL); | |
661 istate->set_thread(thread); | |
662 istate->set_bcp(method->is_native() ? NULL : method->code_base()); | |
663 istate->set_constants(method->constants()->cache()); | |
664 istate->set_msg(BytecodeInterpreter::method_entry); | |
665 istate->set_oop_temp(NULL); | |
666 istate->set_mdx(NULL); | |
667 istate->set_callee(NULL); | |
668 | |
669 istate->set_monitor_base((BasicObjectLock *) stack->sp()); | |
670 if (method->is_synchronized()) { | |
671 BasicObjectLock *monitor = | |
672 (BasicObjectLock *) stack->alloc(monitor_words * wordSize); | |
673 oop object; | |
674 if (method->is_static()) | |
675 object = method->constants()->pool_holder()->klass_part()->java_mirror(); | |
676 else | |
677 object = (oop) locals[0]; | |
678 monitor->set_obj(object); | |
679 } | |
680 | |
681 istate->set_stack_base(stack->sp()); | |
682 istate->set_stack(stack->sp() - 1); | |
683 if (stack_words) | |
684 stack->alloc(stack_words * wordSize); | |
685 istate->set_stack_limit(stack->sp() - 1); | |
686 | |
687 return (InterpreterFrame *) fp; | |
688 } | |
689 | |
690 int AbstractInterpreter::BasicType_as_index(BasicType type) { | |
691 int i = 0; | |
692 switch (type) { | |
693 case T_BOOLEAN: i = 0; break; | |
694 case T_CHAR : i = 1; break; | |
695 case T_BYTE : i = 2; break; | |
696 case T_SHORT : i = 3; break; | |
697 case T_INT : i = 4; break; | |
698 case T_LONG : i = 5; break; | |
699 case T_VOID : i = 6; break; | |
700 case T_FLOAT : i = 7; break; | |
701 case T_DOUBLE : i = 8; break; | |
702 case T_OBJECT : i = 9; break; | |
703 case T_ARRAY : i = 9; break; | |
704 default : ShouldNotReachHere(); | |
705 } | |
706 assert(0 <= i && i < AbstractInterpreter::number_of_result_handlers, | |
707 "index out of bounds"); | |
708 return i; | |
709 } | |
710 | |
1256 | 711 BasicType CppInterpreter::result_type_of(methodOop method) { |
712 BasicType t; | |
713 switch (method->result_index()) { | |
714 case 0 : t = T_BOOLEAN; break; | |
715 case 1 : t = T_CHAR; break; | |
716 case 2 : t = T_BYTE; break; | |
717 case 3 : t = T_SHORT; break; | |
718 case 4 : t = T_INT; break; | |
719 case 5 : t = T_LONG; break; | |
720 case 6 : t = T_VOID; break; | |
721 case 7 : t = T_FLOAT; break; | |
722 case 8 : t = T_DOUBLE; break; | |
723 case 9 : t = T_OBJECT; break; | |
724 default: ShouldNotReachHere(); | |
725 } | |
726 assert(AbstractInterpreter::BasicType_as_index(t) == method->result_index(), | |
727 "out of step with AbstractInterpreter::BasicType_as_index"); | |
728 return t; | |
729 } | |
730 | |
1010 | 731 address InterpreterGenerator::generate_empty_entry() { |
732 if (!UseFastEmptyMethods) | |
733 return NULL; | |
734 | |
735 return generate_entry((address) CppInterpreter::empty_entry); | |
736 } | |
737 | |
738 address InterpreterGenerator::generate_accessor_entry() { | |
739 if (!UseFastAccessorMethods) | |
740 return NULL; | |
741 | |
742 return generate_entry((address) CppInterpreter::accessor_entry); | |
743 } | |
744 | |
745 address InterpreterGenerator::generate_native_entry(bool synchronized) { | |
746 assert(synchronized == false, "should be"); | |
747 | |
748 return generate_entry((address) CppInterpreter::native_entry); | |
749 } | |
750 | |
751 address InterpreterGenerator::generate_normal_entry(bool synchronized) { | |
752 assert(synchronized == false, "should be"); | |
753 | |
754 return generate_entry((address) CppInterpreter::normal_entry); | |
755 } | |
756 | |
757 address AbstractInterpreterGenerator::generate_method_entry( | |
758 AbstractInterpreter::MethodKind kind) { | |
759 address entry_point = NULL; | |
760 | |
761 switch (kind) { | |
762 case Interpreter::zerolocals: | |
763 case Interpreter::zerolocals_synchronized: | |
764 break; | |
765 | |
766 case Interpreter::native: | |
767 entry_point = ((InterpreterGenerator*) this)->generate_native_entry(false); | |
768 break; | |
769 | |
770 case Interpreter::native_synchronized: | |
771 entry_point = ((InterpreterGenerator*) this)->generate_native_entry(false); | |
772 break; | |
773 | |
774 case Interpreter::empty: | |
775 entry_point = ((InterpreterGenerator*) this)->generate_empty_entry(); | |
776 break; | |
777 | |
778 case Interpreter::accessor: | |
779 entry_point = ((InterpreterGenerator*) this)->generate_accessor_entry(); | |
780 break; | |
781 | |
782 case Interpreter::abstract: | |
783 entry_point = ((InterpreterGenerator*) this)->generate_abstract_entry(); | |
784 break; | |
785 | |
786 case Interpreter::method_handle: | |
787 entry_point = ((InterpreterGenerator*) this)->generate_method_handle_entry(); | |
788 break; | |
789 | |
790 case Interpreter::java_lang_math_sin: | |
791 case Interpreter::java_lang_math_cos: | |
792 case Interpreter::java_lang_math_tan: | |
793 case Interpreter::java_lang_math_abs: | |
794 case Interpreter::java_lang_math_log: | |
795 case Interpreter::java_lang_math_log10: | |
796 case Interpreter::java_lang_math_sqrt: | |
797 entry_point = ((InterpreterGenerator*) this)->generate_math_entry(kind); | |
798 break; | |
799 | |
800 default: | |
801 ShouldNotReachHere(); | |
802 } | |
803 | |
804 if (entry_point == NULL) | |
805 entry_point = ((InterpreterGenerator*) this)->generate_normal_entry(false); | |
806 | |
807 return entry_point; | |
808 } | |
809 | |
810 InterpreterGenerator::InterpreterGenerator(StubQueue* code) | |
811 : CppInterpreterGenerator(code) { | |
812 generate_all(); | |
813 } | |
814 | |
815 // Deoptimization helpers | |
816 | |
817 InterpreterFrame *InterpreterFrame::build(ZeroStack* stack, int size) { | |
818 int size_in_words = size >> LogBytesPerWord; | |
819 assert(size_in_words * wordSize == size, "unaligned"); | |
820 assert(size_in_words >= header_words, "too small"); | |
821 | |
822 if (size_in_words > stack->available_words()) { | |
823 Unimplemented(); | |
824 } | |
825 | |
826 stack->push(0); // next_frame, filled in later | |
827 intptr_t *fp = stack->sp(); | |
828 assert(fp - stack->sp() == next_frame_off, "should be"); | |
829 | |
830 stack->push(INTERPRETER_FRAME); | |
831 assert(fp - stack->sp() == frame_type_off, "should be"); | |
832 | |
833 interpreterState istate = | |
834 (interpreterState) stack->alloc(sizeof(BytecodeInterpreter)); | |
835 assert(fp - stack->sp() == istate_off, "should be"); | |
836 istate->set_self_link(NULL); // mark invalid | |
837 | |
838 stack->alloc((size_in_words - header_words) * wordSize); | |
839 | |
840 return (InterpreterFrame *) fp; | |
841 } | |
842 | |
843 int AbstractInterpreter::layout_activation(methodOop method, | |
844 int tempcount, | |
845 int popframe_extra_args, | |
846 int moncount, | |
847 int callee_param_count, | |
848 int callee_locals, | |
849 frame* caller, | |
850 frame* interpreter_frame, | |
851 bool is_top_frame) { | |
852 assert(popframe_extra_args == 0, "what to do?"); | |
853 assert(!is_top_frame || (!callee_locals && !callee_param_count), | |
854 "top frame should have no caller") | |
855 | |
856 // This code must exactly match what InterpreterFrame::build | |
857 // does (the full InterpreterFrame::build, that is, not the | |
858 // one that creates empty frames for the deoptimizer). | |
859 // | |
860 // If interpreter_frame is not NULL then it will be filled in. | |
861 // It's size is determined by a previous call to this method, | |
862 // so it should be correct. | |
863 // | |
864 // Note that tempcount is the current size of the expression | |
865 // stack. For top most frames we will allocate a full sized | |
866 // expression stack and not the trimmed version that non-top | |
867 // frames have. | |
868 | |
869 int header_words = InterpreterFrame::header_words; | |
870 int monitor_words = moncount * frame::interpreter_frame_monitor_size(); | |
871 int stack_words = is_top_frame ? method->max_stack() : tempcount; | |
872 int callee_extra_locals = callee_locals - callee_param_count; | |
873 | |
874 if (interpreter_frame) { | |
875 intptr_t *locals = interpreter_frame->sp() + method->max_locals(); | |
876 interpreterState istate = interpreter_frame->get_interpreterState(); | |
877 intptr_t *monitor_base = (intptr_t*) istate; | |
878 intptr_t *stack_base = monitor_base - monitor_words; | |
879 intptr_t *stack = stack_base - tempcount - 1; | |
880 | |
881 BytecodeInterpreter::layout_interpreterState(istate, | |
882 caller, | |
883 NULL, | |
884 method, | |
885 locals, | |
886 stack, | |
887 stack_base, | |
888 monitor_base, | |
889 NULL, | |
890 is_top_frame); | |
891 } | |
892 return header_words + monitor_words + stack_words + callee_extra_locals; | |
893 } | |
894 | |
895 void BytecodeInterpreter::layout_interpreterState(interpreterState istate, | |
896 frame* caller, | |
897 frame* current, | |
898 methodOop method, | |
899 intptr_t* locals, | |
900 intptr_t* stack, | |
901 intptr_t* stack_base, | |
902 intptr_t* monitor_base, | |
903 intptr_t* frame_bottom, | |
904 bool is_top_frame) { | |
905 istate->set_locals(locals); | |
906 istate->set_method(method); | |
907 istate->set_self_link(istate); | |
908 istate->set_prev_link(NULL); | |
909 // thread will be set by a hacky repurposing of frame::patch_pc() | |
910 // bcp will be set by vframeArrayElement::unpack_on_stack() | |
911 istate->set_constants(method->constants()->cache()); | |
912 istate->set_msg(BytecodeInterpreter::method_resume); | |
913 istate->set_bcp_advance(0); | |
914 istate->set_oop_temp(NULL); | |
915 istate->set_mdx(NULL); | |
916 if (caller->is_interpreted_frame()) { | |
917 interpreterState prev = caller->get_interpreterState(); | |
918 prev->set_callee(method); | |
919 if (*prev->bcp() == Bytecodes::_invokeinterface) | |
920 prev->set_bcp_advance(5); | |
921 else | |
922 prev->set_bcp_advance(3); | |
923 } | |
924 istate->set_callee(NULL); | |
925 istate->set_monitor_base((BasicObjectLock *) monitor_base); | |
926 istate->set_stack_base(stack_base); | |
927 istate->set_stack(stack); | |
928 istate->set_stack_limit(stack_base - method->max_stack() - 1); | |
929 } | |
930 | |
931 address CppInterpreter::return_entry(TosState state, int length) { | |
932 ShouldNotCallThis(); | |
933 } | |
934 | |
935 address CppInterpreter::deopt_entry(TosState state, int length) { | |
936 return NULL; | |
937 } | |
938 | |
939 // Helper for (runtime) stack overflow checks | |
940 | |
941 int AbstractInterpreter::size_top_interpreter_activation(methodOop method) { | |
942 return 0; | |
943 } | |
944 | |
945 // Helper for figuring out if frames are interpreter frames | |
946 | |
947 bool CppInterpreter::contains(address pc) { | |
948 #ifdef PRODUCT | |
949 ShouldNotCallThis(); | |
950 #else | |
951 return false; // make frame::print_value_on work | |
952 #endif // !PRODUCT | |
953 } | |
954 | |
955 // Result handlers and convertors | |
956 | |
957 address CppInterpreterGenerator::generate_result_handler_for( | |
958 BasicType type) { | |
959 assembler()->advance(1); | |
960 return ShouldNotCallThisStub(); | |
961 } | |
962 | |
963 address CppInterpreterGenerator::generate_tosca_to_stack_converter( | |
964 BasicType type) { | |
965 assembler()->advance(1); | |
966 return ShouldNotCallThisStub(); | |
967 } | |
968 | |
969 address CppInterpreterGenerator::generate_stack_to_stack_converter( | |
970 BasicType type) { | |
971 assembler()->advance(1); | |
972 return ShouldNotCallThisStub(); | |
973 } | |
974 | |
975 address CppInterpreterGenerator::generate_stack_to_native_abi_converter( | |
976 BasicType type) { | |
977 assembler()->advance(1); | |
978 return ShouldNotCallThisStub(); | |
979 } | |
980 | |
981 #endif // CC_INTERP |