src/share/vm/oops/generateOopMap.hpp

Thu, 04 Apr 2019 17:56:29 +0800

author
aoqi
date
Thu, 04 Apr 2019 17:56:29 +0800
changeset 9572
624a0741915c
parent 6876
710a3c8b516e
permissions
-rw-r--r--

Merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #ifndef SHARE_VM_OOPS_GENERATEOOPMAP_HPP
aoqi@0 26 #define SHARE_VM_OOPS_GENERATEOOPMAP_HPP
aoqi@0 27
aoqi@0 28 #include "interpreter/bytecodeStream.hpp"
aoqi@0 29 #include "memory/allocation.inline.hpp"
aoqi@0 30 #include "memory/universe.inline.hpp"
aoqi@0 31 #include "oops/method.hpp"
aoqi@0 32 #include "oops/oopsHierarchy.hpp"
aoqi@0 33 #include "runtime/signature.hpp"
aoqi@0 34
aoqi@0 35 // Forward definition
aoqi@0 36 class GenerateOopMap;
aoqi@0 37 class BasicBlock;
aoqi@0 38 class CellTypeState;
aoqi@0 39 class StackMap;
aoqi@0 40
aoqi@0 41 // These two should be removed. But requires som code to be cleaned up
aoqi@0 42 #define MAXARGSIZE 256 // This should be enough
aoqi@0 43 #define MAX_LOCAL_VARS 65536 // 16-bit entry
aoqi@0 44
aoqi@0 45 typedef void (*jmpFct_t)(GenerateOopMap *c, int bcpDelta, int* data);
aoqi@0 46
aoqi@0 47
aoqi@0 48 // RetTable
aoqi@0 49 //
aoqi@0 50 // Contains maping between jsr targets and there return addresses. One-to-many mapping
aoqi@0 51 //
aoqi@0 52 class RetTableEntry : public ResourceObj {
aoqi@0 53 private:
aoqi@0 54 static int _init_nof_jsrs; // Default size of jsrs list
aoqi@0 55 int _target_bci; // Target PC address of jump (bytecode index)
aoqi@0 56 GrowableArray<intptr_t> * _jsrs; // List of return addresses (bytecode index)
aoqi@0 57 RetTableEntry *_next; // Link to next entry
aoqi@0 58 public:
aoqi@0 59 RetTableEntry(int target, RetTableEntry *next) { _target_bci=target; _jsrs = new GrowableArray<intptr_t>(_init_nof_jsrs); _next = next; }
aoqi@0 60
aoqi@0 61 // Query
aoqi@0 62 int target_bci() const { return _target_bci; }
aoqi@0 63 int nof_jsrs() const { return _jsrs->length(); }
aoqi@0 64 int jsrs(int i) const { assert(i>=0 && i<nof_jsrs(), "Index out of bounds"); return _jsrs->at(i); }
aoqi@0 65
aoqi@0 66 // Update entry
aoqi@0 67 void add_jsr (int return_bci) { _jsrs->append(return_bci); }
aoqi@0 68 void add_delta (int bci, int delta);
aoqi@0 69 RetTableEntry * next() const { return _next; }
aoqi@0 70 };
aoqi@0 71
aoqi@0 72
aoqi@0 73 class RetTable VALUE_OBJ_CLASS_SPEC {
aoqi@0 74 private:
aoqi@0 75 RetTableEntry *_first;
aoqi@0 76 static int _init_nof_entries;
aoqi@0 77
aoqi@0 78 void add_jsr(int return_bci, int target_bci); // Adds entry to list
aoqi@0 79 public:
aoqi@0 80 RetTable() { _first = NULL; }
aoqi@0 81 void compute_ret_table(methodHandle method);
aoqi@0 82 void update_ret_table(int bci, int delta);
aoqi@0 83 RetTableEntry* find_jsrs_for_target(int targBci);
aoqi@0 84 };
aoqi@0 85
aoqi@0 86 //
aoqi@0 87 // CellTypeState
aoqi@0 88 //
aoqi@0 89 class CellTypeState VALUE_OBJ_CLASS_SPEC {
aoqi@0 90 private:
aoqi@0 91 unsigned int _state;
aoqi@0 92
aoqi@0 93 // Masks for separating the BITS and INFO portions of a CellTypeState
aoqi@0 94 enum { info_mask = right_n_bits(28),
aoqi@0 95 bits_mask = (int)(~info_mask) };
aoqi@0 96
aoqi@0 97 // These constant are used for manipulating the BITS portion of a
aoqi@0 98 // CellTypeState
aoqi@0 99 enum { uninit_bit = (int)(nth_bit(31)),
aoqi@0 100 ref_bit = nth_bit(30),
aoqi@0 101 val_bit = nth_bit(29),
aoqi@0 102 addr_bit = nth_bit(28),
aoqi@0 103 live_bits_mask = (int)(bits_mask & ~uninit_bit) };
aoqi@0 104
aoqi@0 105 // These constants are used for manipulating the INFO portion of a
aoqi@0 106 // CellTypeState
aoqi@0 107 enum { top_info_bit = nth_bit(27),
aoqi@0 108 not_bottom_info_bit = nth_bit(26),
aoqi@0 109 info_data_mask = right_n_bits(26),
aoqi@0 110 info_conflict = info_mask };
aoqi@0 111
aoqi@0 112 // Within the INFO data, these values are used to distinguish different
aoqi@0 113 // kinds of references.
aoqi@0 114 enum { ref_not_lock_bit = nth_bit(25), // 0 if this reference is locked as a monitor
aoqi@0 115 ref_slot_bit = nth_bit(24), // 1 if this reference is a "slot" reference,
aoqi@0 116 // 0 if it is a "line" reference.
aoqi@0 117 ref_data_mask = right_n_bits(24) };
aoqi@0 118
aoqi@0 119
aoqi@0 120 // These values are used to initialize commonly used CellTypeState
aoqi@0 121 // constants.
aoqi@0 122 enum { bottom_value = 0,
aoqi@0 123 uninit_value = (int)(uninit_bit | info_conflict),
aoqi@0 124 ref_value = ref_bit,
aoqi@0 125 ref_conflict = ref_bit | info_conflict,
aoqi@0 126 val_value = val_bit | info_conflict,
aoqi@0 127 addr_value = addr_bit,
aoqi@0 128 addr_conflict = addr_bit | info_conflict };
aoqi@0 129
aoqi@0 130 public:
aoqi@0 131
aoqi@0 132 // Since some C++ constructors generate poor code for declarations of the
aoqi@0 133 // form...
aoqi@0 134 //
aoqi@0 135 // CellTypeState vector[length];
aoqi@0 136 //
aoqi@0 137 // ...we avoid making a constructor for this class. CellTypeState values
aoqi@0 138 // should be constructed using one of the make_* methods:
aoqi@0 139
aoqi@0 140 static CellTypeState make_any(int state) {
aoqi@0 141 CellTypeState s;
aoqi@0 142 s._state = state;
aoqi@0 143 // Causes SS10 warning.
aoqi@0 144 // assert(s.is_valid_state(), "check to see if CellTypeState is valid");
aoqi@0 145 return s;
aoqi@0 146 }
aoqi@0 147
aoqi@0 148 static CellTypeState make_bottom() {
aoqi@0 149 return make_any(0);
aoqi@0 150 }
aoqi@0 151
aoqi@0 152 static CellTypeState make_top() {
aoqi@0 153 return make_any(AllBits);
aoqi@0 154 }
aoqi@0 155
aoqi@0 156 static CellTypeState make_addr(int bci) {
aoqi@0 157 assert((bci >= 0) && (bci < info_data_mask), "check to see if ret addr is valid");
aoqi@0 158 return make_any(addr_bit | not_bottom_info_bit | (bci & info_data_mask));
aoqi@0 159 }
aoqi@0 160
aoqi@0 161 static CellTypeState make_slot_ref(int slot_num) {
aoqi@0 162 assert(slot_num >= 0 && slot_num < ref_data_mask, "slot out of range");
aoqi@0 163 return make_any(ref_bit | not_bottom_info_bit | ref_not_lock_bit | ref_slot_bit |
aoqi@0 164 (slot_num & ref_data_mask));
aoqi@0 165 }
aoqi@0 166
aoqi@0 167 static CellTypeState make_line_ref(int bci) {
aoqi@0 168 assert(bci >= 0 && bci < ref_data_mask, "line out of range");
aoqi@0 169 return make_any(ref_bit | not_bottom_info_bit | ref_not_lock_bit |
aoqi@0 170 (bci & ref_data_mask));
aoqi@0 171 }
aoqi@0 172
aoqi@0 173 static CellTypeState make_lock_ref(int bci) {
aoqi@0 174 assert(bci >= 0 && bci < ref_data_mask, "line out of range");
aoqi@0 175 return make_any(ref_bit | not_bottom_info_bit | (bci & ref_data_mask));
aoqi@0 176 }
aoqi@0 177
aoqi@0 178 // Query methods:
aoqi@0 179 bool is_bottom() const { return _state == 0; }
aoqi@0 180 bool is_live() const { return ((_state & live_bits_mask) != 0); }
aoqi@0 181 bool is_valid_state() const {
aoqi@0 182 // Uninitialized and value cells must contain no data in their info field:
aoqi@0 183 if ((can_be_uninit() || can_be_value()) && !is_info_top()) {
aoqi@0 184 return false;
aoqi@0 185 }
aoqi@0 186 // The top bit is only set when all info bits are set:
aoqi@0 187 if (is_info_top() && ((_state & info_mask) != info_mask)) {
aoqi@0 188 return false;
aoqi@0 189 }
aoqi@0 190 // The not_bottom_bit must be set when any other info bit is set:
aoqi@0 191 if (is_info_bottom() && ((_state & info_mask) != 0)) {
aoqi@0 192 return false;
aoqi@0 193 }
aoqi@0 194 return true;
aoqi@0 195 }
aoqi@0 196
aoqi@0 197 bool is_address() const { return ((_state & bits_mask) == addr_bit); }
aoqi@0 198 bool is_reference() const { return ((_state & bits_mask) == ref_bit); }
aoqi@0 199 bool is_value() const { return ((_state & bits_mask) == val_bit); }
aoqi@0 200 bool is_uninit() const { return ((_state & bits_mask) == (uint)uninit_bit); }
aoqi@0 201
aoqi@0 202 bool can_be_address() const { return ((_state & addr_bit) != 0); }
aoqi@0 203 bool can_be_reference() const { return ((_state & ref_bit) != 0); }
aoqi@0 204 bool can_be_value() const { return ((_state & val_bit) != 0); }
aoqi@0 205 bool can_be_uninit() const { return ((_state & uninit_bit) != 0); }
aoqi@0 206
aoqi@0 207 bool is_info_bottom() const { return ((_state & not_bottom_info_bit) == 0); }
aoqi@0 208 bool is_info_top() const { return ((_state & top_info_bit) != 0); }
aoqi@0 209 int get_info() const {
aoqi@0 210 assert((!is_info_top() && !is_info_bottom()),
aoqi@0 211 "check to make sure top/bottom info is not used");
aoqi@0 212 return (_state & info_data_mask);
aoqi@0 213 }
aoqi@0 214
aoqi@0 215 bool is_good_address() const { return is_address() && !is_info_top(); }
aoqi@0 216 bool is_lock_reference() const {
aoqi@0 217 return ((_state & (bits_mask | top_info_bit | ref_not_lock_bit)) == ref_bit);
aoqi@0 218 }
aoqi@0 219 bool is_nonlock_reference() const {
aoqi@0 220 return ((_state & (bits_mask | top_info_bit | ref_not_lock_bit)) == (ref_bit | ref_not_lock_bit));
aoqi@0 221 }
aoqi@0 222
aoqi@0 223 bool equal(CellTypeState a) const { return _state == a._state; }
aoqi@0 224 bool equal_kind(CellTypeState a) const {
aoqi@0 225 return (_state & bits_mask) == (a._state & bits_mask);
aoqi@0 226 }
aoqi@0 227
aoqi@0 228 char to_char() const;
aoqi@0 229
aoqi@0 230 // Merge
aoqi@0 231 CellTypeState merge (CellTypeState cts, int slot) const;
aoqi@0 232
aoqi@0 233 // Debugging output
aoqi@0 234 void print(outputStream *os);
aoqi@0 235
aoqi@0 236 // Default values of common values
aoqi@0 237 static CellTypeState bottom;
aoqi@0 238 static CellTypeState uninit;
aoqi@0 239 static CellTypeState ref;
aoqi@0 240 static CellTypeState value;
aoqi@0 241 static CellTypeState refUninit;
aoqi@0 242 static CellTypeState varUninit;
aoqi@0 243 static CellTypeState top;
aoqi@0 244 static CellTypeState addr;
aoqi@0 245 };
aoqi@0 246
aoqi@0 247
aoqi@0 248 //
aoqi@0 249 // BasicBlockStruct
aoqi@0 250 //
aoqi@0 251 class BasicBlock: ResourceObj {
aoqi@0 252 private:
aoqi@0 253 bool _changed; // Reached a fixpoint or not
aoqi@0 254 public:
aoqi@0 255 enum Constants {
aoqi@0 256 _dead_basic_block = -2,
aoqi@0 257 _unreached = -1 // Alive but not yet reached by analysis
aoqi@0 258 // >=0 // Alive and has a merged state
aoqi@0 259 };
aoqi@0 260
aoqi@0 261 int _bci; // Start of basic block
aoqi@0 262 int _end_bci; // Bci of last instruction in basicblock
aoqi@0 263 int _max_locals; // Determines split between vars and stack
aoqi@0 264 int _max_stack; // Determines split between stack and monitors
aoqi@0 265 CellTypeState* _state; // State (vars, stack) at entry.
aoqi@0 266 int _stack_top; // -1 indicates bottom stack value.
aoqi@0 267 int _monitor_top; // -1 indicates bottom monitor stack value.
aoqi@0 268
aoqi@0 269 CellTypeState* vars() { return _state; }
aoqi@0 270 CellTypeState* stack() { return _state + _max_locals; }
aoqi@0 271
aoqi@0 272 bool changed() { return _changed; }
aoqi@0 273 void set_changed(bool s) { _changed = s; }
aoqi@0 274
aoqi@0 275 bool is_reachable() const { return _stack_top >= 0; } // Analysis has reached this basicblock
aoqi@0 276
aoqi@0 277 // All basicblocks that are unreachable are going to have a _stack_top == _dead_basic_block.
aoqi@0 278 // This info. is setup in a pre-parse before the real abstract interpretation starts.
aoqi@0 279 bool is_dead() const { return _stack_top == _dead_basic_block; }
aoqi@0 280 bool is_alive() const { return _stack_top != _dead_basic_block; }
aoqi@0 281 void mark_as_alive() { assert(is_dead(), "must be dead"); _stack_top = _unreached; }
aoqi@0 282 };
aoqi@0 283
aoqi@0 284
aoqi@0 285 //
aoqi@0 286 // GenerateOopMap
aoqi@0 287 //
aoqi@0 288 // Main class used to compute the pointer-maps in a Method
aoqi@0 289 //
aoqi@0 290 class GenerateOopMap VALUE_OBJ_CLASS_SPEC {
aoqi@0 291 protected:
aoqi@0 292
aoqi@0 293 // _monitor_top is set to this constant to indicate that a monitor matching
aoqi@0 294 // problem was encountered prior to this point in control flow.
aoqi@0 295 enum { bad_monitors = -1 };
aoqi@0 296
aoqi@0 297 // Main variables
aoqi@0 298 methodHandle _method; // The method we are examine
aoqi@0 299 RetTable _rt; // Contains the return address mappings
aoqi@0 300 int _max_locals; // Cached value of no. of locals
aoqi@0 301 int _max_stack; // Cached value of max. stack depth
aoqi@0 302 int _max_monitors; // Cached value of max. monitor stack depth
aoqi@0 303 int _has_exceptions; // True, if exceptions exist for method
aoqi@0 304 bool _got_error; // True, if an error occurred during interpretation.
aoqi@0 305 Handle _exception; // Exception if got_error is true.
aoqi@0 306 bool _did_rewriting; // was bytecodes rewritten
aoqi@0 307 bool _did_relocation; // was relocation neccessary
aoqi@0 308 bool _monitor_safe; // The monitors in this method have been determined
aoqi@0 309 // to be safe.
aoqi@0 310
aoqi@0 311 // Working Cell type state
aoqi@0 312 int _state_len; // Size of states
aoqi@0 313 CellTypeState *_state; // list of states
aoqi@0 314 char *_state_vec_buf; // Buffer used to print a readable version of a state
aoqi@0 315 int _stack_top;
aoqi@0 316 int _monitor_top;
aoqi@0 317
aoqi@0 318 // Timing and statistics
aoqi@0 319 static elapsedTimer _total_oopmap_time; // Holds cumulative oopmap generation time
aoqi@0 320 static long _total_byte_count; // Holds cumulative number of bytes inspected
aoqi@0 321
aoqi@0 322 // Cell type methods
aoqi@0 323 void init_state();
aoqi@0 324 void make_context_uninitialized ();
aoqi@0 325 int methodsig_to_effect (Symbol* signature, bool isStatic, CellTypeState* effect);
aoqi@0 326 bool merge_local_state_vectors (CellTypeState* cts, CellTypeState* bbts);
aoqi@0 327 bool merge_monitor_state_vectors(CellTypeState* cts, CellTypeState* bbts);
aoqi@0 328 void copy_state (CellTypeState *dst, CellTypeState *src);
aoqi@0 329 void merge_state_into_bb (BasicBlock *bb);
aoqi@0 330 static void merge_state (GenerateOopMap *gom, int bcidelta, int* data);
aoqi@0 331 void set_var (int localNo, CellTypeState cts);
aoqi@0 332 CellTypeState get_var (int localNo);
aoqi@0 333 CellTypeState pop ();
aoqi@0 334 void push (CellTypeState cts);
aoqi@0 335 CellTypeState monitor_pop ();
aoqi@0 336 void monitor_push (CellTypeState cts);
aoqi@0 337 CellTypeState * vars () { return _state; }
aoqi@0 338 CellTypeState * stack () { return _state+_max_locals; }
aoqi@0 339 CellTypeState * monitors () { return _state+_max_locals+_max_stack; }
aoqi@0 340
aoqi@0 341 void replace_all_CTS_matches (CellTypeState match,
aoqi@0 342 CellTypeState replace);
aoqi@0 343 void print_states (outputStream *os, CellTypeState *vector, int num);
aoqi@0 344 void print_current_state (outputStream *os,
aoqi@0 345 BytecodeStream *itr,
aoqi@0 346 bool detailed);
aoqi@0 347 void report_monitor_mismatch (const char *msg);
aoqi@0 348
aoqi@0 349 // Basicblock info
aoqi@0 350 BasicBlock * _basic_blocks; // Array of basicblock info
aoqi@0 351 int _gc_points;
aoqi@0 352 int _bb_count;
aoqi@0 353 BitMap _bb_hdr_bits;
aoqi@0 354
aoqi@0 355 // Basicblocks methods
aoqi@0 356 void initialize_bb ();
aoqi@0 357 void mark_bbheaders_and_count_gc_points();
aoqi@0 358 bool is_bb_header (int bci) const {
aoqi@0 359 return _bb_hdr_bits.at(bci);
aoqi@0 360 }
aoqi@0 361 int gc_points () const { return _gc_points; }
aoqi@0 362 int bb_count () const { return _bb_count; }
aoqi@0 363 void set_bbmark_bit (int bci) {
aoqi@0 364 _bb_hdr_bits.at_put(bci, true);
aoqi@0 365 }
aoqi@0 366 void clear_bbmark_bit (int bci) {
aoqi@0 367 _bb_hdr_bits.at_put(bci, false);
aoqi@0 368 }
aoqi@0 369 BasicBlock * get_basic_block_at (int bci) const;
aoqi@0 370 BasicBlock * get_basic_block_containing (int bci) const;
aoqi@0 371 void interp_bb (BasicBlock *bb);
aoqi@0 372 void restore_state (BasicBlock *bb);
aoqi@0 373 int next_bb_start_pc (BasicBlock *bb);
aoqi@0 374 void update_basic_blocks (int bci, int delta, int new_method_size);
aoqi@0 375 static void bb_mark_fct (GenerateOopMap *c, int deltaBci, int *data);
aoqi@0 376
aoqi@0 377 // Dead code detection
aoqi@0 378 void mark_reachable_code();
aoqi@0 379 static void reachable_basicblock (GenerateOopMap *c, int deltaBci, int *data);
aoqi@0 380
aoqi@0 381 // Interpretation methods (primary)
aoqi@0 382 void do_interpretation ();
aoqi@0 383 void init_basic_blocks ();
aoqi@0 384 void setup_method_entry_state ();
aoqi@0 385 void interp_all ();
aoqi@0 386
aoqi@0 387 // Interpretation methods (secondary)
aoqi@0 388 void interp1 (BytecodeStream *itr);
aoqi@0 389 void do_exception_edge (BytecodeStream *itr);
aoqi@0 390 void check_type (CellTypeState expected, CellTypeState actual);
aoqi@0 391 void ppstore (CellTypeState *in, int loc_no);
aoqi@0 392 void ppload (CellTypeState *out, int loc_no);
aoqi@0 393 void ppush1 (CellTypeState in);
aoqi@0 394 void ppush (CellTypeState *in);
aoqi@0 395 void ppop1 (CellTypeState out);
aoqi@0 396 void ppop (CellTypeState *out);
aoqi@0 397 void ppop_any (int poplen);
aoqi@0 398 void pp (CellTypeState *in, CellTypeState *out);
aoqi@0 399 void pp_new_ref (CellTypeState *in, int bci);
aoqi@0 400 void ppdupswap (int poplen, const char *out);
aoqi@0 401 void do_ldc (int bci);
aoqi@0 402 void do_astore (int idx);
aoqi@0 403 void do_jsr (int delta);
aoqi@0 404 void do_field (int is_get, int is_static, int idx, int bci);
aoqi@0 405 void do_method (int is_static, int is_interface, int idx, int bci);
aoqi@0 406 void do_multianewarray (int dims, int bci);
aoqi@0 407 void do_monitorenter (int bci);
aoqi@0 408 void do_monitorexit (int bci);
aoqi@0 409 void do_return_monitor_check ();
aoqi@0 410 void do_checkcast ();
aoqi@0 411 CellTypeState *sigchar_to_effect (char sigch, int bci, CellTypeState *out);
aoqi@0 412 int copy_cts (CellTypeState *dst, CellTypeState *src);
aoqi@0 413
aoqi@0 414 // Error handling
aoqi@0 415 void error_work (const char *format, va_list ap) ATTRIBUTE_PRINTF(2, 0);
aoqi@0 416 void report_error (const char *format, ...) ATTRIBUTE_PRINTF(2, 3);
aoqi@0 417 void verify_error (const char *format, ...) ATTRIBUTE_PRINTF(2, 3);
aoqi@0 418 bool got_error() { return _got_error; }
aoqi@0 419
aoqi@0 420 // Create result set
aoqi@0 421 bool _report_result;
aoqi@0 422 bool _report_result_for_send; // Unfortunatly, stackmaps for sends are special, so we need some extra
aoqi@0 423 BytecodeStream *_itr_send; // variables to handle them properly.
aoqi@0 424
aoqi@0 425 void report_result ();
aoqi@0 426
aoqi@0 427 // Initvars
aoqi@0 428 GrowableArray<intptr_t> * _init_vars;
aoqi@0 429
aoqi@0 430 void initialize_vars ();
aoqi@0 431 void add_to_ref_init_set (int localNo);
aoqi@0 432
aoqi@0 433 // Conflicts rewrite logic
aoqi@0 434 bool _conflict; // True, if a conflict occurred during interpretation
aoqi@0 435 int _nof_refval_conflicts; // No. of conflicts that require rewrites
aoqi@0 436 int * _new_var_map;
aoqi@0 437
aoqi@0 438 void record_refval_conflict (int varNo);
aoqi@0 439 void rewrite_refval_conflicts ();
aoqi@0 440 void rewrite_refval_conflict (int from, int to);
aoqi@0 441 bool rewrite_refval_conflict_inst (BytecodeStream *i, int from, int to);
aoqi@0 442 bool rewrite_load_or_store (BytecodeStream *i, Bytecodes::Code bc, Bytecodes::Code bc0, unsigned int varNo);
aoqi@0 443
aoqi@0 444 void expand_current_instr (int bci, int ilen, int newIlen, u_char inst_buffer[]);
aoqi@0 445 bool is_astore (BytecodeStream *itr, int *index);
aoqi@0 446 bool is_aload (BytecodeStream *itr, int *index);
aoqi@0 447
aoqi@0 448 // List of bci's where a return address is on top of the stack
aoqi@0 449 GrowableArray<intptr_t> *_ret_adr_tos;
aoqi@0 450
aoqi@0 451 bool stack_top_holds_ret_addr (int bci);
aoqi@0 452 void compute_ret_adr_at_TOS ();
aoqi@0 453 void update_ret_adr_at_TOS (int bci, int delta);
aoqi@0 454
aoqi@0 455 int binsToHold (int no) { return ((no+(BitsPerWord-1))/BitsPerWord); }
aoqi@0 456 char *state_vec_to_string (CellTypeState* vec, int len);
aoqi@0 457
aoqi@0 458 // Helper method. Can be used in subclasses to fx. calculate gc_points. If the current instuction
aoqi@0 459 // is a control transfer, then calls the jmpFct all possible destinations.
aoqi@0 460 void ret_jump_targets_do (BytecodeStream *bcs, jmpFct_t jmpFct, int varNo,int *data);
aoqi@0 461 bool jump_targets_do (BytecodeStream *bcs, jmpFct_t jmpFct, int *data);
aoqi@0 462
aoqi@0 463 friend class RelocCallback;
aoqi@0 464 public:
aoqi@0 465 GenerateOopMap(methodHandle method);
aoqi@0 466
aoqi@0 467 // Compute the map.
aoqi@0 468 void compute_map(TRAPS);
aoqi@0 469 void result_for_basicblock(int bci); // Do a callback on fill_stackmap_for_opcodes for basicblock containing bci
aoqi@0 470
aoqi@0 471 // Query
aoqi@0 472 int max_locals() const { return _max_locals; }
aoqi@0 473 Method* method() const { return _method(); }
aoqi@0 474 methodHandle method_as_handle() const { return _method; }
aoqi@0 475
aoqi@0 476 bool did_rewriting() { return _did_rewriting; }
aoqi@0 477 bool did_relocation() { return _did_relocation; }
aoqi@0 478
aoqi@0 479 static void print_time();
aoqi@0 480
aoqi@0 481 // Monitor query
aoqi@0 482 bool monitor_safe() { return _monitor_safe; }
aoqi@0 483
aoqi@0 484 // Specialization methods. Intended use:
aoqi@0 485 // - possible_gc_point must return true for every bci for which the stackmaps must be returned
aoqi@0 486 // - fill_stackmap_prolog is called just before the result is reported. The arguments tells the estimated
aoqi@0 487 // number of gc points
aoqi@0 488 // - fill_stackmap_for_opcodes is called once for each bytecode index in order (0...code_length-1)
aoqi@0 489 // - fill_stackmap_epilog is called after all results has been reported. Note: Since the algorithm does not report
aoqi@0 490 // stackmaps for deadcode, fewer gc_points might have been encounted than assumed during the epilog. It is the
aoqi@0 491 // responsibility of the subclass to count the correct number.
aoqi@0 492 // - fill_init_vars are called once with the result of the init_vars computation
aoqi@0 493 //
aoqi@0 494 // All these methods are used during a call to: compute_map. Note: Non of the return results are valid
aoqi@0 495 // after compute_map returns, since all values are allocated as resource objects.
aoqi@0 496 //
aoqi@0 497 // All virtual method must be implemented in subclasses
aoqi@0 498 virtual bool allow_rewrites () const { return false; }
aoqi@0 499 virtual bool report_results () const { return true; }
aoqi@0 500 virtual bool report_init_vars () const { return true; }
aoqi@0 501 virtual bool possible_gc_point (BytecodeStream *bcs) { ShouldNotReachHere(); return false; }
aoqi@0 502 virtual void fill_stackmap_prolog (int nof_gc_points) { ShouldNotReachHere(); }
aoqi@0 503 virtual void fill_stackmap_epilog () { ShouldNotReachHere(); }
aoqi@0 504 virtual void fill_stackmap_for_opcodes (BytecodeStream *bcs,
aoqi@0 505 CellTypeState* vars,
aoqi@0 506 CellTypeState* stack,
aoqi@0 507 int stackTop) { ShouldNotReachHere(); }
aoqi@0 508 virtual void fill_init_vars (GrowableArray<intptr_t> *init_vars) { ShouldNotReachHere();; }
aoqi@0 509 };
aoqi@0 510
aoqi@0 511 //
aoqi@0 512 // Subclass of the GenerateOopMap Class that just do rewrites of the method, if needed.
aoqi@0 513 // It does not store any oopmaps.
aoqi@0 514 //
aoqi@0 515 class ResolveOopMapConflicts: public GenerateOopMap {
aoqi@0 516 private:
aoqi@0 517
aoqi@0 518 bool _must_clear_locals;
aoqi@0 519
aoqi@0 520 virtual bool report_results() const { return false; }
aoqi@0 521 virtual bool report_init_vars() const { return true; }
aoqi@0 522 virtual bool allow_rewrites() const { return true; }
aoqi@0 523 virtual bool possible_gc_point (BytecodeStream *bcs) { return false; }
aoqi@0 524 virtual void fill_stackmap_prolog (int nof_gc_points) {}
aoqi@0 525 virtual void fill_stackmap_epilog () {}
aoqi@0 526 virtual void fill_stackmap_for_opcodes (BytecodeStream *bcs,
aoqi@0 527 CellTypeState* vars,
aoqi@0 528 CellTypeState* stack,
aoqi@0 529 int stack_top) {}
aoqi@0 530 virtual void fill_init_vars (GrowableArray<intptr_t> *init_vars) { _must_clear_locals = init_vars->length() > 0; }
aoqi@0 531
aoqi@0 532 #ifndef PRODUCT
aoqi@0 533 // Statistics
aoqi@0 534 static int _nof_invocations;
aoqi@0 535 static int _nof_rewrites;
aoqi@0 536 static int _nof_relocations;
aoqi@0 537 #endif
aoqi@0 538
aoqi@0 539 public:
aoqi@0 540 ResolveOopMapConflicts(methodHandle method) : GenerateOopMap(method) { _must_clear_locals = false; };
aoqi@0 541
aoqi@0 542 methodHandle do_potential_rewrite(TRAPS);
aoqi@0 543 bool must_clear_locals() const { return _must_clear_locals; }
aoqi@0 544 };
aoqi@0 545
aoqi@0 546
aoqi@0 547 //
aoqi@0 548 // Subclass used by the compiler to generate pairing infomation
aoqi@0 549 //
aoqi@0 550 class GeneratePairingInfo: public GenerateOopMap {
aoqi@0 551 private:
aoqi@0 552
aoqi@0 553 virtual bool report_results() const { return false; }
aoqi@0 554 virtual bool report_init_vars() const { return false; }
aoqi@0 555 virtual bool allow_rewrites() const { return false; }
aoqi@0 556 virtual bool possible_gc_point (BytecodeStream *bcs) { return false; }
aoqi@0 557 virtual void fill_stackmap_prolog (int nof_gc_points) {}
aoqi@0 558 virtual void fill_stackmap_epilog () {}
aoqi@0 559 virtual void fill_stackmap_for_opcodes (BytecodeStream *bcs,
aoqi@0 560 CellTypeState* vars,
aoqi@0 561 CellTypeState* stack,
aoqi@0 562 int stack_top) {}
aoqi@0 563 virtual void fill_init_vars (GrowableArray<intptr_t> *init_vars) {}
aoqi@0 564 public:
aoqi@0 565 GeneratePairingInfo(methodHandle method) : GenerateOopMap(method) {};
aoqi@0 566
aoqi@0 567 // Call compute_map(CHECK) to generate info.
aoqi@0 568 };
aoqi@0 569
aoqi@0 570 #endif // SHARE_VM_OOPS_GENERATEOOPMAP_HPP

mercurial