src/share/vm/shark/sharkBlock.hpp

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 2314
f95d63e2154a
parent 0
f90c822e73f8
permissions
-rw-r--r--

merge

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

mercurial