1 /*
   2  * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright 2007, 2008 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 #ifndef CPU_ZERO_VM_BYTECODEINTERPRETER_ZERO_HPP
  27 #define CPU_ZERO_VM_BYTECODEINTERPRETER_ZERO_HPP
  28 
  29 // Platform specific for C++ based Interpreter
  30 
  31 #if defined(PPC) || defined(SPARC) || defined(IA64)
  32 #define LOTS_OF_REGS   // Use plenty of registers
  33 #else
  34 #undef LOTS_OF_REGS    // Loser platforms
  35 #endif
  36 
  37  private:
  38   interpreterState _self_link;
  39 
  40  public:
  41   inline void set_locals(intptr_t* new_locals) {
  42     _locals = new_locals;
  43   }
  44   inline void set_method(methodOop new_method) {
  45     _method = new_method;
  46   }
  47   inline interpreterState self_link() {
  48     return _self_link;
  49   }
  50   inline void set_self_link(interpreterState new_self_link) {
  51     _self_link = new_self_link;
  52   }
  53   inline interpreterState prev_link() {
  54     return _prev_link;
  55   }
  56   inline void set_prev_link(interpreterState new_prev_link) {
  57     _prev_link = new_prev_link;
  58   }
  59   inline void set_stack_limit(intptr_t* new_stack_limit) {
  60     _stack_limit = new_stack_limit;
  61   }
  62   inline void set_stack_base(intptr_t* new_stack_base) {
  63     _stack_base = new_stack_base;
  64   }
  65   inline void set_monitor_base(BasicObjectLock *new_monitor_base) {
  66     _monitor_base = new_monitor_base;
  67   }
  68   inline void set_thread(JavaThread* new_thread) {
  69     _thread = new_thread;
  70   }
  71   inline void set_constants(constantPoolCacheOop new_constants) {
  72     _constants = new_constants;
  73   }
  74   inline oop oop_temp() {
  75     return _oop_temp;
  76   }
  77   inline oop *oop_temp_addr() {
  78     return &_oop_temp;
  79   }
  80   inline void set_oop_temp(oop new_oop_temp) {
  81     _oop_temp = new_oop_temp;
  82   }
  83   inline address callee_entry_point() {
  84     return _result._to_call._callee_entry_point;
  85   }
  86   inline address osr_buf() {
  87     return _result._osr._osr_buf;
  88   }
  89   inline address osr_entry() {
  90     return _result._osr._osr_entry;
  91   }
  92 
  93  public:
  94   const char *name_of_field_at_address(address addr);
  95 
  96 // The frame manager handles this
  97 #define SET_LAST_JAVA_FRAME()
  98 #define RESET_LAST_JAVA_FRAME()
  99 
 100 // ZeroStack Implementation
 101 
 102 #undef STACK_INT
 103 #undef STACK_FLOAT
 104 #undef STACK_ADDR
 105 #undef STACK_OBJECT
 106 #undef STACK_DOUBLE
 107 #undef STACK_LONG
 108 
 109 #define GET_STACK_SLOT(offset)    (*((intptr_t*) &topOfStack[-(offset)]))
 110 #define STACK_SLOT(offset)    ((address) &topOfStack[-(offset)])
 111 #define STACK_ADDR(offset)    (*((address *) &topOfStack[-(offset)]))
 112 #define STACK_INT(offset)     (*((jint*) &topOfStack[-(offset)]))
 113 #define STACK_FLOAT(offset)   (*((jfloat *) &topOfStack[-(offset)]))
 114 #define STACK_OBJECT(offset)  (*((oop *) &topOfStack [-(offset)]))
 115 #define STACK_DOUBLE(offset)  (((VMJavaVal64*) &topOfStack[-(offset)])->d)
 116 #define STACK_LONG(offset)    (((VMJavaVal64 *) &topOfStack[-(offset)])->l)
 117 
 118 #define SET_STACK_SLOT(value, offset)   (*(intptr_t*)&topOfStack[-(offset)] = *(intptr_t*)(value))
 119 #define SET_STACK_ADDR(value, offset)   (*((address *)&topOfStack[-(offset)]) = (value))
 120 #define SET_STACK_INT(value, offset)    (*((jint *)&topOfStack[-(offset)]) = (value))
 121 #define SET_STACK_FLOAT(value, offset)  (*((jfloat *)&topOfStack[-(offset)]) = (value))
 122 #define SET_STACK_OBJECT(value, offset) (*((oop *)&topOfStack[-(offset)]) = (value))
 123 #define SET_STACK_DOUBLE(value, offset) (((VMJavaVal64*)&topOfStack[-(offset)])->d = (value))
 124 #define SET_STACK_DOUBLE_FROM_ADDR(addr, offset) (((VMJavaVal64*)&topOfStack[-(offset)])->d =  \
 125                                                  ((VMJavaVal64*)(addr))->d)
 126 #define SET_STACK_LONG(value, offset)   (((VMJavaVal64*)&topOfStack[-(offset)])->l = (value))
 127 #define SET_STACK_LONG_FROM_ADDR(addr, offset)   (((VMJavaVal64*)&topOfStack[-(offset)])->l =  \
 128                                                  ((VMJavaVal64*)(addr))->l)
 129 // JavaLocals implementation
 130 
 131 #define LOCALS_SLOT(offset)    ((intptr_t*)&locals[-(offset)])
 132 #define LOCALS_ADDR(offset)    ((address)locals[-(offset)])
 133 #define LOCALS_INT(offset)     (*((jint*)&locals[-(offset)]))
 134 #define LOCALS_FLOAT(offset)   (*((jfloat*)&locals[-(offset)]))
 135 #define LOCALS_OBJECT(offset)  ((oop)locals[-(offset)])
 136 #define LOCALS_DOUBLE(offset)  (((VMJavaVal64*)&locals[-((offset) + 1)])->d)
 137 #define LOCALS_LONG(offset)    (((VMJavaVal64*)&locals[-((offset) + 1)])->l)
 138 #define LOCALS_LONG_AT(offset) (((address)&locals[-((offset) + 1)]))
 139 #define LOCALS_DOUBLE_AT(offset) (((address)&locals[-((offset) + 1)]))
 140 
 141 #define SET_LOCALS_SLOT(value, offset)    (*(intptr_t*)&locals[-(offset)] = *(intptr_t *)(value))
 142 #define SET_LOCALS_ADDR(value, offset)    (*((address *)&locals[-(offset)]) = (value))
 143 #define SET_LOCALS_INT(value, offset)     (*((jint *)&locals[-(offset)]) = (value))
 144 #define SET_LOCALS_FLOAT(value, offset)   (*((jfloat *)&locals[-(offset)]) = (value))
 145 #define SET_LOCALS_OBJECT(value, offset)  (*((oop *)&locals[-(offset)]) = (value))
 146 #define SET_LOCALS_DOUBLE(value, offset)  (((VMJavaVal64*)&locals[-((offset)+1)])->d = (value))
 147 #define SET_LOCALS_LONG(value, offset)    (((VMJavaVal64*)&locals[-((offset)+1)])->l = (value))
 148 #define SET_LOCALS_DOUBLE_FROM_ADDR(addr, offset) (((VMJavaVal64*)&locals[-((offset)+1)])->d = \
 149                                                   ((VMJavaVal64*)(addr))->d)
 150 #define SET_LOCALS_LONG_FROM_ADDR(addr, offset) (((VMJavaVal64*)&locals[-((offset)+1)])->l = \
 151                                                 ((VMJavaVal64*)(addr))->l)
 152 
 153 #endif // CPU_ZERO_VM_BYTECODEINTERPRETER_ZERO_HPP