src/cpu/zero/vm/cppInterpreter_zero.cpp

Fri, 18 Mar 2011 16:00:34 -0700

author
never
date
Fri, 18 Mar 2011 16:00:34 -0700
changeset 2658
c7f3d0b4570f
parent 2314
f95d63e2154a
child 2762
4b95bbb36464
child 2781
e1162778c1c8
permissions
-rw-r--r--

7017732: move static fields into Class to prepare for perm gen removal
Reviewed-by: kvn, coleenp, twisti, stefank

     1 /*
     2  * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
     3  * Copyright 2007, 2008, 2009, 2010 Red Hat, Inc.
     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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    21  * or visit www.oracle.com if you need additional information or have any
    22  * questions.
    23  *
    24  */
    26 #include "precompiled.hpp"
    27 #include "asm/assembler.hpp"
    28 #include "interpreter/bytecodeHistogram.hpp"
    29 #include "interpreter/cppInterpreter.hpp"
    30 #include "interpreter/interpreter.hpp"
    31 #include "interpreter/interpreterGenerator.hpp"
    32 #include "interpreter/interpreterRuntime.hpp"
    33 #include "oops/arrayOop.hpp"
    34 #include "oops/methodDataOop.hpp"
    35 #include "oops/methodOop.hpp"
    36 #include "oops/oop.inline.hpp"
    37 #include "prims/jvmtiExport.hpp"
    38 #include "prims/jvmtiThreadState.hpp"
    39 #include "runtime/arguments.hpp"
    40 #include "runtime/deoptimization.hpp"
    41 #include "runtime/frame.inline.hpp"
    42 #include "runtime/interfaceSupport.hpp"
    43 #include "runtime/sharedRuntime.hpp"
    44 #include "runtime/stubRoutines.hpp"
    45 #include "runtime/synchronizer.hpp"
    46 #include "runtime/timer.hpp"
    47 #include "runtime/vframeArray.hpp"
    48 #include "stack_zero.inline.hpp"
    49 #include "utilities/debug.hpp"
    50 #ifdef SHARK
    51 #include "shark/shark_globals.hpp"
    52 #endif
    54 #ifdef CC_INTERP
    56 #define fixup_after_potential_safepoint()       \
    57   method = istate->method()
    59 #define CALL_VM_NOCHECK(func)                   \
    60   thread->set_last_Java_frame();                \
    61   func;                                         \
    62   thread->reset_last_Java_frame();              \
    63   fixup_after_potential_safepoint()
    65 int CppInterpreter::normal_entry(methodOop method, intptr_t UNUSED, TRAPS) {
    66   JavaThread *thread = (JavaThread *) THREAD;
    68   // Allocate and initialize our frame.
    69   InterpreterFrame *frame = InterpreterFrame::build(method, CHECK_0);
    70   thread->push_zero_frame(frame);
    72   // Execute those bytecodes!
    73   main_loop(0, THREAD);
    75   // No deoptimized frames on the stack
    76   return 0;
    77 }
    79 void CppInterpreter::main_loop(int recurse, TRAPS) {
    80   JavaThread *thread = (JavaThread *) THREAD;
    81   ZeroStack *stack = thread->zero_stack();
    83   // If we are entering from a deopt we may need to call
    84   // ourself a few times in order to get to our frame.
    85   if (recurse)
    86     main_loop(recurse - 1, THREAD);
    88   InterpreterFrame *frame = thread->top_zero_frame()->as_interpreter_frame();
    89   interpreterState istate = frame->interpreter_state();
    90   methodOop method = istate->method();
    92   intptr_t *result = NULL;
    93   int result_slots = 0;
    95   while (true) {
    96     // We can set up the frame anchor with everything we want at
    97     // this point as we are thread_in_Java and no safepoints can
    98     // occur until we go to vm mode.  We do have to clear flags
    99     // on return from vm but that is it.
   100     thread->set_last_Java_frame();
   102     // Call the interpreter
   103     if (JvmtiExport::can_post_interpreter_events())
   104       BytecodeInterpreter::runWithChecks(istate);
   105     else
   106       BytecodeInterpreter::run(istate);
   107     fixup_after_potential_safepoint();
   109     // Clear the frame anchor
   110     thread->reset_last_Java_frame();
   112     // Examine the message from the interpreter to decide what to do
   113     if (istate->msg() == BytecodeInterpreter::call_method) {
   114       methodOop callee = istate->callee();
   116       // Trim back the stack to put the parameters at the top
   117       stack->set_sp(istate->stack() + 1);
   119       // Make the call
   120       Interpreter::invoke_method(callee, istate->callee_entry_point(), THREAD);
   121       fixup_after_potential_safepoint();
   123       // Convert the result
   124       istate->set_stack(stack->sp() - 1);
   126       // Restore the stack
   127       stack->set_sp(istate->stack_limit() + 1);
   129       // Resume the interpreter
   130       istate->set_msg(BytecodeInterpreter::method_resume);
   131     }
   132     else if (istate->msg() == BytecodeInterpreter::more_monitors) {
   133       int monitor_words = frame::interpreter_frame_monitor_size();
   135       // Allocate the space
   136       stack->overflow_check(monitor_words, THREAD);
   137       if (HAS_PENDING_EXCEPTION)
   138         break;
   139       stack->alloc(monitor_words * wordSize);
   141       // Move the expression stack contents
   142       for (intptr_t *p = istate->stack() + 1; p < istate->stack_base(); p++)
   143         *(p - monitor_words) = *p;
   145       // Move the expression stack pointers
   146       istate->set_stack_limit(istate->stack_limit() - monitor_words);
   147       istate->set_stack(istate->stack() - monitor_words);
   148       istate->set_stack_base(istate->stack_base() - monitor_words);
   150       // Zero the new monitor so the interpreter can find it.
   151       ((BasicObjectLock *) istate->stack_base())->set_obj(NULL);
   153       // Resume the interpreter
   154       istate->set_msg(BytecodeInterpreter::got_monitors);
   155     }
   156     else if (istate->msg() == BytecodeInterpreter::return_from_method) {
   157       // Copy the result into the caller's frame
   158       result_slots = type2size[result_type_of(method)];
   159       assert(result_slots >= 0 && result_slots <= 2, "what?");
   160       result = istate->stack() + result_slots;
   161       break;
   162     }
   163     else if (istate->msg() == BytecodeInterpreter::throwing_exception) {
   164       assert(HAS_PENDING_EXCEPTION, "should do");
   165       break;
   166     }
   167     else if (istate->msg() == BytecodeInterpreter::do_osr) {
   168       // Unwind the current frame
   169       thread->pop_zero_frame();
   171       // Remove any extension of the previous frame
   172       int extra_locals = method->max_locals() - method->size_of_parameters();
   173       stack->set_sp(stack->sp() + extra_locals);
   175       // Jump into the OSR method
   176       Interpreter::invoke_osr(
   177         method, istate->osr_entry(), istate->osr_buf(), THREAD);
   178       return;
   179     }
   180     else {
   181       ShouldNotReachHere();
   182     }
   183   }
   185   // Unwind the current frame
   186   thread->pop_zero_frame();
   188   // Pop our local variables
   189   stack->set_sp(stack->sp() + method->max_locals());
   191   // Push our result
   192   for (int i = 0; i < result_slots; i++)
   193     stack->push(result[-i]);
   194 }
   196 int CppInterpreter::native_entry(methodOop method, intptr_t UNUSED, TRAPS) {
   197   // Make sure method is native and not abstract
   198   assert(method->is_native() && !method->is_abstract(), "should be");
   200   JavaThread *thread = (JavaThread *) THREAD;
   201   ZeroStack *stack = thread->zero_stack();
   203   // Allocate and initialize our frame
   204   InterpreterFrame *frame = InterpreterFrame::build(method, CHECK_0);
   205   thread->push_zero_frame(frame);
   206   interpreterState istate = frame->interpreter_state();
   207   intptr_t *locals = istate->locals();
   209   // Update the invocation counter
   210   if ((UseCompiler || CountCompiledCalls) && !method->is_synchronized()) {
   211     InvocationCounter *counter = method->invocation_counter();
   212     counter->increment();
   213     if (counter->reached_InvocationLimit()) {
   214       CALL_VM_NOCHECK(
   215         InterpreterRuntime::frequency_counter_overflow(thread, NULL));
   216       if (HAS_PENDING_EXCEPTION)
   217         goto unwind_and_return;
   218     }
   219   }
   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();
   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   }
   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)
   248         goto unlock_unwind_and_return;
   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)
   257         goto unlock_unwind_and_return;
   258     }
   259     handler = \
   260       InterpreterRuntime::SignatureHandler::from_handlerAddr(handlerAddr);
   261   }
   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");
   268   // Build the argument list
   269   stack->overflow_check(handler->argument_count() * 2, THREAD);
   270   if (HAS_PENDING_EXCEPTION)
   271     goto unlock_unwind_and_return;
   273   void **arguments;
   274   void *mirror; {
   275     arguments =
   276       (void **) stack->alloc(handler->argument_count() * sizeof(void **));
   277     void **dst = arguments;
   279     void *env = thread->jni_environment();
   280     *(dst++) = &env;
   282     if (method->is_static()) {
   283       istate->set_oop_temp(
   284         method->constants()->pool_holder()->java_mirror());
   285       mirror = istate->oop_temp_addr();
   286       *(dst++) = &mirror;
   287     }
   289     intptr_t *src = locals;
   290     for (int i = dst - arguments; i < handler->argument_count(); i++) {
   291       ffi_type *type = handler->argument_type(i);
   292       if (type == &ffi_type_pointer) {
   293         if (*src) {
   294           stack->push((intptr_t) src);
   295           *(dst++) = stack->sp();
   296         }
   297         else {
   298           *(dst++) = src;
   299         }
   300         src--;
   301       }
   302       else if (type->size == 4) {
   303         *(dst++) = src--;
   304       }
   305       else if (type->size == 8) {
   306         src--;
   307         *(dst++) = src--;
   308       }
   309       else {
   310         ShouldNotReachHere();
   311       }
   312     }
   313   }
   315   // Set up the Java frame anchor
   316   thread->set_last_Java_frame();
   318   // Change the thread state to _thread_in_native
   319   ThreadStateTransition::transition_from_java(thread, _thread_in_native);
   321   // Make the call
   322   intptr_t result[4 - LogBytesPerWord];
   323   ffi_call(handler->cif(), (void (*)()) function, result, arguments);
   325   // Change the thread state back to _thread_in_Java.
   326   // ThreadStateTransition::transition_from_native() cannot be used
   327   // here because it does not check for asynchronous exceptions.
   328   // We have to manage the transition ourself.
   329   thread->set_thread_state(_thread_in_native_trans);
   331   // Make sure new state is visible in the GC thread
   332   if (os::is_MP()) {
   333     if (UseMembar) {
   334       OrderAccess::fence();
   335     }
   336     else {
   337       InterfaceSupport::serialize_memory(thread);
   338     }
   339   }
   341   // Handle safepoint operations, pending suspend requests,
   342   // and pending asynchronous exceptions.
   343   if (SafepointSynchronize::do_call_back() ||
   344       thread->has_special_condition_for_native_trans()) {
   345     JavaThread::check_special_condition_for_native_trans(thread);
   346     CHECK_UNHANDLED_OOPS_ONLY(thread->clear_unhandled_oops());
   347   }
   349   // Finally we can change the thread state to _thread_in_Java.
   350   thread->set_thread_state(_thread_in_Java);
   351   fixup_after_potential_safepoint();
   353   // Clear the frame anchor
   354   thread->reset_last_Java_frame();
   356   // If the result was an oop then unbox it and store it in
   357   // oop_temp where the garbage collector can see it before
   358   // we release the handle it might be protected by.
   359   if (handler->result_type() == &ffi_type_pointer) {
   360     if (result[0])
   361       istate->set_oop_temp(*(oop *) result[0]);
   362     else
   363       istate->set_oop_temp(NULL);
   364   }
   366   // Reset handle block
   367   thread->active_handles()->clear();
   369  unlock_unwind_and_return:
   371   // Unlock if necessary
   372   if (monitor) {
   373     BasicLock *lock = monitor->lock();
   374     markOop header = lock->displaced_header();
   375     oop rcvr = monitor->obj();
   376     monitor->set_obj(NULL);
   378     if (header != NULL) {
   379       if (Atomic::cmpxchg_ptr(header, rcvr->mark_addr(), lock) != lock) {
   380         monitor->set_obj(rcvr); {
   381           HandleMark hm(thread);
   382           CALL_VM_NOCHECK(InterpreterRuntime::monitorexit(thread, monitor));
   383         }
   384       }
   385     }
   386   }
   388  unwind_and_return:
   390   // Unwind the current activation
   391   thread->pop_zero_frame();
   393   // Pop our parameters
   394   stack->set_sp(stack->sp() + method->size_of_parameters());
   396   // Push our result
   397   if (!HAS_PENDING_EXCEPTION) {
   398     BasicType type = result_type_of(method);
   399     stack->set_sp(stack->sp() - type2size[type]);
   401     switch (type) {
   402     case T_VOID:
   403       break;
   405     case T_BOOLEAN:
   406 #ifndef VM_LITTLE_ENDIAN
   407       result[0] <<= (BitsPerWord - BitsPerByte);
   408 #endif
   409       SET_LOCALS_INT(*(jboolean *) result != 0, 0);
   410       break;
   412     case T_CHAR:
   413 #ifndef VM_LITTLE_ENDIAN
   414       result[0] <<= (BitsPerWord - BitsPerShort);
   415 #endif
   416       SET_LOCALS_INT(*(jchar *) result, 0);
   417       break;
   419     case T_BYTE:
   420 #ifndef VM_LITTLE_ENDIAN
   421       result[0] <<= (BitsPerWord - BitsPerByte);
   422 #endif
   423       SET_LOCALS_INT(*(jbyte *) result, 0);
   424       break;
   426     case T_SHORT:
   427 #ifndef VM_LITTLE_ENDIAN
   428       result[0] <<= (BitsPerWord - BitsPerShort);
   429 #endif
   430       SET_LOCALS_INT(*(jshort *) result, 0);
   431       break;
   433     case T_INT:
   434 #ifndef VM_LITTLE_ENDIAN
   435       result[0] <<= (BitsPerWord - BitsPerInt);
   436 #endif
   437       SET_LOCALS_INT(*(jint *) result, 0);
   438       break;
   440     case T_LONG:
   441       SET_LOCALS_LONG(*(jlong *) result, 0);
   442       break;
   444     case T_FLOAT:
   445       SET_LOCALS_FLOAT(*(jfloat *) result, 0);
   446       break;
   448     case T_DOUBLE:
   449       SET_LOCALS_DOUBLE(*(jdouble *) result, 0);
   450       break;
   452     case T_OBJECT:
   453     case T_ARRAY:
   454       SET_LOCALS_OBJECT(istate->oop_temp(), 0);
   455       break;
   457     default:
   458       ShouldNotReachHere();
   459     }
   460   }
   462   // No deoptimized frames on the stack
   463   return 0;
   464 }
   466 int CppInterpreter::accessor_entry(methodOop method, intptr_t UNUSED, TRAPS) {
   467   JavaThread *thread = (JavaThread *) THREAD;
   468   ZeroStack *stack = thread->zero_stack();
   469   intptr_t *locals = stack->sp();
   471   // Drop into the slow path if we need a safepoint check
   472   if (SafepointSynchronize::do_call_back()) {
   473     return normal_entry(method, 0, THREAD);
   474   }
   476   // Load the object pointer and drop into the slow path
   477   // if we have a NullPointerException
   478   oop object = LOCALS_OBJECT(0);
   479   if (object == NULL) {
   480     return normal_entry(method, 0, THREAD);
   481   }
   483   // Read the field index from the bytecode, which looks like this:
   484   //  0:  aload_0
   485   //  1:  getfield
   486   //  2:    index
   487   //  3:    index
   488   //  4:  ireturn/areturn
   489   // NB this is not raw bytecode: index is in machine order
   490   u1 *code = method->code_base();
   491   assert(code[0] == Bytecodes::_aload_0 &&
   492          code[1] == Bytecodes::_getfield &&
   493          (code[4] == Bytecodes::_ireturn ||
   494           code[4] == Bytecodes::_areturn), "should do");
   495   u2 index = Bytes::get_native_u2(&code[2]);
   497   // Get the entry from the constant pool cache, and drop into
   498   // the slow path if it has not been resolved
   499   constantPoolCacheOop cache = method->constants()->cache();
   500   ConstantPoolCacheEntry* entry = cache->entry_at(index);
   501   if (!entry->is_resolved(Bytecodes::_getfield)) {
   502     return normal_entry(method, 0, THREAD);
   503   }
   505   // Get the result and push it onto the stack
   506   switch (entry->flag_state()) {
   507   case ltos:
   508   case dtos:
   509     stack->overflow_check(1, CHECK_0);
   510     stack->alloc(wordSize);
   511     break;
   512   }
   513   if (entry->is_volatile()) {
   514     switch (entry->flag_state()) {
   515     case ctos:
   516       SET_LOCALS_INT(object->char_field_acquire(entry->f2()), 0);
   517       break;
   519     case btos:
   520       SET_LOCALS_INT(object->byte_field_acquire(entry->f2()), 0);
   521       break;
   523     case stos:
   524       SET_LOCALS_INT(object->short_field_acquire(entry->f2()), 0);
   525       break;
   527     case itos:
   528       SET_LOCALS_INT(object->int_field_acquire(entry->f2()), 0);
   529       break;
   531     case ltos:
   532       SET_LOCALS_LONG(object->long_field_acquire(entry->f2()), 0);
   533       break;
   535     case ftos:
   536       SET_LOCALS_FLOAT(object->float_field_acquire(entry->f2()), 0);
   537       break;
   539     case dtos:
   540       SET_LOCALS_DOUBLE(object->double_field_acquire(entry->f2()), 0);
   541       break;
   543     case atos:
   544       SET_LOCALS_OBJECT(object->obj_field_acquire(entry->f2()), 0);
   545       break;
   547     default:
   548       ShouldNotReachHere();
   549     }
   550   }
   551   else {
   552     switch (entry->flag_state()) {
   553     case ctos:
   554       SET_LOCALS_INT(object->char_field(entry->f2()), 0);
   555       break;
   557     case btos:
   558       SET_LOCALS_INT(object->byte_field(entry->f2()), 0);
   559       break;
   561     case stos:
   562       SET_LOCALS_INT(object->short_field(entry->f2()), 0);
   563       break;
   565     case itos:
   566       SET_LOCALS_INT(object->int_field(entry->f2()), 0);
   567       break;
   569     case ltos:
   570       SET_LOCALS_LONG(object->long_field(entry->f2()), 0);
   571       break;
   573     case ftos:
   574       SET_LOCALS_FLOAT(object->float_field(entry->f2()), 0);
   575       break;
   577     case dtos:
   578       SET_LOCALS_DOUBLE(object->double_field(entry->f2()), 0);
   579       break;
   581     case atos:
   582       SET_LOCALS_OBJECT(object->obj_field(entry->f2()), 0);
   583       break;
   585     default:
   586       ShouldNotReachHere();
   587     }
   588   }
   590   // No deoptimized frames on the stack
   591   return 0;
   592 }
   594 int CppInterpreter::empty_entry(methodOop method, intptr_t UNUSED, TRAPS) {
   595   JavaThread *thread = (JavaThread *) THREAD;
   596   ZeroStack *stack = thread->zero_stack();
   598   // Drop into the slow path if we need a safepoint check
   599   if (SafepointSynchronize::do_call_back()) {
   600     return normal_entry(method, 0, THREAD);
   601   }
   603   // Pop our parameters
   604   stack->set_sp(stack->sp() + method->size_of_parameters());
   606   // No deoptimized frames on the stack
   607   return 0;
   608 }
   610 InterpreterFrame *InterpreterFrame::build(const methodOop method, TRAPS) {
   611   JavaThread *thread = (JavaThread *) THREAD;
   612   ZeroStack *stack = thread->zero_stack();
   614   // Calculate the size of the frame we'll build, including
   615   // any adjustments to the caller's frame that we'll make.
   616   int extra_locals  = 0;
   617   int monitor_words = 0;
   618   int stack_words   = 0;
   620   if (!method->is_native()) {
   621     extra_locals = method->max_locals() - method->size_of_parameters();
   622     stack_words  = method->max_stack();
   623   }
   624   if (method->is_synchronized()) {
   625     monitor_words = frame::interpreter_frame_monitor_size();
   626   }
   627   stack->overflow_check(
   628     extra_locals + header_words + monitor_words + stack_words, CHECK_NULL);
   630   // Adjust the caller's stack frame to accomodate any additional
   631   // local variables we have contiguously with our parameters.
   632   for (int i = 0; i < extra_locals; i++)
   633     stack->push(0);
   635   intptr_t *locals;
   636   if (method->is_native())
   637     locals = stack->sp() + (method->size_of_parameters() - 1);
   638   else
   639     locals = stack->sp() + (method->max_locals() - 1);
   641   stack->push(0); // next_frame, filled in later
   642   intptr_t *fp = stack->sp();
   643   assert(fp - stack->sp() == next_frame_off, "should be");
   645   stack->push(INTERPRETER_FRAME);
   646   assert(fp - stack->sp() == frame_type_off, "should be");
   648   interpreterState istate =
   649     (interpreterState) stack->alloc(sizeof(BytecodeInterpreter));
   650   assert(fp - stack->sp() == istate_off, "should be");
   652   istate->set_locals(locals);
   653   istate->set_method(method);
   654   istate->set_self_link(istate);
   655   istate->set_prev_link(NULL);
   656   istate->set_thread(thread);
   657   istate->set_bcp(method->is_native() ? NULL : method->code_base());
   658   istate->set_constants(method->constants()->cache());
   659   istate->set_msg(BytecodeInterpreter::method_entry);
   660   istate->set_oop_temp(NULL);
   661   istate->set_mdx(NULL);
   662   istate->set_callee(NULL);
   664   istate->set_monitor_base((BasicObjectLock *) stack->sp());
   665   if (method->is_synchronized()) {
   666     BasicObjectLock *monitor =
   667       (BasicObjectLock *) stack->alloc(monitor_words * wordSize);
   668     oop object;
   669     if (method->is_static())
   670       object = method->constants()->pool_holder()->java_mirror();
   671     else
   672       object = (oop) locals[0];
   673     monitor->set_obj(object);
   674   }
   676   istate->set_stack_base(stack->sp());
   677   istate->set_stack(stack->sp() - 1);
   678   if (stack_words)
   679     stack->alloc(stack_words * wordSize);
   680   istate->set_stack_limit(stack->sp() - 1);
   682   return (InterpreterFrame *) fp;
   683 }
   685 int AbstractInterpreter::BasicType_as_index(BasicType type) {
   686   int i = 0;
   687   switch (type) {
   688     case T_BOOLEAN: i = 0; break;
   689     case T_CHAR   : i = 1; break;
   690     case T_BYTE   : i = 2; break;
   691     case T_SHORT  : i = 3; break;
   692     case T_INT    : i = 4; break;
   693     case T_LONG   : i = 5; break;
   694     case T_VOID   : i = 6; break;
   695     case T_FLOAT  : i = 7; break;
   696     case T_DOUBLE : i = 8; break;
   697     case T_OBJECT : i = 9; break;
   698     case T_ARRAY  : i = 9; break;
   699     default       : ShouldNotReachHere();
   700   }
   701   assert(0 <= i && i < AbstractInterpreter::number_of_result_handlers,
   702          "index out of bounds");
   703   return i;
   704 }
   706 BasicType CppInterpreter::result_type_of(methodOop method) {
   707   BasicType t;
   708   switch (method->result_index()) {
   709     case 0 : t = T_BOOLEAN; break;
   710     case 1 : t = T_CHAR;    break;
   711     case 2 : t = T_BYTE;    break;
   712     case 3 : t = T_SHORT;   break;
   713     case 4 : t = T_INT;     break;
   714     case 5 : t = T_LONG;    break;
   715     case 6 : t = T_VOID;    break;
   716     case 7 : t = T_FLOAT;   break;
   717     case 8 : t = T_DOUBLE;  break;
   718     case 9 : t = T_OBJECT;  break;
   719     default: ShouldNotReachHere();
   720   }
   721   assert(AbstractInterpreter::BasicType_as_index(t) == method->result_index(),
   722          "out of step with AbstractInterpreter::BasicType_as_index");
   723   return t;
   724 }
   726 address InterpreterGenerator::generate_empty_entry() {
   727   if (!UseFastEmptyMethods)
   728     return NULL;
   730   return generate_entry((address) CppInterpreter::empty_entry);
   731 }
   733 address InterpreterGenerator::generate_accessor_entry() {
   734   if (!UseFastAccessorMethods)
   735     return NULL;
   737   return generate_entry((address) CppInterpreter::accessor_entry);
   738 }
   740 address InterpreterGenerator::generate_native_entry(bool synchronized) {
   741   assert(synchronized == false, "should be");
   743   return generate_entry((address) CppInterpreter::native_entry);
   744 }
   746 address InterpreterGenerator::generate_normal_entry(bool synchronized) {
   747   assert(synchronized == false, "should be");
   749   return generate_entry((address) CppInterpreter::normal_entry);
   750 }
   752 address AbstractInterpreterGenerator::generate_method_entry(
   753     AbstractInterpreter::MethodKind kind) {
   754   address entry_point = NULL;
   756   switch (kind) {
   757   case Interpreter::zerolocals:
   758   case Interpreter::zerolocals_synchronized:
   759     break;
   761   case Interpreter::native:
   762     entry_point = ((InterpreterGenerator*) this)->generate_native_entry(false);
   763     break;
   765   case Interpreter::native_synchronized:
   766     entry_point = ((InterpreterGenerator*) this)->generate_native_entry(false);
   767     break;
   769   case Interpreter::empty:
   770     entry_point = ((InterpreterGenerator*) this)->generate_empty_entry();
   771     break;
   773   case Interpreter::accessor:
   774     entry_point = ((InterpreterGenerator*) this)->generate_accessor_entry();
   775     break;
   777   case Interpreter::abstract:
   778     entry_point = ((InterpreterGenerator*) this)->generate_abstract_entry();
   779     break;
   781   case Interpreter::method_handle:
   782     entry_point = ((InterpreterGenerator*) this)->generate_method_handle_entry();
   783     break;
   785   case Interpreter::java_lang_math_sin:
   786   case Interpreter::java_lang_math_cos:
   787   case Interpreter::java_lang_math_tan:
   788   case Interpreter::java_lang_math_abs:
   789   case Interpreter::java_lang_math_log:
   790   case Interpreter::java_lang_math_log10:
   791   case Interpreter::java_lang_math_sqrt:
   792     entry_point = ((InterpreterGenerator*) this)->generate_math_entry(kind);
   793     break;
   795   default:
   796     ShouldNotReachHere();
   797   }
   799   if (entry_point == NULL)
   800     entry_point = ((InterpreterGenerator*) this)->generate_normal_entry(false);
   802   return entry_point;
   803 }
   805 InterpreterGenerator::InterpreterGenerator(StubQueue* code)
   806  : CppInterpreterGenerator(code) {
   807    generate_all();
   808 }
   810 // Deoptimization helpers
   812 InterpreterFrame *InterpreterFrame::build(int size, TRAPS) {
   813   ZeroStack *stack = ((JavaThread *) THREAD)->zero_stack();
   815   int size_in_words = size >> LogBytesPerWord;
   816   assert(size_in_words * wordSize == size, "unaligned");
   817   assert(size_in_words >= header_words, "too small");
   818   stack->overflow_check(size_in_words, CHECK_NULL);
   820   stack->push(0); // next_frame, filled in later
   821   intptr_t *fp = stack->sp();
   822   assert(fp - stack->sp() == next_frame_off, "should be");
   824   stack->push(INTERPRETER_FRAME);
   825   assert(fp - stack->sp() == frame_type_off, "should be");
   827   interpreterState istate =
   828     (interpreterState) stack->alloc(sizeof(BytecodeInterpreter));
   829   assert(fp - stack->sp() == istate_off, "should be");
   830   istate->set_self_link(NULL); // mark invalid
   832   stack->alloc((size_in_words - header_words) * wordSize);
   834   return (InterpreterFrame *) fp;
   835 }
   837 int AbstractInterpreter::layout_activation(methodOop method,
   838                                            int       tempcount,
   839                                            int       popframe_extra_args,
   840                                            int       moncount,
   841                                            int       callee_param_count,
   842                                            int       callee_locals,
   843                                            frame*    caller,
   844                                            frame*    interpreter_frame,
   845                                            bool      is_top_frame) {
   846   assert(popframe_extra_args == 0, "what to do?");
   847   assert(!is_top_frame || (!callee_locals && !callee_param_count),
   848          "top frame should have no caller");
   850   // This code must exactly match what InterpreterFrame::build
   851   // does (the full InterpreterFrame::build, that is, not the
   852   // one that creates empty frames for the deoptimizer).
   853   //
   854   // If interpreter_frame is not NULL then it will be filled in.
   855   // It's size is determined by a previous call to this method,
   856   // so it should be correct.
   857   //
   858   // Note that tempcount is the current size of the expression
   859   // stack.  For top most frames we will allocate a full sized
   860   // expression stack and not the trimmed version that non-top
   861   // frames have.
   863   int header_words        = InterpreterFrame::header_words;
   864   int monitor_words       = moncount * frame::interpreter_frame_monitor_size();
   865   int stack_words         = is_top_frame ? method->max_stack() : tempcount;
   866   int callee_extra_locals = callee_locals - callee_param_count;
   868   if (interpreter_frame) {
   869     intptr_t *locals        = interpreter_frame->fp() + method->max_locals();
   870     interpreterState istate = interpreter_frame->get_interpreterState();
   871     intptr_t *monitor_base  = (intptr_t*) istate;
   872     intptr_t *stack_base    = monitor_base - monitor_words;
   873     intptr_t *stack         = stack_base - tempcount - 1;
   875     BytecodeInterpreter::layout_interpreterState(istate,
   876                                                  caller,
   877                                                  NULL,
   878                                                  method,
   879                                                  locals,
   880                                                  stack,
   881                                                  stack_base,
   882                                                  monitor_base,
   883                                                  NULL,
   884                                                  is_top_frame);
   885   }
   886   return header_words + monitor_words + stack_words + callee_extra_locals;
   887 }
   889 void BytecodeInterpreter::layout_interpreterState(interpreterState istate,
   890                                                   frame*    caller,
   891                                                   frame*    current,
   892                                                   methodOop method,
   893                                                   intptr_t* locals,
   894                                                   intptr_t* stack,
   895                                                   intptr_t* stack_base,
   896                                                   intptr_t* monitor_base,
   897                                                   intptr_t* frame_bottom,
   898                                                   bool      is_top_frame) {
   899   istate->set_locals(locals);
   900   istate->set_method(method);
   901   istate->set_self_link(istate);
   902   istate->set_prev_link(NULL);
   903   // thread will be set by a hacky repurposing of frame::patch_pc()
   904   // bcp will be set by vframeArrayElement::unpack_on_stack()
   905   istate->set_constants(method->constants()->cache());
   906   istate->set_msg(BytecodeInterpreter::method_resume);
   907   istate->set_bcp_advance(0);
   908   istate->set_oop_temp(NULL);
   909   istate->set_mdx(NULL);
   910   if (caller->is_interpreted_frame()) {
   911     interpreterState prev = caller->get_interpreterState();
   912     prev->set_callee(method);
   913     if (*prev->bcp() == Bytecodes::_invokeinterface)
   914       prev->set_bcp_advance(5);
   915     else
   916       prev->set_bcp_advance(3);
   917   }
   918   istate->set_callee(NULL);
   919   istate->set_monitor_base((BasicObjectLock *) monitor_base);
   920   istate->set_stack_base(stack_base);
   921   istate->set_stack(stack);
   922   istate->set_stack_limit(stack_base - method->max_stack() - 1);
   923 }
   925 address CppInterpreter::return_entry(TosState state, int length) {
   926   ShouldNotCallThis();
   927 }
   929 address CppInterpreter::deopt_entry(TosState state, int length) {
   930   return NULL;
   931 }
   933 // Helper for (runtime) stack overflow checks
   935 int AbstractInterpreter::size_top_interpreter_activation(methodOop method) {
   936   return 0;
   937 }
   939 // Helper for figuring out if frames are interpreter frames
   941 bool CppInterpreter::contains(address pc) {
   942 #ifdef PRODUCT
   943   ShouldNotCallThis();
   944 #else
   945   return false; // make frame::print_value_on work
   946 #endif // !PRODUCT
   947 }
   949 // Result handlers and convertors
   951 address CppInterpreterGenerator::generate_result_handler_for(
   952     BasicType type) {
   953   assembler()->advance(1);
   954   return ShouldNotCallThisStub();
   955 }
   957 address CppInterpreterGenerator::generate_tosca_to_stack_converter(
   958     BasicType type) {
   959   assembler()->advance(1);
   960   return ShouldNotCallThisStub();
   961 }
   963 address CppInterpreterGenerator::generate_stack_to_stack_converter(
   964     BasicType type) {
   965   assembler()->advance(1);
   966   return ShouldNotCallThisStub();
   967 }
   969 address CppInterpreterGenerator::generate_stack_to_native_abi_converter(
   970     BasicType type) {
   971   assembler()->advance(1);
   972   return ShouldNotCallThisStub();
   973 }
   975 #endif // CC_INTERP

mercurial