Mercurial > hg > graal-jvmci-8
annotate src/cpu/zero/vm/cppInterpreter_zero.cpp @ 1497:96d554193f72
6944822: Fix for 6938627 exposes problem with hard-coded buffer sizes
Summary: Make tmpdir buffer sizes MAX_PATH+1
Reviewed-by: dholmes, coleenp
Contributed-by: andreas.kohn@fredhopper.com
author | coleenp |
---|---|
date | Mon, 19 Apr 2010 18:58:31 -0400 |
parents | 747d26efc5fa |
children | f9271ff9d324 |
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 InvocationCounter *counter = method->invocation_counter(); | |
210 counter->increment(); | |
211 if (counter->reached_InvocationLimit()) { | |
212 CALL_VM_NOCHECK( | |
213 InterpreterRuntime::frequency_counter_overflow(thread, NULL)); | |
214 if (HAS_PENDING_EXCEPTION) | |
215 goto unwind_and_return; | |
216 } | |
217 } | |
218 | |
1010 | 219 // Lock if necessary |
220 BasicObjectLock *monitor; | |
221 monitor = NULL; | |
222 if (method->is_synchronized()) { | |
223 monitor = (BasicObjectLock*) istate->stack_base(); | |
224 oop lockee = monitor->obj(); | |
225 markOop disp = lockee->mark()->set_unlocked(); | |
226 | |
227 monitor->lock()->set_displaced_header(disp); | |
228 if (Atomic::cmpxchg_ptr(monitor, lockee->mark_addr(), disp) != disp) { | |
229 if (thread->is_lock_owned((address) disp->clear_lock_bits())) { | |
230 monitor->lock()->set_displaced_header(NULL); | |
231 } | |
232 else { | |
233 CALL_VM_NOCHECK(InterpreterRuntime::monitorenter(thread, monitor)); | |
234 if (HAS_PENDING_EXCEPTION) | |
235 goto unwind_and_return; | |
236 } | |
237 } | |
238 } | |
239 | |
240 // Get the signature handler | |
241 InterpreterRuntime::SignatureHandler *handler; { | |
242 address handlerAddr = method->signature_handler(); | |
243 if (handlerAddr == NULL) { | |
244 CALL_VM_NOCHECK(InterpreterRuntime::prepare_native_call(thread, method)); | |
245 if (HAS_PENDING_EXCEPTION) | |
1139
b6f06e395428
6908267: Zero fails to unlock synchronized native methods on exception
never
parents:
1078
diff
changeset
|
246 goto unlock_unwind_and_return; |
1010 | 247 |
248 handlerAddr = method->signature_handler(); | |
249 assert(handlerAddr != NULL, "eh?"); | |
250 } | |
251 if (handlerAddr == (address) InterpreterRuntime::slow_signature_handler) { | |
252 CALL_VM_NOCHECK(handlerAddr = | |
253 InterpreterRuntime::slow_signature_handler(thread, method, NULL,NULL)); | |
254 if (HAS_PENDING_EXCEPTION) | |
1139
b6f06e395428
6908267: Zero fails to unlock synchronized native methods on exception
never
parents:
1078
diff
changeset
|
255 goto unlock_unwind_and_return; |
1010 | 256 } |
257 handler = \ | |
258 InterpreterRuntime::SignatureHandler::from_handlerAddr(handlerAddr); | |
259 } | |
260 | |
261 // Get the native function entry point | |
262 address function; | |
263 function = method->native_function(); | |
264 assert(function != NULL, "should be set if signature handler is"); | |
265 | |
266 // Build the argument list | |
267 if (handler->argument_count() * 2 > stack->available_words()) { | |
268 Unimplemented(); | |
269 } | |
270 void **arguments; | |
271 void *mirror; { | |
272 arguments = | |
273 (void **) stack->alloc(handler->argument_count() * sizeof(void **)); | |
274 void **dst = arguments; | |
275 | |
276 void *env = thread->jni_environment(); | |
277 *(dst++) = &env; | |
278 | |
279 if (method->is_static()) { | |
280 istate->set_oop_temp( | |
281 method->constants()->pool_holder()->klass_part()->java_mirror()); | |
282 mirror = istate->oop_temp_addr(); | |
283 *(dst++) = &mirror; | |
284 } | |
285 | |
286 intptr_t *src = locals; | |
287 for (int i = dst - arguments; i < handler->argument_count(); i++) { | |
288 ffi_type *type = handler->argument_type(i); | |
289 if (type == &ffi_type_pointer) { | |
290 if (*src) { | |
291 stack->push((intptr_t) src); | |
292 *(dst++) = stack->sp(); | |
293 } | |
294 else { | |
295 *(dst++) = src; | |
296 } | |
297 src--; | |
298 } | |
299 else if (type->size == 4) { | |
300 *(dst++) = src--; | |
301 } | |
302 else if (type->size == 8) { | |
303 src--; | |
304 *(dst++) = src--; | |
305 } | |
306 else { | |
307 ShouldNotReachHere(); | |
308 } | |
309 } | |
310 } | |
311 | |
312 // Set up the Java frame anchor | |
313 thread->set_last_Java_frame(); | |
314 | |
315 // Change the thread state to _thread_in_native | |
316 ThreadStateTransition::transition_from_java(thread, _thread_in_native); | |
317 | |
318 // Make the call | |
319 intptr_t result[4 - LogBytesPerWord]; | |
320 ffi_call(handler->cif(), (void (*)()) function, result, arguments); | |
321 | |
322 // Change the thread state back to _thread_in_Java. | |
323 // ThreadStateTransition::transition_from_native() cannot be used | |
324 // here because it does not check for asynchronous exceptions. | |
325 // We have to manage the transition ourself. | |
326 thread->set_thread_state(_thread_in_native_trans); | |
327 | |
328 // Make sure new state is visible in the GC thread | |
329 if (os::is_MP()) { | |
330 if (UseMembar) { | |
331 OrderAccess::fence(); | |
332 } | |
333 else { | |
334 InterfaceSupport::serialize_memory(thread); | |
335 } | |
336 } | |
337 | |
338 // Handle safepoint operations, pending suspend requests, | |
339 // and pending asynchronous exceptions. | |
340 if (SafepointSynchronize::do_call_back() || | |
341 thread->has_special_condition_for_native_trans()) { | |
342 JavaThread::check_special_condition_for_native_trans(thread); | |
343 CHECK_UNHANDLED_OOPS_ONLY(thread->clear_unhandled_oops()); | |
344 } | |
345 | |
346 // Finally we can change the thread state to _thread_in_Java. | |
347 thread->set_thread_state(_thread_in_Java); | |
348 fixup_after_potential_safepoint(); | |
349 | |
350 // Clear the frame anchor | |
351 thread->reset_last_Java_frame(); | |
352 | |
353 // If the result was an oop then unbox it and store it in | |
354 // oop_temp where the garbage collector can see it before | |
355 // we release the handle it might be protected by. | |
356 if (handler->result_type() == &ffi_type_pointer) { | |
357 if (result[0]) | |
358 istate->set_oop_temp(*(oop *) result[0]); | |
359 else | |
360 istate->set_oop_temp(NULL); | |
361 } | |
362 | |
363 // Reset handle block | |
364 thread->active_handles()->clear(); | |
365 | |
1139
b6f06e395428
6908267: Zero fails to unlock synchronized native methods on exception
never
parents:
1078
diff
changeset
|
366 unlock_unwind_and_return: |
b6f06e395428
6908267: Zero fails to unlock synchronized native methods on exception
never
parents:
1078
diff
changeset
|
367 |
b6f06e395428
6908267: Zero fails to unlock synchronized native methods on exception
never
parents:
1078
diff
changeset
|
368 // Unlock if necessary |
b6f06e395428
6908267: Zero fails to unlock synchronized native methods on exception
never
parents:
1078
diff
changeset
|
369 if (monitor) { |
1010 | 370 BasicLock *lock = monitor->lock(); |
371 markOop header = lock->displaced_header(); | |
372 oop rcvr = monitor->obj(); | |
373 monitor->set_obj(NULL); | |
374 | |
375 if (header != NULL) { | |
376 if (Atomic::cmpxchg_ptr(header, rcvr->mark_addr(), lock) != lock) { | |
377 monitor->set_obj(rcvr); { | |
378 HandleMark hm(thread); | |
379 CALL_VM_NOCHECK(InterpreterRuntime::monitorexit(thread, monitor)); | |
380 } | |
381 } | |
382 } | |
383 } | |
384 | |
385 unwind_and_return: | |
386 | |
387 // Unwind the current activation | |
388 thread->pop_zero_frame(); | |
389 | |
390 // Pop our parameters | |
391 stack->set_sp(stack->sp() + method->size_of_parameters()); | |
392 | |
393 // Push our result | |
394 if (!HAS_PENDING_EXCEPTION) { | |
1256 | 395 BasicType type = result_type_of(method); |
396 stack->set_sp(stack->sp() - type2size[type]); | |
1010 | 397 |
1256 | 398 switch (type) { |
1010 | 399 case T_VOID: |
400 break; | |
401 | |
402 case T_BOOLEAN: | |
403 #ifndef VM_LITTLE_ENDIAN | |
404 result[0] <<= (BitsPerWord - BitsPerByte); | |
405 #endif | |
406 SET_LOCALS_INT(*(jboolean *) result != 0, 0); | |
407 break; | |
408 | |
409 case T_CHAR: | |
410 #ifndef VM_LITTLE_ENDIAN | |
411 result[0] <<= (BitsPerWord - BitsPerShort); | |
412 #endif | |
413 SET_LOCALS_INT(*(jchar *) result, 0); | |
414 break; | |
415 | |
416 case T_BYTE: | |
417 #ifndef VM_LITTLE_ENDIAN | |
418 result[0] <<= (BitsPerWord - BitsPerByte); | |
419 #endif | |
420 SET_LOCALS_INT(*(jbyte *) result, 0); | |
421 break; | |
422 | |
423 case T_SHORT: | |
424 #ifndef VM_LITTLE_ENDIAN | |
425 result[0] <<= (BitsPerWord - BitsPerShort); | |
426 #endif | |
427 SET_LOCALS_INT(*(jshort *) result, 0); | |
428 break; | |
429 | |
430 case T_INT: | |
431 #ifndef VM_LITTLE_ENDIAN | |
432 result[0] <<= (BitsPerWord - BitsPerInt); | |
433 #endif | |
434 SET_LOCALS_INT(*(jint *) result, 0); | |
435 break; | |
436 | |
437 case T_LONG: | |
438 SET_LOCALS_LONG(*(jlong *) result, 0); | |
439 break; | |
440 | |
441 case T_FLOAT: | |
442 SET_LOCALS_FLOAT(*(jfloat *) result, 0); | |
443 break; | |
444 | |
445 case T_DOUBLE: | |
446 SET_LOCALS_DOUBLE(*(jdouble *) result, 0); | |
447 break; | |
448 | |
449 case T_OBJECT: | |
450 case T_ARRAY: | |
451 SET_LOCALS_OBJECT(istate->oop_temp(), 0); | |
452 break; | |
453 | |
454 default: | |
455 ShouldNotReachHere(); | |
456 } | |
457 } | |
458 } | |
459 | |
460 void CppInterpreter::accessor_entry(methodOop method, intptr_t UNUSED, TRAPS) { | |
461 JavaThread *thread = (JavaThread *) THREAD; | |
462 ZeroStack *stack = thread->zero_stack(); | |
463 intptr_t *locals = stack->sp(); | |
464 | |
465 // Drop into the slow path if we need a safepoint check | |
466 if (SafepointSynchronize::do_call_back()) { | |
467 normal_entry(method, 0, THREAD); | |
468 return; | |
469 } | |
470 | |
471 // Load the object pointer and drop into the slow path | |
472 // if we have a NullPointerException | |
473 oop object = LOCALS_OBJECT(0); | |
474 if (object == NULL) { | |
475 normal_entry(method, 0, THREAD); | |
476 return; | |
477 } | |
478 | |
479 // Read the field index from the bytecode, which looks like this: | |
480 // 0: aload_0 | |
481 // 1: getfield | |
482 // 2: index | |
483 // 3: index | |
484 // 4: ireturn/areturn | |
485 // NB this is not raw bytecode: index is in machine order | |
486 u1 *code = method->code_base(); | |
487 assert(code[0] == Bytecodes::_aload_0 && | |
488 code[1] == Bytecodes::_getfield && | |
489 (code[4] == Bytecodes::_ireturn || | |
490 code[4] == Bytecodes::_areturn), "should do"); | |
491 u2 index = Bytes::get_native_u2(&code[2]); | |
492 | |
493 // Get the entry from the constant pool cache, and drop into | |
494 // the slow path if it has not been resolved | |
495 constantPoolCacheOop cache = method->constants()->cache(); | |
496 ConstantPoolCacheEntry* entry = cache->entry_at(index); | |
497 if (!entry->is_resolved(Bytecodes::_getfield)) { | |
498 normal_entry(method, 0, THREAD); | |
499 return; | |
500 } | |
501 | |
502 // Get the result and push it onto the stack | |
503 switch (entry->flag_state()) { | |
504 case ltos: | |
505 case dtos: | |
506 if (stack->available_words() < 1) { | |
507 Unimplemented(); | |
508 } | |
509 stack->alloc(wordSize); | |
510 break; | |
511 } | |
512 if (entry->is_volatile()) { | |
513 switch (entry->flag_state()) { | |
514 case ctos: | |
515 SET_LOCALS_INT(object->char_field_acquire(entry->f2()), 0); | |
516 break; | |
517 | |
518 case btos: | |
519 SET_LOCALS_INT(object->byte_field_acquire(entry->f2()), 0); | |
520 break; | |
521 | |
522 case stos: | |
523 SET_LOCALS_INT(object->short_field_acquire(entry->f2()), 0); | |
524 break; | |
525 | |
526 case itos: | |
527 SET_LOCALS_INT(object->int_field_acquire(entry->f2()), 0); | |
528 break; | |
529 | |
530 case ltos: | |
531 SET_LOCALS_LONG(object->long_field_acquire(entry->f2()), 0); | |
532 break; | |
533 | |
534 case ftos: | |
535 SET_LOCALS_FLOAT(object->float_field_acquire(entry->f2()), 0); | |
536 break; | |
537 | |
538 case dtos: | |
539 SET_LOCALS_DOUBLE(object->double_field_acquire(entry->f2()), 0); | |
540 break; | |
541 | |
542 case atos: | |
543 SET_LOCALS_OBJECT(object->obj_field_acquire(entry->f2()), 0); | |
544 break; | |
545 | |
546 default: | |
547 ShouldNotReachHere(); | |
548 } | |
549 } | |
550 else { | |
551 switch (entry->flag_state()) { | |
552 case ctos: | |
553 SET_LOCALS_INT(object->char_field(entry->f2()), 0); | |
554 break; | |
555 | |
556 case btos: | |
557 SET_LOCALS_INT(object->byte_field(entry->f2()), 0); | |
558 break; | |
559 | |
560 case stos: | |
561 SET_LOCALS_INT(object->short_field(entry->f2()), 0); | |
562 break; | |
563 | |
564 case itos: | |
565 SET_LOCALS_INT(object->int_field(entry->f2()), 0); | |
566 break; | |
567 | |
568 case ltos: | |
569 SET_LOCALS_LONG(object->long_field(entry->f2()), 0); | |
570 break; | |
571 | |
572 case ftos: | |
573 SET_LOCALS_FLOAT(object->float_field(entry->f2()), 0); | |
574 break; | |
575 | |
576 case dtos: | |
577 SET_LOCALS_DOUBLE(object->double_field(entry->f2()), 0); | |
578 break; | |
579 | |
580 case atos: | |
581 SET_LOCALS_OBJECT(object->obj_field(entry->f2()), 0); | |
582 break; | |
583 | |
584 default: | |
585 ShouldNotReachHere(); | |
586 } | |
587 } | |
588 } | |
589 | |
590 void CppInterpreter::empty_entry(methodOop method, intptr_t UNUSED, TRAPS) { | |
591 JavaThread *thread = (JavaThread *) THREAD; | |
592 ZeroStack *stack = thread->zero_stack(); | |
593 | |
594 // Drop into the slow path if we need a safepoint check | |
595 if (SafepointSynchronize::do_call_back()) { | |
596 normal_entry(method, 0, THREAD); | |
597 return; | |
598 } | |
599 | |
600 // Pop our parameters | |
601 stack->set_sp(stack->sp() + method->size_of_parameters()); | |
602 } | |
603 | |
604 bool CppInterpreter::stack_overflow_imminent(JavaThread *thread) { | |
605 // How is the ABI stack? | |
606 address stack_top = thread->stack_base() - thread->stack_size(); | |
607 int free_stack = os::current_stack_pointer() - stack_top; | |
608 if (free_stack < StackShadowPages * os::vm_page_size()) { | |
609 return true; | |
610 } | |
611 | |
612 // How is the Zero stack? | |
613 // Throwing a StackOverflowError involves a VM call, which means | |
614 // we need a frame on the stack. We should be checking here to | |
615 // ensure that methods we call have enough room to install the | |
616 // largest possible frame, but that's more than twice the size | |
617 // of the entire Zero stack we get by default, so we just check | |
618 // we have *some* space instead... | |
619 free_stack = thread->zero_stack()->available_words() * wordSize; | |
620 if (free_stack < StackShadowPages * os::vm_page_size()) { | |
621 return true; | |
622 } | |
623 | |
624 return false; | |
625 } | |
626 | |
627 InterpreterFrame *InterpreterFrame::build(ZeroStack* stack, | |
628 const methodOop method, | |
629 JavaThread* thread) { | |
630 int monitor_words = | |
631 method->is_synchronized() ? frame::interpreter_frame_monitor_size() : 0; | |
632 int stack_words = method->is_native() ? 0 : method->max_stack(); | |
633 | |
634 if (header_words + monitor_words + stack_words > stack->available_words()) { | |
635 Unimplemented(); | |
636 } | |
637 | |
638 intptr_t *locals; | |
639 if (method->is_native()) | |
640 locals = stack->sp() + (method->size_of_parameters() - 1); | |
641 else | |
642 locals = stack->sp() + (method->max_locals() - 1); | |
643 | |
644 stack->push(0); // next_frame, filled in later | |
645 intptr_t *fp = stack->sp(); | |
646 assert(fp - stack->sp() == next_frame_off, "should be"); | |
647 | |
648 stack->push(INTERPRETER_FRAME); | |
649 assert(fp - stack->sp() == frame_type_off, "should be"); | |
650 | |
651 interpreterState istate = | |
652 (interpreterState) stack->alloc(sizeof(BytecodeInterpreter)); | |
653 assert(fp - stack->sp() == istate_off, "should be"); | |
654 | |
655 istate->set_locals(locals); | |
656 istate->set_method(method); | |
657 istate->set_self_link(istate); | |
658 istate->set_prev_link(NULL); | |
659 istate->set_thread(thread); | |
660 istate->set_bcp(method->is_native() ? NULL : method->code_base()); | |
661 istate->set_constants(method->constants()->cache()); | |
662 istate->set_msg(BytecodeInterpreter::method_entry); | |
663 istate->set_oop_temp(NULL); | |
664 istate->set_mdx(NULL); | |
665 istate->set_callee(NULL); | |
666 | |
667 istate->set_monitor_base((BasicObjectLock *) stack->sp()); | |
668 if (method->is_synchronized()) { | |
669 BasicObjectLock *monitor = | |
670 (BasicObjectLock *) stack->alloc(monitor_words * wordSize); | |
671 oop object; | |
672 if (method->is_static()) | |
673 object = method->constants()->pool_holder()->klass_part()->java_mirror(); | |
674 else | |
675 object = (oop) locals[0]; | |
676 monitor->set_obj(object); | |
677 } | |
678 | |
679 istate->set_stack_base(stack->sp()); | |
680 istate->set_stack(stack->sp() - 1); | |
681 if (stack_words) | |
682 stack->alloc(stack_words * wordSize); | |
683 istate->set_stack_limit(stack->sp() - 1); | |
684 | |
685 return (InterpreterFrame *) fp; | |
686 } | |
687 | |
688 int AbstractInterpreter::BasicType_as_index(BasicType type) { | |
689 int i = 0; | |
690 switch (type) { | |
691 case T_BOOLEAN: i = 0; break; | |
692 case T_CHAR : i = 1; break; | |
693 case T_BYTE : i = 2; break; | |
694 case T_SHORT : i = 3; break; | |
695 case T_INT : i = 4; break; | |
696 case T_LONG : i = 5; break; | |
697 case T_VOID : i = 6; break; | |
698 case T_FLOAT : i = 7; break; | |
699 case T_DOUBLE : i = 8; break; | |
700 case T_OBJECT : i = 9; break; | |
701 case T_ARRAY : i = 9; break; | |
702 default : ShouldNotReachHere(); | |
703 } | |
704 assert(0 <= i && i < AbstractInterpreter::number_of_result_handlers, | |
705 "index out of bounds"); | |
706 return i; | |
707 } | |
708 | |
1256 | 709 BasicType CppInterpreter::result_type_of(methodOop method) { |
710 BasicType t; | |
711 switch (method->result_index()) { | |
712 case 0 : t = T_BOOLEAN; break; | |
713 case 1 : t = T_CHAR; break; | |
714 case 2 : t = T_BYTE; break; | |
715 case 3 : t = T_SHORT; break; | |
716 case 4 : t = T_INT; break; | |
717 case 5 : t = T_LONG; break; | |
718 case 6 : t = T_VOID; break; | |
719 case 7 : t = T_FLOAT; break; | |
720 case 8 : t = T_DOUBLE; break; | |
721 case 9 : t = T_OBJECT; break; | |
722 default: ShouldNotReachHere(); | |
723 } | |
724 assert(AbstractInterpreter::BasicType_as_index(t) == method->result_index(), | |
725 "out of step with AbstractInterpreter::BasicType_as_index"); | |
726 return t; | |
727 } | |
728 | |
1010 | 729 address InterpreterGenerator::generate_empty_entry() { |
730 if (!UseFastEmptyMethods) | |
731 return NULL; | |
732 | |
733 return generate_entry((address) CppInterpreter::empty_entry); | |
734 } | |
735 | |
736 address InterpreterGenerator::generate_accessor_entry() { | |
737 if (!UseFastAccessorMethods) | |
738 return NULL; | |
739 | |
740 return generate_entry((address) CppInterpreter::accessor_entry); | |
741 } | |
742 | |
743 address InterpreterGenerator::generate_native_entry(bool synchronized) { | |
744 assert(synchronized == false, "should be"); | |
745 | |
746 return generate_entry((address) CppInterpreter::native_entry); | |
747 } | |
748 | |
749 address InterpreterGenerator::generate_normal_entry(bool synchronized) { | |
750 assert(synchronized == false, "should be"); | |
751 | |
752 return generate_entry((address) CppInterpreter::normal_entry); | |
753 } | |
754 | |
755 address AbstractInterpreterGenerator::generate_method_entry( | |
756 AbstractInterpreter::MethodKind kind) { | |
757 address entry_point = NULL; | |
758 | |
759 switch (kind) { | |
760 case Interpreter::zerolocals: | |
761 case Interpreter::zerolocals_synchronized: | |
762 break; | |
763 | |
764 case Interpreter::native: | |
765 entry_point = ((InterpreterGenerator*) this)->generate_native_entry(false); | |
766 break; | |
767 | |
768 case Interpreter::native_synchronized: | |
769 entry_point = ((InterpreterGenerator*) this)->generate_native_entry(false); | |
770 break; | |
771 | |
772 case Interpreter::empty: | |
773 entry_point = ((InterpreterGenerator*) this)->generate_empty_entry(); | |
774 break; | |
775 | |
776 case Interpreter::accessor: | |
777 entry_point = ((InterpreterGenerator*) this)->generate_accessor_entry(); | |
778 break; | |
779 | |
780 case Interpreter::abstract: | |
781 entry_point = ((InterpreterGenerator*) this)->generate_abstract_entry(); | |
782 break; | |
783 | |
784 case Interpreter::method_handle: | |
785 entry_point = ((InterpreterGenerator*) this)->generate_method_handle_entry(); | |
786 break; | |
787 | |
788 case Interpreter::java_lang_math_sin: | |
789 case Interpreter::java_lang_math_cos: | |
790 case Interpreter::java_lang_math_tan: | |
791 case Interpreter::java_lang_math_abs: | |
792 case Interpreter::java_lang_math_log: | |
793 case Interpreter::java_lang_math_log10: | |
794 case Interpreter::java_lang_math_sqrt: | |
795 entry_point = ((InterpreterGenerator*) this)->generate_math_entry(kind); | |
796 break; | |
797 | |
798 default: | |
799 ShouldNotReachHere(); | |
800 } | |
801 | |
802 if (entry_point == NULL) | |
803 entry_point = ((InterpreterGenerator*) this)->generate_normal_entry(false); | |
804 | |
805 return entry_point; | |
806 } | |
807 | |
808 InterpreterGenerator::InterpreterGenerator(StubQueue* code) | |
809 : CppInterpreterGenerator(code) { | |
810 generate_all(); | |
811 } | |
812 | |
813 // Deoptimization helpers | |
814 | |
815 InterpreterFrame *InterpreterFrame::build(ZeroStack* stack, int size) { | |
816 int size_in_words = size >> LogBytesPerWord; | |
817 assert(size_in_words * wordSize == size, "unaligned"); | |
818 assert(size_in_words >= header_words, "too small"); | |
819 | |
820 if (size_in_words > stack->available_words()) { | |
821 Unimplemented(); | |
822 } | |
823 | |
824 stack->push(0); // next_frame, filled in later | |
825 intptr_t *fp = stack->sp(); | |
826 assert(fp - stack->sp() == next_frame_off, "should be"); | |
827 | |
828 stack->push(INTERPRETER_FRAME); | |
829 assert(fp - stack->sp() == frame_type_off, "should be"); | |
830 | |
831 interpreterState istate = | |
832 (interpreterState) stack->alloc(sizeof(BytecodeInterpreter)); | |
833 assert(fp - stack->sp() == istate_off, "should be"); | |
834 istate->set_self_link(NULL); // mark invalid | |
835 | |
836 stack->alloc((size_in_words - header_words) * wordSize); | |
837 | |
838 return (InterpreterFrame *) fp; | |
839 } | |
840 | |
841 int AbstractInterpreter::layout_activation(methodOop method, | |
842 int tempcount, | |
843 int popframe_extra_args, | |
844 int moncount, | |
845 int callee_param_count, | |
846 int callee_locals, | |
847 frame* caller, | |
848 frame* interpreter_frame, | |
849 bool is_top_frame) { | |
850 assert(popframe_extra_args == 0, "what to do?"); | |
851 assert(!is_top_frame || (!callee_locals && !callee_param_count), | |
852 "top frame should have no caller") | |
853 | |
854 // This code must exactly match what InterpreterFrame::build | |
855 // does (the full InterpreterFrame::build, that is, not the | |
856 // one that creates empty frames for the deoptimizer). | |
857 // | |
858 // If interpreter_frame is not NULL then it will be filled in. | |
859 // It's size is determined by a previous call to this method, | |
860 // so it should be correct. | |
861 // | |
862 // Note that tempcount is the current size of the expression | |
863 // stack. For top most frames we will allocate a full sized | |
864 // expression stack and not the trimmed version that non-top | |
865 // frames have. | |
866 | |
867 int header_words = InterpreterFrame::header_words; | |
868 int monitor_words = moncount * frame::interpreter_frame_monitor_size(); | |
869 int stack_words = is_top_frame ? method->max_stack() : tempcount; | |
870 int callee_extra_locals = callee_locals - callee_param_count; | |
871 | |
872 if (interpreter_frame) { | |
873 intptr_t *locals = interpreter_frame->sp() + method->max_locals(); | |
874 interpreterState istate = interpreter_frame->get_interpreterState(); | |
875 intptr_t *monitor_base = (intptr_t*) istate; | |
876 intptr_t *stack_base = monitor_base - monitor_words; | |
877 intptr_t *stack = stack_base - tempcount - 1; | |
878 | |
879 BytecodeInterpreter::layout_interpreterState(istate, | |
880 caller, | |
881 NULL, | |
882 method, | |
883 locals, | |
884 stack, | |
885 stack_base, | |
886 monitor_base, | |
887 NULL, | |
888 is_top_frame); | |
889 } | |
890 return header_words + monitor_words + stack_words + callee_extra_locals; | |
891 } | |
892 | |
893 void BytecodeInterpreter::layout_interpreterState(interpreterState istate, | |
894 frame* caller, | |
895 frame* current, | |
896 methodOop method, | |
897 intptr_t* locals, | |
898 intptr_t* stack, | |
899 intptr_t* stack_base, | |
900 intptr_t* monitor_base, | |
901 intptr_t* frame_bottom, | |
902 bool is_top_frame) { | |
903 istate->set_locals(locals); | |
904 istate->set_method(method); | |
905 istate->set_self_link(istate); | |
906 istate->set_prev_link(NULL); | |
907 // thread will be set by a hacky repurposing of frame::patch_pc() | |
908 // bcp will be set by vframeArrayElement::unpack_on_stack() | |
909 istate->set_constants(method->constants()->cache()); | |
910 istate->set_msg(BytecodeInterpreter::method_resume); | |
911 istate->set_bcp_advance(0); | |
912 istate->set_oop_temp(NULL); | |
913 istate->set_mdx(NULL); | |
914 if (caller->is_interpreted_frame()) { | |
915 interpreterState prev = caller->get_interpreterState(); | |
916 prev->set_callee(method); | |
917 if (*prev->bcp() == Bytecodes::_invokeinterface) | |
918 prev->set_bcp_advance(5); | |
919 else | |
920 prev->set_bcp_advance(3); | |
921 } | |
922 istate->set_callee(NULL); | |
923 istate->set_monitor_base((BasicObjectLock *) monitor_base); | |
924 istate->set_stack_base(stack_base); | |
925 istate->set_stack(stack); | |
926 istate->set_stack_limit(stack_base - method->max_stack() - 1); | |
927 } | |
928 | |
929 address CppInterpreter::return_entry(TosState state, int length) { | |
930 ShouldNotCallThis(); | |
931 } | |
932 | |
933 address CppInterpreter::deopt_entry(TosState state, int length) { | |
934 return NULL; | |
935 } | |
936 | |
937 // Helper for (runtime) stack overflow checks | |
938 | |
939 int AbstractInterpreter::size_top_interpreter_activation(methodOop method) { | |
940 return 0; | |
941 } | |
942 | |
943 // Helper for figuring out if frames are interpreter frames | |
944 | |
945 bool CppInterpreter::contains(address pc) { | |
946 #ifdef PRODUCT | |
947 ShouldNotCallThis(); | |
948 #else | |
949 return false; // make frame::print_value_on work | |
950 #endif // !PRODUCT | |
951 } | |
952 | |
953 // Result handlers and convertors | |
954 | |
955 address CppInterpreterGenerator::generate_result_handler_for( | |
956 BasicType type) { | |
957 assembler()->advance(1); | |
958 return ShouldNotCallThisStub(); | |
959 } | |
960 | |
961 address CppInterpreterGenerator::generate_tosca_to_stack_converter( | |
962 BasicType type) { | |
963 assembler()->advance(1); | |
964 return ShouldNotCallThisStub(); | |
965 } | |
966 | |
967 address CppInterpreterGenerator::generate_stack_to_stack_converter( | |
968 BasicType type) { | |
969 assembler()->advance(1); | |
970 return ShouldNotCallThisStub(); | |
971 } | |
972 | |
973 address CppInterpreterGenerator::generate_stack_to_native_abi_converter( | |
974 BasicType type) { | |
975 assembler()->advance(1); | |
976 return ShouldNotCallThisStub(); | |
977 } | |
978 | |
979 #endif // CC_INTERP |