1 /*
   2  * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright 2007, 2008, 2009, 2010, 2011 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  */
  25 
  26 #include "precompiled.hpp"
  27 #include "interpreter/bytecodeInterpreter.hpp"
  28 #include "interpreter/cppInterpreter.hpp"
  29 #include "runtime/frame.inline.hpp"
  30 #include "utilities/globalDefinitions.hpp"
  31 
  32 bool AbstractInterpreter::can_be_compiled(methodHandle m) {
  33   return true;
  34 }
  35 
  36 int AbstractInterpreter::BasicType_as_index(BasicType type) {
  37   int i = 0;
  38   switch (type) {
  39     case T_BOOLEAN: i = 0; break;
  40     case T_CHAR   : i = 1; break;
  41     case T_BYTE   : i = 2; break;
  42     case T_SHORT  : i = 3; break;
  43     case T_INT    : i = 4; break;
  44     case T_LONG   : i = 5; break;
  45     case T_VOID   : i = 6; break;
  46     case T_FLOAT  : i = 7; break;
  47     case T_DOUBLE : i = 8; break;
  48     case T_OBJECT : i = 9; break;
  49     case T_ARRAY  : i = 9; break;
  50     default       : ShouldNotReachHere();
  51   }
  52   assert(0 <= i && i < AbstractInterpreter::number_of_result_handlers,
  53          "index out of bounds");
  54   return i;
  55 }
  56 
  57 // Deoptimization helpers
  58 
  59 int AbstractInterpreter::size_activation(int       max_stack,
  60                                          int       tempcount,
  61                                          int       extra_args,
  62                                          int       moncount,
  63                                          int       callee_param_count,
  64                                          int       callee_locals,
  65                                          bool      is_top_frame) {
  66   int header_words        = InterpreterFrame::header_words;
  67   int monitor_words       = moncount * frame::interpreter_frame_monitor_size();
  68   int stack_words         = is_top_frame ? max_stack : tempcount;
  69   int callee_extra_locals = callee_locals - callee_param_count;
  70 
  71   return header_words + monitor_words + stack_words + callee_extra_locals;
  72 }
  73 
  74 void AbstractInterpreter::layout_activation(Method* method,
  75                                             int       tempcount,
  76                                             int       popframe_extra_args,
  77                                             int       moncount,
  78                                             int       caller_actual_parameters,
  79                                             int       callee_param_count,
  80                                             int       callee_locals,
  81                                             frame*    caller,
  82                                             frame*    interpreter_frame,
  83                                             bool      is_top_frame,
  84                                             bool      is_bottom_frame) {
  85   assert(popframe_extra_args == 0, "what to do?");
  86   assert(!is_top_frame || (!callee_locals && !callee_param_count),
  87          "top frame should have no caller");
  88 
  89   // This code must exactly match what InterpreterFrame::build
  90   // does (the full InterpreterFrame::build, that is, not the
  91   // one that creates empty frames for the deoptimizer).
  92   //
  93   // interpreter_frame will be filled in.  It's size is determined by
  94   // a previous call to the size_activation() method,
  95   //
  96   // Note that tempcount is the current size of the expression
  97   // stack.  For top most frames we will allocate a full sized
  98   // expression stack and not the trimmed version that non-top
  99   // frames have.
 100 
 101   int monitor_words       = moncount * frame::interpreter_frame_monitor_size();
 102   intptr_t *locals        = interpreter_frame->fp() + method->max_locals();
 103   interpreterState istate = interpreter_frame->get_interpreterState();
 104   intptr_t *monitor_base  = (intptr_t*) istate;
 105   intptr_t *stack_base    = monitor_base - monitor_words;
 106   intptr_t *stack         = stack_base - tempcount - 1;
 107 
 108   BytecodeInterpreter::layout_interpreterState(istate,
 109                                                caller,
 110                                                NULL,
 111                                                method,
 112                                                locals,
 113                                                stack,
 114                                                stack_base,
 115                                                monitor_base,
 116                                                NULL,
 117                                                is_top_frame);
 118 }
 119 
 120 // Helper for (runtime) stack overflow checks
 121 
 122 int AbstractInterpreter::size_top_interpreter_activation(Method* method) {
 123   return 0;
 124 }