src/share/vm/ci/ciStreams.hpp

Tue, 18 Jun 2013 12:31:07 -0700

author
johnc
date
Tue, 18 Jun 2013 12:31:07 -0700
changeset 5277
01522ca68fc7
parent 4133
f6b0eb4e44cf
child 5914
d13d7aba8c12
permissions
-rw-r--r--

8015237: Parallelize string table scanning during strong root processing
Summary: Parallelize the scanning of the intern string table by having each GC worker claim a given number of buckets. Changes were also reviewed by Per Liden <per.liden@oracle.com>.
Reviewed-by: tschatzl, stefank, twisti

duke@435 1 /*
coleenp@4037 2 * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #ifndef SHARE_VM_CI_CISTREAMS_HPP
stefank@2314 26 #define SHARE_VM_CI_CISTREAMS_HPP
stefank@2314 27
stefank@2314 28 #include "ci/ciClassList.hpp"
stefank@2314 29 #include "ci/ciExceptionHandler.hpp"
stefank@2314 30 #include "ci/ciInstanceKlass.hpp"
stefank@2314 31 #include "ci/ciMethod.hpp"
stefank@2314 32 #include "interpreter/bytecode.hpp"
stefank@2314 33
duke@435 34 // ciBytecodeStream
duke@435 35 //
duke@435 36 // The class is used to iterate over the bytecodes of a method.
duke@435 37 // It hides the details of constant pool structure/access by
duke@435 38 // providing accessors for constant pool items. It returns only pure
duke@435 39 // Java bytecodes; VM-internal _fast bytecodes are translated back to
duke@435 40 // their original form during iteration.
duke@435 41 class ciBytecodeStream : StackObj {
duke@435 42 private:
jrose@1920 43 // Handling for the weird bytecodes
jrose@1920 44 Bytecodes::Code next_wide_or_table(Bytecodes::Code); // Handle _wide & complicated inline table
duke@435 45
duke@435 46 static Bytecodes::Code check_java(Bytecodes::Code c) {
duke@435 47 assert(Bytecodes::is_java_code(c), "should not return _fast bytecodes");
duke@435 48 return c;
duke@435 49 }
duke@435 50
jrose@1920 51 static Bytecodes::Code check_defined(Bytecodes::Code c) {
jrose@1920 52 assert(Bytecodes::is_defined(c), "");
jrose@1920 53 return c;
jrose@1920 54 }
jrose@1920 55
duke@435 56 ciMethod* _method; // the method
duke@435 57 ciInstanceKlass* _holder;
duke@435 58 address _bc_start; // Start of current bytecode for table
duke@435 59 address _was_wide; // Address past last wide bytecode
duke@435 60 jint* _table_base; // Aligned start of last table or switch
duke@435 61
duke@435 62 address _start; // Start of bytecodes
duke@435 63 address _end; // Past end of bytecodes
duke@435 64 address _pc; // Current PC
duke@435 65 Bytecodes::Code _bc; // Current bytecode
jrose@1920 66 Bytecodes::Code _raw_bc; // Current bytecode, raw form
duke@435 67
duke@435 68 void reset( address base, unsigned int size ) {
duke@435 69 _bc_start =_was_wide = 0;
jrose@1957 70 _start = _pc = base; _end = base + size;
jrose@1957 71 }
duke@435 72
jrose@1920 73 void assert_wide(bool require_wide) const {
jrose@1920 74 if (require_wide)
jrose@1920 75 { assert(is_wide(), "must be a wide instruction"); }
jrose@1920 76 else { assert(!is_wide(), "must not be a wide instruction"); }
jrose@1920 77 }
jrose@1920 78
never@2462 79 Bytecode bytecode() const { return Bytecode(this, _bc_start); }
never@2462 80 Bytecode next_bytecode() const { return Bytecode(this, _pc); }
jrose@1920 81
duke@435 82 public:
duke@435 83 // End-Of-Bytecodes
duke@435 84 static Bytecodes::Code EOBC() {
duke@435 85 return Bytecodes::_illegal;
duke@435 86 }
duke@435 87
duke@435 88 ciBytecodeStream(ciMethod* m) {
duke@435 89 reset_to_method(m);
duke@435 90 }
duke@435 91
duke@435 92 ciBytecodeStream() {
duke@435 93 reset_to_method(NULL);
duke@435 94 }
duke@435 95
duke@435 96 ciMethod* method() const { return _method; }
duke@435 97
duke@435 98 void reset_to_method(ciMethod* m) {
duke@435 99 _method = m;
duke@435 100 if (m == NULL) {
duke@435 101 _holder = NULL;
duke@435 102 reset(NULL, 0);
duke@435 103 } else {
duke@435 104 _holder = m->holder();
duke@435 105 reset(m->code(), m->code_size());
duke@435 106 }
duke@435 107 }
duke@435 108
duke@435 109 void reset_to_bci( int bci );
duke@435 110
duke@435 111 // Force the iterator to report a certain bci.
duke@435 112 void force_bci(int bci);
duke@435 113
duke@435 114 void set_max_bci( int max ) {
duke@435 115 _end = _start + max;
duke@435 116 }
duke@435 117
jrose@1161 118 address cur_bcp() const { return _bc_start; } // Returns bcp to current instruction
jrose@1920 119 int next_bci() const { return _pc - _start; }
duke@435 120 int cur_bci() const { return _bc_start - _start; }
jrose@1161 121 int instruction_size() const { return _pc - _bc_start; }
duke@435 122
duke@435 123 Bytecodes::Code cur_bc() const{ return check_java(_bc); }
jrose@1920 124 Bytecodes::Code cur_bc_raw() const { return check_defined(_raw_bc); }
duke@435 125 Bytecodes::Code next_bc() { return Bytecodes::java_code((Bytecodes::Code)* _pc); }
duke@435 126
duke@435 127 // Return current ByteCode and increment PC to next bytecode, skipping all
duke@435 128 // intermediate constants. Returns EOBC at end.
duke@435 129 // Expected usage:
twisti@3097 130 // ciBytecodeStream iter(m);
twisti@3097 131 // while (iter.next() != ciBytecodeStream::EOBC()) { ... }
duke@435 132 Bytecodes::Code next() {
duke@435 133 _bc_start = _pc; // Capture start of bc
duke@435 134 if( _pc >= _end ) return EOBC(); // End-Of-Bytecodes
duke@435 135
duke@435 136 // Fetch Java bytecode
duke@435 137 // All rewritten bytecodes maintain the size of original bytecode.
jrose@1920 138 _bc = Bytecodes::java_code(_raw_bc = (Bytecodes::Code)*_pc);
duke@435 139 int csize = Bytecodes::length_for(_bc); // Expected size
jrose@1920 140 _pc += csize; // Bump PC past bytecode
jrose@1920 141 if (csize == 0) {
jrose@1920 142 _bc = next_wide_or_table(_bc);
duke@435 143 }
duke@435 144 return check_java(_bc);
duke@435 145 }
duke@435 146
jrose@1161 147 bool is_wide() const { return ( _pc == _was_wide ); }
duke@435 148
jrose@1920 149 // Does this instruction contain an index which refes into the CP cache?
jrose@1957 150 bool has_cache_index() const { return Bytecodes::uses_cp_cache(cur_bc_raw()); }
jrose@1920 151
twisti@4021 152 bool has_optional_appendix() { return Bytecodes::has_optional_appendix(cur_bc_raw()); }
twisti@4021 153
jrose@1920 154 int get_index_u1() const {
never@2462 155 return bytecode().get_index_u1(cur_bc_raw());
jrose@1920 156 }
jrose@1920 157
jrose@1957 158 int get_index_u1_cpcache() const {
never@2462 159 return bytecode().get_index_u1_cpcache(cur_bc_raw());
jrose@1957 160 }
jrose@1957 161
duke@435 162 // Get a byte index following this bytecode.
duke@435 163 // If prefixed with a wide bytecode, get a wide index.
duke@435 164 int get_index() const {
jrose@1957 165 assert(!has_cache_index(), "else use cpcache variant");
duke@435 166 return (_pc == _was_wide) // was widened?
jrose@1920 167 ? get_index_u2(true) // yes, return wide index
jrose@1920 168 : get_index_u1(); // no, return narrow index
duke@435 169 }
duke@435 170
jrose@1920 171 // Get 2-byte index (byte swapping depending on which bytecode)
jrose@1920 172 int get_index_u2(bool is_wide = false) const {
never@2462 173 return bytecode().get_index_u2(cur_bc_raw(), is_wide);
duke@435 174 }
duke@435 175
jrose@1920 176 // Get 2-byte index in native byte order. (Rewriter::rewrite makes these.)
jrose@1920 177 int get_index_u2_cpcache() const {
never@2462 178 return bytecode().get_index_u2_cpcache(cur_bc_raw());
jrose@1161 179 }
jrose@1161 180
jrose@1161 181 // Get 4-byte index, for invokedynamic.
jrose@1920 182 int get_index_u4() const {
never@2462 183 return bytecode().get_index_u4(cur_bc_raw());
jrose@1161 184 }
jrose@1161 185
jrose@1920 186 bool has_index_u4() const {
never@2462 187 return bytecode().has_index_u4(cur_bc_raw());
jrose@1920 188 }
duke@435 189
duke@435 190 // Get dimensions byte (multinewarray)
duke@435 191 int get_dimensions() const { return *(unsigned char*)(_pc-1); }
duke@435 192
duke@435 193 // Sign-extended index byte/short, no widening
never@2462 194 int get_constant_u1() const { return bytecode().get_constant_u1(instruction_size()-1, cur_bc_raw()); }
never@2462 195 int get_constant_u2(bool is_wide = false) const { return bytecode().get_constant_u2(instruction_size()-2, cur_bc_raw(), is_wide); }
duke@435 196
duke@435 197 // Get a byte signed constant for "iinc". Invalid for other bytecodes.
duke@435 198 // If prefixed with a wide bytecode, get a wide constant
jrose@1920 199 int get_iinc_con() const {return (_pc==_was_wide) ? (jshort) get_constant_u2(true) : (jbyte) get_constant_u1();}
duke@435 200
duke@435 201 // 2-byte branch offset from current pc
jrose@1920 202 int get_dest() const {
never@2462 203 return cur_bci() + bytecode().get_offset_s2(cur_bc_raw());
duke@435 204 }
duke@435 205
duke@435 206 // 2-byte branch offset from next pc
jrose@1920 207 int next_get_dest() const {
jrose@1920 208 assert(_pc < _end, "");
never@2462 209 return next_bci() + next_bytecode().get_offset_s2(Bytecodes::_ifeq);
duke@435 210 }
duke@435 211
duke@435 212 // 4-byte branch offset from current pc
jrose@1920 213 int get_far_dest() const {
never@2462 214 return cur_bci() + bytecode().get_offset_s4(cur_bc_raw());
duke@435 215 }
duke@435 216
duke@435 217 // For a lookup or switch table, return target destination
duke@435 218 int get_int_table( int index ) const {
duke@435 219 return Bytes::get_Java_u4((address)&_table_base[index]); }
duke@435 220
duke@435 221 // For tableswitch - get length of offset part
duke@435 222 int get_tableswitch_length() { return get_int_table(2)-get_int_table(1)+1; }
duke@435 223
duke@435 224 int get_dest_table( int index ) const {
duke@435 225 return cur_bci() + get_int_table(index); }
duke@435 226
duke@435 227 // --- Constant pool access ---
jrose@1957 228 int get_constant_raw_index() const;
jrose@1957 229 int get_constant_pool_index() const;
jrose@1957 230 int get_constant_cache_index() const;
duke@435 231 int get_field_index();
duke@435 232 int get_method_index();
duke@435 233
duke@435 234 // If this bytecode is a new, newarray, multianewarray, instanceof,
duke@435 235 // or checkcast, get the referenced klass.
duke@435 236 ciKlass* get_klass(bool& will_link);
duke@435 237 int get_klass_index() const;
duke@435 238
duke@435 239 // If this bytecode is one of the ldc variants, get the referenced
jrose@1957 240 // constant. Do not attempt to resolve it, since that would require
jrose@1957 241 // execution of Java code. If it is not resolved, return an unloaded
jrose@1957 242 // object (ciConstant.as_object()->is_loaded() == false).
duke@435 243 ciConstant get_constant();
jrose@1957 244 constantTag get_constant_pool_tag(int index) const;
jrose@1957 245
jrose@1957 246 // True if the klass-using bytecode points to an unresolved klass
jrose@1957 247 bool is_unresolved_klass() const {
jrose@1957 248 constantTag tag = get_constant_pool_tag(get_klass_index());
jrose@1957 249 return tag.is_unresolved_klass();
jrose@1957 250 }
duke@435 251
duke@435 252 // If this bytecode is one of get_field, get_static, put_field,
duke@435 253 // or put_static, get the referenced field.
duke@435 254 ciField* get_field(bool& will_link);
duke@435 255
duke@435 256 ciInstanceKlass* get_declared_field_holder();
duke@435 257 int get_field_holder_index();
duke@435 258 int get_field_signature_index();
duke@435 259
twisti@4133 260 ciMethod* get_method(bool& will_link, ciSignature* *declared_signature_result);
twisti@4133 261 bool has_appendix();
twisti@4133 262 ciObject* get_appendix();
twisti@4133 263 bool has_method_type();
twisti@4133 264 ciMethodType* get_method_type();
twisti@4133 265 ciKlass* get_declared_method_holder();
twisti@4133 266 int get_method_holder_index();
twisti@4133 267 int get_method_signature_index();
jrose@1161 268
coleenp@4037 269 // Get the resolved references arrays from the constant pool
coleenp@4037 270 ciObjArray* get_resolved_references();
duke@435 271 };
duke@435 272
duke@435 273
duke@435 274 // ciSignatureStream
duke@435 275 //
duke@435 276 // The class is used to iterate over the elements of a method signature.
duke@435 277 class ciSignatureStream : public StackObj {
duke@435 278 private:
duke@435 279 ciSignature* _sig;
duke@435 280 int _pos;
duke@435 281 public:
duke@435 282 ciSignatureStream(ciSignature* signature) {
duke@435 283 _sig = signature;
duke@435 284 _pos = 0;
duke@435 285 }
duke@435 286
duke@435 287 bool at_return_type() { return _pos == _sig->count(); }
duke@435 288
duke@435 289 bool is_done() { return _pos > _sig->count(); }
duke@435 290
duke@435 291 void next() {
duke@435 292 if (_pos <= _sig->count()) {
duke@435 293 _pos++;
duke@435 294 }
duke@435 295 }
duke@435 296
duke@435 297 ciType* type() {
duke@435 298 if (at_return_type()) {
duke@435 299 return _sig->return_type();
duke@435 300 } else {
duke@435 301 return _sig->type_at(_pos);
duke@435 302 }
duke@435 303 }
duke@435 304 };
duke@435 305
duke@435 306
duke@435 307 // ciExceptionHandlerStream
duke@435 308 //
duke@435 309 // The class is used to iterate over the exception handlers of
duke@435 310 // a method.
duke@435 311 class ciExceptionHandlerStream : public StackObj {
duke@435 312 private:
duke@435 313 // The method whose handlers we are traversing
duke@435 314 ciMethod* _method;
duke@435 315
duke@435 316 // Our current position in the list of handlers
duke@435 317 int _pos;
duke@435 318 int _end;
duke@435 319
duke@435 320 ciInstanceKlass* _exception_klass;
duke@435 321 int _bci;
duke@435 322 bool _is_exact;
duke@435 323
duke@435 324 public:
duke@435 325 ciExceptionHandlerStream(ciMethod* method) {
duke@435 326 _method = method;
duke@435 327
duke@435 328 // Force loading of method code and handlers.
duke@435 329 _method->code();
duke@435 330
duke@435 331 _pos = 0;
duke@435 332 _end = _method->_handler_count;
duke@435 333 _exception_klass = NULL;
duke@435 334 _bci = -1;
duke@435 335 _is_exact = false;
duke@435 336 }
duke@435 337
duke@435 338 ciExceptionHandlerStream(ciMethod* method, int bci,
duke@435 339 ciInstanceKlass* exception_klass = NULL,
duke@435 340 bool is_exact = false) {
duke@435 341 _method = method;
duke@435 342
duke@435 343 // Force loading of method code and handlers.
duke@435 344 _method->code();
duke@435 345
duke@435 346 _pos = -1;
duke@435 347 _end = _method->_handler_count + 1; // include the rethrow handler
duke@435 348 _exception_klass = (exception_klass != NULL && exception_klass->is_loaded()
duke@435 349 ? exception_klass
duke@435 350 : NULL);
duke@435 351 _bci = bci;
duke@435 352 assert(_bci >= 0, "bci out of range");
duke@435 353 _is_exact = is_exact;
duke@435 354 next();
duke@435 355 }
duke@435 356
duke@435 357 // These methods are currently implemented in an odd way.
duke@435 358 // Count the number of handlers the iterator has ever produced
duke@435 359 // or will ever produce. Do not include the final rethrow handler.
duke@435 360 // That is, a trivial exception handler stream will have a count
duke@435 361 // of zero and produce just the rethrow handler.
duke@435 362 int count();
duke@435 363
duke@435 364 // Count the number of handlers this stream will produce from now on.
duke@435 365 // Include the current handler, and the final rethrow handler.
duke@435 366 // The remaining count will be zero iff is_done() is true,
duke@435 367 int count_remaining();
duke@435 368
duke@435 369 bool is_done() {
duke@435 370 return (_pos >= _end);
duke@435 371 }
duke@435 372
duke@435 373 void next() {
duke@435 374 _pos++;
duke@435 375 if (_bci != -1) {
duke@435 376 // We are not iterating over all handlers...
duke@435 377 while (!is_done()) {
duke@435 378 ciExceptionHandler* handler = _method->_exception_handlers[_pos];
duke@435 379 if (handler->is_in_range(_bci)) {
duke@435 380 if (handler->is_catch_all()) {
duke@435 381 // Found final active catch block.
duke@435 382 _end = _pos+1;
duke@435 383 return;
duke@435 384 } else if (_exception_klass == NULL || !handler->catch_klass()->is_loaded()) {
duke@435 385 // We cannot do any type analysis here. Must conservatively assume
duke@435 386 // catch block is reachable.
duke@435 387 return;
duke@435 388 } else if (_exception_klass->is_subtype_of(handler->catch_klass())) {
duke@435 389 // This catch clause will definitely catch the exception.
duke@435 390 // Final candidate.
duke@435 391 _end = _pos+1;
duke@435 392 return;
duke@435 393 } else if (!_is_exact &&
duke@435 394 handler->catch_klass()->is_subtype_of(_exception_klass)) {
duke@435 395 // This catch block may be reachable.
duke@435 396 return;
duke@435 397 }
duke@435 398 }
duke@435 399
duke@435 400 // The catch block was not pertinent. Go on.
duke@435 401 _pos++;
duke@435 402 }
duke@435 403 } else {
duke@435 404 // This is an iteration over all handlers.
duke@435 405 return;
duke@435 406 }
duke@435 407 }
duke@435 408
duke@435 409 ciExceptionHandler* handler() {
duke@435 410 return _method->_exception_handlers[_pos];
duke@435 411 }
duke@435 412 };
stefank@2314 413
never@2462 414
never@2462 415
never@2462 416 // Implementation for declarations in bytecode.hpp
never@2462 417 Bytecode::Bytecode(const ciBytecodeStream* stream, address bcp): _bcp(bcp != NULL ? bcp : stream->cur_bcp()), _code(Bytecodes::code_at(NULL, addr_at(0))) {}
never@2462 418 Bytecode_lookupswitch::Bytecode_lookupswitch(const ciBytecodeStream* stream): Bytecode(stream) { verify(); }
never@2462 419 Bytecode_tableswitch::Bytecode_tableswitch(const ciBytecodeStream* stream): Bytecode(stream) { verify(); }
never@2462 420
stefank@2314 421 #endif // SHARE_VM_CI_CISTREAMS_HPP

mercurial