src/cpu/zero/vm/cppInterpreter_zero.cpp

changeset 1814
f9271ff9d324
parent 1780
747d26efc5fa
child 1860
0c5b3cf3c1f5
     1.1 --- a/src/cpu/zero/vm/cppInterpreter_zero.cpp	Wed Apr 14 15:30:13 2010 -0700
     1.2 +++ b/src/cpu/zero/vm/cppInterpreter_zero.cpp	Thu Apr 15 02:40:12 2010 -0700
     1.3 @@ -39,21 +39,9 @@
     1.4  
     1.5  void CppInterpreter::normal_entry(methodOop method, intptr_t UNUSED, TRAPS) {
     1.6    JavaThread *thread = (JavaThread *) THREAD;
     1.7 -  ZeroStack *stack = thread->zero_stack();
     1.8 -
     1.9 -  // Adjust the caller's stack frame to accomodate any additional
    1.10 -  // local variables we have contiguously with our parameters.
    1.11 -  int extra_locals = method->max_locals() - method->size_of_parameters();
    1.12 -  if (extra_locals > 0) {
    1.13 -    if (extra_locals > stack->available_words()) {
    1.14 -      Unimplemented();
    1.15 -    }
    1.16 -    for (int i = 0; i < extra_locals; i++)
    1.17 -      stack->push(0);
    1.18 -  }
    1.19  
    1.20    // Allocate and initialize our frame.
    1.21 -  InterpreterFrame *frame = InterpreterFrame::build(stack, method, thread);
    1.22 +  InterpreterFrame *frame = InterpreterFrame::build(method, CHECK);
    1.23    thread->push_zero_frame(frame);
    1.24  
    1.25    // Execute those bytecodes!
    1.26 @@ -76,12 +64,6 @@
    1.27    intptr_t *result = NULL;
    1.28    int result_slots = 0;
    1.29  
    1.30 -  // Check we're not about to run out of stack
    1.31 -  if (stack_overflow_imminent(thread)) {
    1.32 -    CALL_VM_NOCHECK(InterpreterRuntime::throw_StackOverflowError(thread));
    1.33 -    goto unwind_and_return;
    1.34 -  }
    1.35 -
    1.36    while (true) {
    1.37      // We can set up the frame anchor with everything we want at
    1.38      // this point as we are thread_in_Java and no safepoints can
    1.39 @@ -123,9 +105,9 @@
    1.40        int monitor_words = frame::interpreter_frame_monitor_size();
    1.41  
    1.42        // Allocate the space
    1.43 -      if (monitor_words > stack->available_words()) {
    1.44 -        Unimplemented();
    1.45 -      }
    1.46 +      stack->overflow_check(monitor_words, THREAD);
    1.47 +      if (HAS_PENDING_EXCEPTION)
    1.48 +        break;
    1.49        stack->alloc(monitor_words * wordSize);
    1.50  
    1.51        // Move the expression stack contents
    1.52 @@ -172,8 +154,6 @@
    1.53      }
    1.54    }
    1.55  
    1.56 - unwind_and_return:
    1.57 -
    1.58    // Unwind the current frame
    1.59    thread->pop_zero_frame();
    1.60  
    1.61 @@ -193,17 +173,11 @@
    1.62    ZeroStack *stack = thread->zero_stack();
    1.63  
    1.64    // Allocate and initialize our frame
    1.65 -  InterpreterFrame *frame = InterpreterFrame::build(stack, method, thread);
    1.66 +  InterpreterFrame *frame = InterpreterFrame::build(method, CHECK);
    1.67    thread->push_zero_frame(frame);
    1.68    interpreterState istate = frame->interpreter_state();
    1.69    intptr_t *locals = istate->locals();
    1.70  
    1.71 -  // Check we're not about to run out of stack
    1.72 -  if (stack_overflow_imminent(thread)) {
    1.73 -    CALL_VM_NOCHECK(InterpreterRuntime::throw_StackOverflowError(thread));
    1.74 -    goto unwind_and_return;
    1.75 -  }
    1.76 -
    1.77    // Update the invocation counter
    1.78    if ((UseCompiler || CountCompiledCalls) && !method->is_synchronized()) {
    1.79      InvocationCounter *counter = method->invocation_counter();
    1.80 @@ -264,9 +238,10 @@
    1.81    assert(function != NULL, "should be set if signature handler is");
    1.82  
    1.83    // Build the argument list
    1.84 -  if (handler->argument_count() * 2 > stack->available_words()) {
    1.85 -    Unimplemented();
    1.86 -  }
    1.87 +  stack->overflow_check(handler->argument_count() * 2, THREAD);
    1.88 +  if (HAS_PENDING_EXCEPTION)
    1.89 +    goto unlock_unwind_and_return;
    1.90 +
    1.91    void **arguments;
    1.92    void *mirror; {
    1.93      arguments =
    1.94 @@ -503,9 +478,7 @@
    1.95    switch (entry->flag_state()) {
    1.96    case ltos:
    1.97    case dtos:
    1.98 -    if (stack->available_words() < 1) {
    1.99 -      Unimplemented();
   1.100 -    }
   1.101 +    stack->overflow_check(1, CHECK);
   1.102      stack->alloc(wordSize);
   1.103      break;
   1.104    }
   1.105 @@ -601,39 +574,30 @@
   1.106    stack->set_sp(stack->sp() + method->size_of_parameters());
   1.107  }
   1.108  
   1.109 -bool CppInterpreter::stack_overflow_imminent(JavaThread *thread) {
   1.110 -  // How is the ABI stack?
   1.111 -  address stack_top = thread->stack_base() - thread->stack_size();
   1.112 -  int free_stack = os::current_stack_pointer() - stack_top;
   1.113 -  if (free_stack < StackShadowPages * os::vm_page_size()) {
   1.114 -    return true;
   1.115 +InterpreterFrame *InterpreterFrame::build(const methodOop method, TRAPS) {
   1.116 +  JavaThread *thread = (JavaThread *) THREAD;
   1.117 +  ZeroStack *stack = thread->zero_stack();
   1.118 +
   1.119 +  // Calculate the size of the frame we'll build, including
   1.120 +  // any adjustments to the caller's frame that we'll make.
   1.121 +  int extra_locals  = 0;
   1.122 +  int monitor_words = 0;
   1.123 +  int stack_words   = 0;
   1.124 +
   1.125 +  if (!method->is_native()) {
   1.126 +    extra_locals = method->max_locals() - method->size_of_parameters();
   1.127 +    stack_words  = method->max_stack();
   1.128    }
   1.129 +  if (method->is_synchronized()) {
   1.130 +    monitor_words = frame::interpreter_frame_monitor_size();
   1.131 +  }
   1.132 +  stack->overflow_check(
   1.133 +    extra_locals + header_words + monitor_words + stack_words, CHECK_NULL);
   1.134  
   1.135 -  // How is the Zero stack?
   1.136 -  // Throwing a StackOverflowError involves a VM call, which means
   1.137 -  // we need a frame on the stack.  We should be checking here to
   1.138 -  // ensure that methods we call have enough room to install the
   1.139 -  // largest possible frame, but that's more than twice the size
   1.140 -  // of the entire Zero stack we get by default, so we just check
   1.141 -  // we have *some* space instead...
   1.142 -  free_stack = thread->zero_stack()->available_words() * wordSize;
   1.143 -  if (free_stack < StackShadowPages * os::vm_page_size()) {
   1.144 -    return true;
   1.145 -  }
   1.146 -
   1.147 -  return false;
   1.148 -}
   1.149 -
   1.150 -InterpreterFrame *InterpreterFrame::build(ZeroStack*       stack,
   1.151 -                                          const methodOop  method,
   1.152 -                                          JavaThread*      thread) {
   1.153 -  int monitor_words =
   1.154 -    method->is_synchronized() ? frame::interpreter_frame_monitor_size() : 0;
   1.155 -  int stack_words = method->is_native() ? 0 : method->max_stack();
   1.156 -
   1.157 -  if (header_words + monitor_words + stack_words > stack->available_words()) {
   1.158 -    Unimplemented();
   1.159 -  }
   1.160 +  // Adjust the caller's stack frame to accomodate any additional
   1.161 +  // local variables we have contiguously with our parameters.
   1.162 +  for (int i = 0; i < extra_locals; i++)
   1.163 +    stack->push(0);
   1.164  
   1.165    intptr_t *locals;
   1.166    if (method->is_native())
   1.167 @@ -812,14 +776,13 @@
   1.168  
   1.169  // Deoptimization helpers
   1.170  
   1.171 -InterpreterFrame *InterpreterFrame::build(ZeroStack* stack, int size) {
   1.172 +InterpreterFrame *InterpreterFrame::build(int size, TRAPS) {
   1.173 +  ZeroStack *stack = ((JavaThread *) THREAD)->zero_stack();
   1.174 +
   1.175    int size_in_words = size >> LogBytesPerWord;
   1.176    assert(size_in_words * wordSize == size, "unaligned");
   1.177    assert(size_in_words >= header_words, "too small");
   1.178 -
   1.179 -  if (size_in_words > stack->available_words()) {
   1.180 -    Unimplemented();
   1.181 -  }
   1.182 +  stack->overflow_check(size_in_words, CHECK_NULL);
   1.183  
   1.184    stack->push(0); // next_frame, filled in later
   1.185    intptr_t *fp = stack->sp();

mercurial