src/share/vm/shark/sharkBlock.hpp

changeset 0
f90c822e73f8
child 6876
710a3c8b516e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/shark/sharkBlock.hpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,297 @@
     1.4 +/*
     1.5 + * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
     1.6 + * Copyright 2008, 2009 Red Hat, Inc.
     1.7 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8 + *
     1.9 + * This code is free software; you can redistribute it and/or modify it
    1.10 + * under the terms of the GNU General Public License version 2 only, as
    1.11 + * published by the Free Software Foundation.
    1.12 + *
    1.13 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.15 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.16 + * version 2 for more details (a copy is included in the LICENSE file that
    1.17 + * accompanied this code).
    1.18 + *
    1.19 + * You should have received a copy of the GNU General Public License version
    1.20 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.21 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.22 + *
    1.23 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.24 + * or visit www.oracle.com if you need additional information or have any
    1.25 + * questions.
    1.26 + *
    1.27 + */
    1.28 +
    1.29 +#ifndef SHARE_VM_SHARK_SHARKBLOCK_HPP
    1.30 +#define SHARE_VM_SHARK_SHARKBLOCK_HPP
    1.31 +
    1.32 +#include "ci/ciMethod.hpp"
    1.33 +#include "ci/ciStreams.hpp"
    1.34 +#include "memory/allocation.hpp"
    1.35 +#include "shark/llvmHeaders.hpp"
    1.36 +#include "shark/sharkBuilder.hpp"
    1.37 +#include "shark/sharkConstant.hpp"
    1.38 +#include "shark/sharkInvariants.hpp"
    1.39 +#include "shark/sharkState.hpp"
    1.40 +#include "shark/sharkValue.hpp"
    1.41 +#include "utilities/debug.hpp"
    1.42 +
    1.43 +class SharkState;
    1.44 +
    1.45 +class SharkBlock : public SharkTargetInvariants {
    1.46 + protected:
    1.47 +  SharkBlock(const SharkTargetInvariants* parent)
    1.48 +    : SharkTargetInvariants(parent),
    1.49 +      _iter(target()),
    1.50 +      _current_state(NULL) {}
    1.51 +
    1.52 +  SharkBlock(const SharkCompileInvariants* parent, ciMethod* target)
    1.53 +    : SharkTargetInvariants(parent, target),
    1.54 +      _iter(target),
    1.55 +      _current_state(NULL) {}
    1.56 +
    1.57 + private:
    1.58 +  ciBytecodeStream _iter;
    1.59 +  SharkState*      _current_state;
    1.60 +
    1.61 + public:
    1.62 +  ciBytecodeStream* iter() {
    1.63 +    return &_iter;
    1.64 +  }
    1.65 +  Bytecodes::Code bc() {
    1.66 +    return iter()->cur_bc();
    1.67 +  }
    1.68 +  int bci() {
    1.69 +    return iter()->cur_bci();
    1.70 +  }
    1.71 +
    1.72 +  // Entry state
    1.73 + protected:
    1.74 +  virtual SharkState* entry_state();
    1.75 +
    1.76 +  // Current state
    1.77 + private:
    1.78 +  SharkState* initial_current_state();
    1.79 +
    1.80 + public:
    1.81 +  SharkState* current_state() {
    1.82 +    if (_current_state == NULL)
    1.83 +      set_current_state(initial_current_state());
    1.84 +    return _current_state;
    1.85 +  }
    1.86 +
    1.87 + protected:
    1.88 +  void set_current_state(SharkState* current_state) {
    1.89 +    _current_state = current_state;
    1.90 +  }
    1.91 +
    1.92 +  // Local variables
    1.93 + protected:
    1.94 +  SharkValue* local(int index) {
    1.95 +    SharkValue *value = current_state()->local(index);
    1.96 +    assert(value != NULL, "shouldn't be");
    1.97 +    assert(value->is_one_word() ||
    1.98 +           (index + 1 < max_locals() &&
    1.99 +            current_state()->local(index + 1) == NULL), "should be");
   1.100 +    return value;
   1.101 +  }
   1.102 +  void set_local(int index, SharkValue* value) {
   1.103 +    assert(value != NULL, "shouldn't be");
   1.104 +    current_state()->set_local(index, value);
   1.105 +    if (value->is_two_word())
   1.106 +      current_state()->set_local(index + 1, NULL);
   1.107 +  }
   1.108 +
   1.109 +  // Expression stack (raw)
   1.110 + protected:
   1.111 +  void xpush(SharkValue* value) {
   1.112 +    current_state()->push(value);
   1.113 +  }
   1.114 +  SharkValue* xpop() {
   1.115 +    return current_state()->pop();
   1.116 +  }
   1.117 +  SharkValue* xstack(int slot) {
   1.118 +    SharkValue *value = current_state()->stack(slot);
   1.119 +    assert(value != NULL, "shouldn't be");
   1.120 +    assert(value->is_one_word() ||
   1.121 +           (slot > 0 &&
   1.122 +            current_state()->stack(slot - 1) == NULL), "should be");
   1.123 +    return value;
   1.124 +  }
   1.125 +  int xstack_depth() {
   1.126 +    return current_state()->stack_depth();
   1.127 +  }
   1.128 +
   1.129 +  // Expression stack (cooked)
   1.130 + protected:
   1.131 +  void push(SharkValue* value) {
   1.132 +    assert(value != NULL, "shouldn't be");
   1.133 +    xpush(value);
   1.134 +    if (value->is_two_word())
   1.135 +      xpush(NULL);
   1.136 +  }
   1.137 +  SharkValue* pop() {
   1.138 +    int size = current_state()->stack(0) == NULL ? 2 : 1;
   1.139 +    if (size == 2)
   1.140 +      xpop();
   1.141 +    SharkValue *value = xpop();
   1.142 +    assert(value && value->size() == size, "should be");
   1.143 +    return value;
   1.144 +  }
   1.145 +  SharkValue* pop_result(BasicType type) {
   1.146 +    SharkValue *result = pop();
   1.147 +
   1.148 +#ifdef ASSERT
   1.149 +    switch (result->basic_type()) {
   1.150 +    case T_BOOLEAN:
   1.151 +    case T_BYTE:
   1.152 +    case T_CHAR:
   1.153 +    case T_SHORT:
   1.154 +      assert(type == T_INT, "type mismatch");
   1.155 +      break;
   1.156 +
   1.157 +    case T_ARRAY:
   1.158 +      assert(type == T_OBJECT, "type mismatch");
   1.159 +      break;
   1.160 +
   1.161 +    default:
   1.162 +      assert(result->basic_type() == type, "type mismatch");
   1.163 +    }
   1.164 +#endif // ASSERT
   1.165 +
   1.166 +    return result;
   1.167 +  }
   1.168 +
   1.169 +  // Code generation
   1.170 + public:
   1.171 +  virtual void emit_IR();
   1.172 +
   1.173 + protected:
   1.174 +  void parse_bytecode(int start, int limit);
   1.175 +
   1.176 +  // Helpers
   1.177 + protected:
   1.178 +  virtual void do_zero_check(SharkValue* value);
   1.179 +
   1.180 +  // Zero checking
   1.181 + protected:
   1.182 +  void check_null(SharkValue* object) {
   1.183 +    zero_check(object);
   1.184 +  }
   1.185 +  void check_divide_by_zero(SharkValue* value) {
   1.186 +    zero_check(value);
   1.187 +  }
   1.188 + private:
   1.189 +  void zero_check(SharkValue* value) {
   1.190 +    if (!value->zero_checked())
   1.191 +      do_zero_check(value);
   1.192 +  }
   1.193 +
   1.194 +  // Safepoints
   1.195 + protected:
   1.196 +  virtual void maybe_add_backedge_safepoint();
   1.197 +
   1.198 +  // Traps
   1.199 + protected:
   1.200 +  virtual bool has_trap();
   1.201 +  virtual int  trap_request();
   1.202 +  virtual int  trap_bci();
   1.203 +  virtual void do_trap(int trap_request);
   1.204 +
   1.205 +  // arraylength
   1.206 + protected:
   1.207 +  virtual void do_arraylength();
   1.208 +
   1.209 +  // *aload and *astore
   1.210 + protected:
   1.211 +  virtual void do_aload(BasicType basic_type);
   1.212 +  virtual void do_astore(BasicType basic_type);
   1.213 +
   1.214 +  // *div and *rem
   1.215 + private:
   1.216 +  void do_idiv() {
   1.217 +    do_div_or_rem(false, false);
   1.218 +  }
   1.219 +  void do_irem() {
   1.220 +    do_div_or_rem(false, true);
   1.221 +  }
   1.222 +  void do_ldiv() {
   1.223 +    do_div_or_rem(true, false);
   1.224 +  }
   1.225 +  void do_lrem() {
   1.226 +    do_div_or_rem(true, true);
   1.227 +  }
   1.228 +  void do_div_or_rem(bool is_long, bool is_rem);
   1.229 +
   1.230 +  // get* and put*
   1.231 + private:
   1.232 +  void do_getstatic() {
   1.233 +    do_field_access(true, false);
   1.234 +  }
   1.235 +  void do_getfield() {
   1.236 +    do_field_access(true, true);
   1.237 +  }
   1.238 +  void do_putstatic() {
   1.239 +    do_field_access(false, false);
   1.240 +  }
   1.241 +  void do_putfield() {
   1.242 +    do_field_access(false, true);
   1.243 +  }
   1.244 +  void do_field_access(bool is_get, bool is_field);
   1.245 +
   1.246 +  // lcmp and [fd]cmp[lg]
   1.247 + private:
   1.248 +  void do_lcmp();
   1.249 +  void do_fcmp(bool is_double, bool unordered_is_greater);
   1.250 +
   1.251 +  // *return and athrow
   1.252 + protected:
   1.253 +  virtual void do_return(BasicType type);
   1.254 +  virtual void do_athrow();
   1.255 +
   1.256 +  // goto*
   1.257 + protected:
   1.258 +  virtual void do_goto();
   1.259 +
   1.260 +  // jsr* and ret
   1.261 + protected:
   1.262 +  virtual void do_jsr();
   1.263 +  virtual void do_ret();
   1.264 +
   1.265 +  // if*
   1.266 + protected:
   1.267 +  virtual void do_if(llvm::ICmpInst::Predicate p, SharkValue* b, SharkValue* a);
   1.268 +
   1.269 +  // *switch
   1.270 + protected:
   1.271 +  int switch_default_dest();
   1.272 +  int switch_table_length();
   1.273 +  int switch_key(int i);
   1.274 +  int switch_dest(int i);
   1.275 +
   1.276 +  virtual void do_switch();
   1.277 +
   1.278 +  // invoke*
   1.279 + protected:
   1.280 +  virtual void do_call();
   1.281 +
   1.282 +  // checkcast and instanceof
   1.283 + protected:
   1.284 +  virtual void do_instance_check();
   1.285 +  virtual bool maybe_do_instanceof_if();
   1.286 +
   1.287 +  // new and *newarray
   1.288 + protected:
   1.289 +  virtual void do_new();
   1.290 +  virtual void do_newarray();
   1.291 +  virtual void do_anewarray();
   1.292 +  virtual void do_multianewarray();
   1.293 +
   1.294 +  // monitorenter and monitorexit
   1.295 + protected:
   1.296 +  virtual void do_monitorenter();
   1.297 +  virtual void do_monitorexit();
   1.298 +};
   1.299 +
   1.300 +#endif // SHARE_VM_SHARK_SHARKBLOCK_HPP

mercurial