src/share/vm/shark/sharkBlock.hpp

Wed, 11 Aug 2010 05:51:21 -0700

author
twisti
date
Wed, 11 Aug 2010 05:51:21 -0700
changeset 2047
d2ede61b7a12
child 2314
f95d63e2154a
permissions
-rw-r--r--

6976186: integrate Shark HotSpot changes
Summary: Shark is a JIT compiler for Zero that uses the LLVM compiler infrastructure.
Reviewed-by: kvn, twisti
Contributed-by: Gary Benson <gbenson@redhat.com>

twisti@2047 1 /*
twisti@2047 2 * Copyright (c) 1999, 2007, Oracle and/or its affiliates. All rights reserved.
twisti@2047 3 * Copyright 2008, 2009 Red Hat, Inc.
twisti@2047 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
twisti@2047 5 *
twisti@2047 6 * This code is free software; you can redistribute it and/or modify it
twisti@2047 7 * under the terms of the GNU General Public License version 2 only, as
twisti@2047 8 * published by the Free Software Foundation.
twisti@2047 9 *
twisti@2047 10 * This code is distributed in the hope that it will be useful, but WITHOUT
twisti@2047 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
twisti@2047 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
twisti@2047 13 * version 2 for more details (a copy is included in the LICENSE file that
twisti@2047 14 * accompanied this code).
twisti@2047 15 *
twisti@2047 16 * You should have received a copy of the GNU General Public License version
twisti@2047 17 * 2 along with this work; if not, write to the Free Software Foundation,
twisti@2047 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
twisti@2047 19 *
twisti@2047 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
twisti@2047 21 * or visit www.oracle.com if you need additional information or have any
twisti@2047 22 * questions.
twisti@2047 23 *
twisti@2047 24 */
twisti@2047 25
twisti@2047 26 class SharkState;
twisti@2047 27
twisti@2047 28 class SharkBlock : public SharkTargetInvariants {
twisti@2047 29 protected:
twisti@2047 30 SharkBlock(const SharkTargetInvariants* parent)
twisti@2047 31 : SharkTargetInvariants(parent),
twisti@2047 32 _iter(target()),
twisti@2047 33 _current_state(NULL) {}
twisti@2047 34
twisti@2047 35 SharkBlock(const SharkCompileInvariants* parent, ciMethod* target)
twisti@2047 36 : SharkTargetInvariants(parent, target),
twisti@2047 37 _iter(target),
twisti@2047 38 _current_state(NULL) {}
twisti@2047 39
twisti@2047 40 private:
twisti@2047 41 ciBytecodeStream _iter;
twisti@2047 42 SharkState* _current_state;
twisti@2047 43
twisti@2047 44 public:
twisti@2047 45 ciBytecodeStream* iter() {
twisti@2047 46 return &_iter;
twisti@2047 47 }
twisti@2047 48 Bytecodes::Code bc() {
twisti@2047 49 return iter()->cur_bc();
twisti@2047 50 }
twisti@2047 51 int bci() {
twisti@2047 52 return iter()->cur_bci();
twisti@2047 53 }
twisti@2047 54
twisti@2047 55 // Entry state
twisti@2047 56 protected:
twisti@2047 57 virtual SharkState* entry_state();
twisti@2047 58
twisti@2047 59 // Current state
twisti@2047 60 private:
twisti@2047 61 SharkState* initial_current_state();
twisti@2047 62
twisti@2047 63 public:
twisti@2047 64 SharkState* current_state() {
twisti@2047 65 if (_current_state == NULL)
twisti@2047 66 set_current_state(initial_current_state());
twisti@2047 67 return _current_state;
twisti@2047 68 }
twisti@2047 69
twisti@2047 70 protected:
twisti@2047 71 void set_current_state(SharkState* current_state) {
twisti@2047 72 _current_state = current_state;
twisti@2047 73 }
twisti@2047 74
twisti@2047 75 // Local variables
twisti@2047 76 protected:
twisti@2047 77 SharkValue* local(int index) {
twisti@2047 78 SharkValue *value = current_state()->local(index);
twisti@2047 79 assert(value != NULL, "shouldn't be");
twisti@2047 80 assert(value->is_one_word() ||
twisti@2047 81 (index + 1 < max_locals() &&
twisti@2047 82 current_state()->local(index + 1) == NULL), "should be");
twisti@2047 83 return value;
twisti@2047 84 }
twisti@2047 85 void set_local(int index, SharkValue* value) {
twisti@2047 86 assert(value != NULL, "shouldn't be");
twisti@2047 87 current_state()->set_local(index, value);
twisti@2047 88 if (value->is_two_word())
twisti@2047 89 current_state()->set_local(index + 1, NULL);
twisti@2047 90 }
twisti@2047 91
twisti@2047 92 // Expression stack (raw)
twisti@2047 93 protected:
twisti@2047 94 void xpush(SharkValue* value) {
twisti@2047 95 current_state()->push(value);
twisti@2047 96 }
twisti@2047 97 SharkValue* xpop() {
twisti@2047 98 return current_state()->pop();
twisti@2047 99 }
twisti@2047 100 SharkValue* xstack(int slot) {
twisti@2047 101 SharkValue *value = current_state()->stack(slot);
twisti@2047 102 assert(value != NULL, "shouldn't be");
twisti@2047 103 assert(value->is_one_word() ||
twisti@2047 104 (slot > 0 &&
twisti@2047 105 current_state()->stack(slot - 1) == NULL), "should be");
twisti@2047 106 return value;
twisti@2047 107 }
twisti@2047 108 int xstack_depth() {
twisti@2047 109 return current_state()->stack_depth();
twisti@2047 110 }
twisti@2047 111
twisti@2047 112 // Expression stack (cooked)
twisti@2047 113 protected:
twisti@2047 114 void push(SharkValue* value) {
twisti@2047 115 assert(value != NULL, "shouldn't be");
twisti@2047 116 xpush(value);
twisti@2047 117 if (value->is_two_word())
twisti@2047 118 xpush(NULL);
twisti@2047 119 }
twisti@2047 120 SharkValue* pop() {
twisti@2047 121 int size = current_state()->stack(0) == NULL ? 2 : 1;
twisti@2047 122 if (size == 2)
twisti@2047 123 xpop();
twisti@2047 124 SharkValue *value = xpop();
twisti@2047 125 assert(value && value->size() == size, "should be");
twisti@2047 126 return value;
twisti@2047 127 }
twisti@2047 128 SharkValue* pop_result(BasicType type) {
twisti@2047 129 SharkValue *result = pop();
twisti@2047 130
twisti@2047 131 #ifdef ASSERT
twisti@2047 132 switch (result->basic_type()) {
twisti@2047 133 case T_BOOLEAN:
twisti@2047 134 case T_BYTE:
twisti@2047 135 case T_CHAR:
twisti@2047 136 case T_SHORT:
twisti@2047 137 assert(type == T_INT, "type mismatch");
twisti@2047 138 break;
twisti@2047 139
twisti@2047 140 case T_ARRAY:
twisti@2047 141 assert(type == T_OBJECT, "type mismatch");
twisti@2047 142 break;
twisti@2047 143
twisti@2047 144 default:
twisti@2047 145 assert(result->basic_type() == type, "type mismatch");
twisti@2047 146 }
twisti@2047 147 #endif // ASSERT
twisti@2047 148
twisti@2047 149 return result;
twisti@2047 150 }
twisti@2047 151
twisti@2047 152 // Code generation
twisti@2047 153 public:
twisti@2047 154 virtual void emit_IR();
twisti@2047 155
twisti@2047 156 protected:
twisti@2047 157 void parse_bytecode(int start, int limit);
twisti@2047 158
twisti@2047 159 // Helpers
twisti@2047 160 protected:
twisti@2047 161 virtual void do_zero_check(SharkValue* value);
twisti@2047 162
twisti@2047 163 // Zero checking
twisti@2047 164 protected:
twisti@2047 165 void check_null(SharkValue* object) {
twisti@2047 166 zero_check(object);
twisti@2047 167 }
twisti@2047 168 void check_divide_by_zero(SharkValue* value) {
twisti@2047 169 zero_check(value);
twisti@2047 170 }
twisti@2047 171 private:
twisti@2047 172 void zero_check(SharkValue* value) {
twisti@2047 173 if (!value->zero_checked())
twisti@2047 174 do_zero_check(value);
twisti@2047 175 }
twisti@2047 176
twisti@2047 177 // Safepoints
twisti@2047 178 protected:
twisti@2047 179 virtual void maybe_add_backedge_safepoint();
twisti@2047 180
twisti@2047 181 // Traps
twisti@2047 182 protected:
twisti@2047 183 virtual bool has_trap();
twisti@2047 184 virtual int trap_request();
twisti@2047 185 virtual int trap_bci();
twisti@2047 186 virtual void do_trap(int trap_request);
twisti@2047 187
twisti@2047 188 // arraylength
twisti@2047 189 protected:
twisti@2047 190 virtual void do_arraylength();
twisti@2047 191
twisti@2047 192 // *aload and *astore
twisti@2047 193 protected:
twisti@2047 194 virtual void do_aload(BasicType basic_type);
twisti@2047 195 virtual void do_astore(BasicType basic_type);
twisti@2047 196
twisti@2047 197 // *div and *rem
twisti@2047 198 private:
twisti@2047 199 void do_idiv() {
twisti@2047 200 do_div_or_rem(false, false);
twisti@2047 201 }
twisti@2047 202 void do_irem() {
twisti@2047 203 do_div_or_rem(false, true);
twisti@2047 204 }
twisti@2047 205 void do_ldiv() {
twisti@2047 206 do_div_or_rem(true, false);
twisti@2047 207 }
twisti@2047 208 void do_lrem() {
twisti@2047 209 do_div_or_rem(true, true);
twisti@2047 210 }
twisti@2047 211 void do_div_or_rem(bool is_long, bool is_rem);
twisti@2047 212
twisti@2047 213 // get* and put*
twisti@2047 214 private:
twisti@2047 215 void do_getstatic() {
twisti@2047 216 do_field_access(true, false);
twisti@2047 217 }
twisti@2047 218 void do_getfield() {
twisti@2047 219 do_field_access(true, true);
twisti@2047 220 }
twisti@2047 221 void do_putstatic() {
twisti@2047 222 do_field_access(false, false);
twisti@2047 223 }
twisti@2047 224 void do_putfield() {
twisti@2047 225 do_field_access(false, true);
twisti@2047 226 }
twisti@2047 227 void do_field_access(bool is_get, bool is_field);
twisti@2047 228
twisti@2047 229 // lcmp and [fd]cmp[lg]
twisti@2047 230 private:
twisti@2047 231 void do_lcmp();
twisti@2047 232 void do_fcmp(bool is_double, bool unordered_is_greater);
twisti@2047 233
twisti@2047 234 // *return and athrow
twisti@2047 235 protected:
twisti@2047 236 virtual void do_return(BasicType type);
twisti@2047 237 virtual void do_athrow();
twisti@2047 238
twisti@2047 239 // goto*
twisti@2047 240 protected:
twisti@2047 241 virtual void do_goto();
twisti@2047 242
twisti@2047 243 // jsr* and ret
twisti@2047 244 protected:
twisti@2047 245 virtual void do_jsr();
twisti@2047 246 virtual void do_ret();
twisti@2047 247
twisti@2047 248 // if*
twisti@2047 249 protected:
twisti@2047 250 virtual void do_if(llvm::ICmpInst::Predicate p, SharkValue* b, SharkValue* a);
twisti@2047 251
twisti@2047 252 // *switch
twisti@2047 253 protected:
twisti@2047 254 int switch_default_dest();
twisti@2047 255 int switch_table_length();
twisti@2047 256 int switch_key(int i);
twisti@2047 257 int switch_dest(int i);
twisti@2047 258
twisti@2047 259 virtual void do_switch();
twisti@2047 260
twisti@2047 261 // invoke*
twisti@2047 262 protected:
twisti@2047 263 virtual void do_call();
twisti@2047 264
twisti@2047 265 // checkcast and instanceof
twisti@2047 266 protected:
twisti@2047 267 virtual void do_instance_check();
twisti@2047 268 virtual bool maybe_do_instanceof_if();
twisti@2047 269
twisti@2047 270 // new and *newarray
twisti@2047 271 protected:
twisti@2047 272 virtual void do_new();
twisti@2047 273 virtual void do_newarray();
twisti@2047 274 virtual void do_anewarray();
twisti@2047 275 virtual void do_multianewarray();
twisti@2047 276
twisti@2047 277 // monitorenter and monitorexit
twisti@2047 278 protected:
twisti@2047 279 virtual void do_monitorenter();
twisti@2047 280 virtual void do_monitorexit();
twisti@2047 281 };

mercurial