1 /*
2 * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_VM_OOPS_CPCACHEOOP_HPP
26 #define SHARE_VM_OOPS_CPCACHEOOP_HPP
27
28 #include "interpreter/bytecodes.hpp"
29 #include "memory/allocation.hpp"
30 #include "oops/array.hpp"
31 #include "oops/oopHandle.hpp"
32 #include "runtime/orderAccess.hpp"
33 #include "utilities/align.hpp"
34 #include "utilities/constantTag.hpp"
35
36 class PSPromotionManager;
37
38 // The ConstantPoolCache is not a cache! It is the resolution table that the
39 // interpreter uses to avoid going into the runtime and a way to access resolved
40 // values.
41
42 // A ConstantPoolCacheEntry describes an individual entry of the constant
43 // pool cache. There's 2 principal kinds of entries: field entries for in-
44 // stance & static field access, and method entries for invokes. Some of
45 // the entry layout is shared and looks as follows:
46 //
47 // bit number |31 0|
48 // bit length |-8--|-8--|---16----|
49 // --------------------------------
50 // _indices [ b2 | b1 | index ] index = constant_pool_index
51 // _f1 [ entry specific ] metadata ptr (method or klass)
52 // _f2 [ entry specific ] vtable or res_ref index, or vfinal method ptr
311 // Which bytecode number (1 or 2) in the index field is valid for this bytecode?
312 // Returns -1 if neither is valid.
313 static int bytecode_number(Bytecodes::Code code) {
314 switch (code) {
315 case Bytecodes::_getstatic : // fall through
316 case Bytecodes::_getfield : // fall through
317 case Bytecodes::_invokespecial : // fall through
318 case Bytecodes::_invokestatic : // fall through
319 case Bytecodes::_invokehandle : // fall through
320 case Bytecodes::_invokedynamic : // fall through
321 case Bytecodes::_invokeinterface : return 1;
322 case Bytecodes::_putstatic : // fall through
323 case Bytecodes::_putfield : // fall through
324 case Bytecodes::_invokevirtual : return 2;
325 default : break;
326 }
327 return -1;
328 }
329
330 // Has this bytecode been resolved? Only valid for invokes and get/put field/static.
331 bool is_resolved(Bytecodes::Code code) const {
332 switch (bytecode_number(code)) {
333 case 1: return (bytecode_1() == code);
334 case 2: return (bytecode_2() == code);
335 }
336 return false; // default: not resolved
337 }
338
339 // Accessors
340 int indices() const { return _indices; }
341 int indices_ord() const { return OrderAccess::load_acquire(&_indices); }
342 int constant_pool_index() const { return (indices() & cp_index_mask); }
343 Bytecodes::Code bytecode_1() const { return Bytecodes::cast((indices_ord() >> bytecode_1_shift) & bytecode_1_mask); }
344 Bytecodes::Code bytecode_2() const { return Bytecodes::cast((indices_ord() >> bytecode_2_shift) & bytecode_2_mask); }
345 Metadata* f1_ord() const { return (Metadata *)OrderAccess::load_acquire(&_f1); }
346 Method* f1_as_method() const { Metadata* f1 = f1_ord(); assert(f1 == NULL || f1->is_method(), ""); return (Method*)f1; }
347 Klass* f1_as_klass() const { Metadata* f1 = f1_ord(); assert(f1 == NULL || f1->is_klass(), ""); return (Klass*)f1; }
348 // Use the accessor f1() to acquire _f1's value. This is needed for
349 // example in BytecodeInterpreter::run(), where is_f1_null() is
350 // called to check if an invokedynamic call is resolved. This load
351 // of _f1 must be ordered with the loads performed by
352 // cache->main_entry_index().
353 bool is_f1_null() const { Metadata* f1 = f1_ord(); return f1 == NULL; } // classifies a CPC entry as unbound
354 int f2_as_index() const { assert(!is_vfinal(), ""); return (int) _f2; }
355 Method* f2_as_vfinal_method() const { assert(is_vfinal(), ""); return (Method*)_f2; }
356 Method* f2_as_interface_method() const { assert(bytecode_1() == Bytecodes::_invokeinterface, ""); return (Method*)_f2; }
357 intx flags_ord() const { return (intx)OrderAccess::load_acquire(&_flags); }
358 int field_index() const { assert(is_field_entry(), ""); return (_flags & field_index_mask); }
359 int parameter_size() const { assert(is_method_entry(), ""); return (_flags & parameter_size_mask); }
360 bool is_volatile() const { return (_flags & (1 << is_volatile_shift)) != 0; }
361 bool is_final() const { return (_flags & (1 << is_final_shift)) != 0; }
362 bool is_forced_virtual() const { return (_flags & (1 << is_forced_virtual_shift)) != 0; }
363 bool is_vfinal() const { return (_flags & (1 << is_vfinal_shift)) != 0; }
364 bool indy_resolution_failed() const { intx flags = flags_ord(); return (flags & (1 << indy_resolution_failed_shift)) != 0; }
365 bool has_appendix() const { return (!is_f1_null()) && (_flags & (1 << has_appendix_shift)) != 0; }
366 bool has_method_type() const { return (!is_f1_null()) && (_flags & (1 << has_method_type_shift)) != 0; }
367 bool is_method_entry() const { return (_flags & (1 << is_field_entry_shift)) == 0; }
368 bool is_field_entry() const { return (_flags & (1 << is_field_entry_shift)) != 0; }
369 bool is_long() const { return flag_state() == ltos; }
370 bool is_double() const { return flag_state() == dtos; }
371 TosState flag_state() const { assert((uint)number_of_states <= (uint)tos_state_mask+1, "");
372 return (TosState)((_flags >> tos_state_shift) & tos_state_mask); }
373 void set_indy_resolution_failed();
374
375 // Code generation support
376 static WordSize size() {
377 return in_WordSize(align_up((int)sizeof(ConstantPoolCacheEntry), wordSize) / wordSize);
378 }
379 static ByteSize size_in_bytes() { return in_ByteSize(sizeof(ConstantPoolCacheEntry)); }
380 static ByteSize indices_offset() { return byte_offset_of(ConstantPoolCacheEntry, _indices); }
381 static ByteSize f1_offset() { return byte_offset_of(ConstantPoolCacheEntry, _f1); }
382 static ByteSize f2_offset() { return byte_offset_of(ConstantPoolCacheEntry, _f2); }
383 static ByteSize flags_offset() { return byte_offset_of(ConstantPoolCacheEntry, _flags); }
384
385 #if INCLUDE_JVMTI
386 // RedefineClasses() API support:
423 int _length;
424 ConstantPool* _constant_pool; // the corresponding constant pool
425
426 // The following fields need to be modified at runtime, so they cannot be
427 // stored in the ConstantPool, which is read-only.
428 // Array of resolved objects from the constant pool and map from resolved
429 // object index to original constant pool index
430 OopHandle _resolved_references;
431 Array<u2>* _reference_map;
432 // The narrowOop pointer to the archived resolved_references. Set at CDS dump
433 // time when caching java heap object is supported.
434 CDS_JAVA_HEAP_ONLY(narrowOop _archived_references;)
435
436 // Sizing
437 debug_only(friend class ClassVerifier;)
438
439 // Constructor
440 ConstantPoolCache(int length,
441 const intStack& inverse_index_map,
442 const intStack& invokedynamic_inverse_index_map,
443 const intStack& invokedynamic_references_map) :
444 _length(length),
445 _constant_pool(NULL) {
446 CDS_JAVA_HEAP_ONLY(_archived_references = 0;)
447 initialize(inverse_index_map, invokedynamic_inverse_index_map,
448 invokedynamic_references_map);
449 for (int i = 0; i < length; i++) {
450 assert(entry_at(i)->is_f1_null(), "Failed to clear?");
451 }
452 }
453
454 // Initialization
455 void initialize(const intArray& inverse_index_map,
456 const intArray& invokedynamic_inverse_index_map,
457 const intArray& invokedynamic_references_map);
458 public:
459 static ConstantPoolCache* allocate(ClassLoaderData* loader_data,
460 const intStack& cp_cache_map,
461 const intStack& invokedynamic_cp_cache_map,
462 const intStack& invokedynamic_references_map, TRAPS);
463 bool is_constantPoolCache() const { return true; }
464
465 int length() const { return _length; }
466 void metaspace_pointers_do(MetaspaceClosure* it);
467 MetaspaceObj::Type type() const { return ConstantPoolCacheType; }
468
469 oop archived_references() NOT_CDS_JAVA_HEAP_RETURN_(NULL);
470 void set_archived_references(oop o) NOT_CDS_JAVA_HEAP_RETURN;
471
472 oop resolved_references() { return _resolved_references.resolve(); }
|
1 /*
2 * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_VM_OOPS_CPCACHEOOP_HPP
26 #define SHARE_VM_OOPS_CPCACHEOOP_HPP
27
28 #include "interpreter/bytecodes.hpp"
29 #include "memory/allocation.hpp"
30 #include "oops/array.hpp"
31 #include "oops/oopHandle.hpp"
32 #include "utilities/align.hpp"
33 #include "utilities/constantTag.hpp"
34
35 class PSPromotionManager;
36
37 // The ConstantPoolCache is not a cache! It is the resolution table that the
38 // interpreter uses to avoid going into the runtime and a way to access resolved
39 // values.
40
41 // A ConstantPoolCacheEntry describes an individual entry of the constant
42 // pool cache. There's 2 principal kinds of entries: field entries for in-
43 // stance & static field access, and method entries for invokes. Some of
44 // the entry layout is shared and looks as follows:
45 //
46 // bit number |31 0|
47 // bit length |-8--|-8--|---16----|
48 // --------------------------------
49 // _indices [ b2 | b1 | index ] index = constant_pool_index
50 // _f1 [ entry specific ] metadata ptr (method or klass)
51 // _f2 [ entry specific ] vtable or res_ref index, or vfinal method ptr
310 // Which bytecode number (1 or 2) in the index field is valid for this bytecode?
311 // Returns -1 if neither is valid.
312 static int bytecode_number(Bytecodes::Code code) {
313 switch (code) {
314 case Bytecodes::_getstatic : // fall through
315 case Bytecodes::_getfield : // fall through
316 case Bytecodes::_invokespecial : // fall through
317 case Bytecodes::_invokestatic : // fall through
318 case Bytecodes::_invokehandle : // fall through
319 case Bytecodes::_invokedynamic : // fall through
320 case Bytecodes::_invokeinterface : return 1;
321 case Bytecodes::_putstatic : // fall through
322 case Bytecodes::_putfield : // fall through
323 case Bytecodes::_invokevirtual : return 2;
324 default : break;
325 }
326 return -1;
327 }
328
329 // Has this bytecode been resolved? Only valid for invokes and get/put field/static.
330 bool is_resolved(Bytecodes::Code code) const;
331
332 // Accessors
333 int indices() const { return _indices; }
334 int indices_ord() const;
335 int constant_pool_index() const { return (indices() & cp_index_mask); }
336 Bytecodes::Code bytecode_1() const;
337 Bytecodes::Code bytecode_2() const;
338 Metadata* f1_ord() const;
339 Method* f1_as_method() const;
340 Klass* f1_as_klass() const;
341 // Use the accessor f1() to acquire _f1's value. This is needed for
342 // example in BytecodeInterpreter::run(), where is_f1_null() is
343 // called to check if an invokedynamic call is resolved. This load
344 // of _f1 must be ordered with the loads performed by
345 // cache->main_entry_index().
346 bool is_f1_null() const; // classifies a CPC entry as unbound
347 int f2_as_index() const { assert(!is_vfinal(), ""); return (int) _f2; }
348 Method* f2_as_vfinal_method() const { assert(is_vfinal(), ""); return (Method*)_f2; }
349 Method* f2_as_interface_method() const;
350 intx flags_ord() const;
351 int field_index() const { assert(is_field_entry(), ""); return (_flags & field_index_mask); }
352 int parameter_size() const { assert(is_method_entry(), ""); return (_flags & parameter_size_mask); }
353 bool is_volatile() const { return (_flags & (1 << is_volatile_shift)) != 0; }
354 bool is_final() const { return (_flags & (1 << is_final_shift)) != 0; }
355 bool is_forced_virtual() const { return (_flags & (1 << is_forced_virtual_shift)) != 0; }
356 bool is_vfinal() const { return (_flags & (1 << is_vfinal_shift)) != 0; }
357 bool indy_resolution_failed() const;
358 bool has_appendix() const;
359 bool has_method_type() const;
360 bool is_method_entry() const { return (_flags & (1 << is_field_entry_shift)) == 0; }
361 bool is_field_entry() const { return (_flags & (1 << is_field_entry_shift)) != 0; }
362 bool is_long() const { return flag_state() == ltos; }
363 bool is_double() const { return flag_state() == dtos; }
364 TosState flag_state() const { assert((uint)number_of_states <= (uint)tos_state_mask+1, "");
365 return (TosState)((_flags >> tos_state_shift) & tos_state_mask); }
366 void set_indy_resolution_failed();
367
368 // Code generation support
369 static WordSize size() {
370 return in_WordSize(align_up((int)sizeof(ConstantPoolCacheEntry), wordSize) / wordSize);
371 }
372 static ByteSize size_in_bytes() { return in_ByteSize(sizeof(ConstantPoolCacheEntry)); }
373 static ByteSize indices_offset() { return byte_offset_of(ConstantPoolCacheEntry, _indices); }
374 static ByteSize f1_offset() { return byte_offset_of(ConstantPoolCacheEntry, _f1); }
375 static ByteSize f2_offset() { return byte_offset_of(ConstantPoolCacheEntry, _f2); }
376 static ByteSize flags_offset() { return byte_offset_of(ConstantPoolCacheEntry, _flags); }
377
378 #if INCLUDE_JVMTI
379 // RedefineClasses() API support:
416 int _length;
417 ConstantPool* _constant_pool; // the corresponding constant pool
418
419 // The following fields need to be modified at runtime, so they cannot be
420 // stored in the ConstantPool, which is read-only.
421 // Array of resolved objects from the constant pool and map from resolved
422 // object index to original constant pool index
423 OopHandle _resolved_references;
424 Array<u2>* _reference_map;
425 // The narrowOop pointer to the archived resolved_references. Set at CDS dump
426 // time when caching java heap object is supported.
427 CDS_JAVA_HEAP_ONLY(narrowOop _archived_references;)
428
429 // Sizing
430 debug_only(friend class ClassVerifier;)
431
432 // Constructor
433 ConstantPoolCache(int length,
434 const intStack& inverse_index_map,
435 const intStack& invokedynamic_inverse_index_map,
436 const intStack& invokedynamic_references_map);
437
438 // Initialization
439 void initialize(const intArray& inverse_index_map,
440 const intArray& invokedynamic_inverse_index_map,
441 const intArray& invokedynamic_references_map);
442 public:
443 static ConstantPoolCache* allocate(ClassLoaderData* loader_data,
444 const intStack& cp_cache_map,
445 const intStack& invokedynamic_cp_cache_map,
446 const intStack& invokedynamic_references_map, TRAPS);
447 bool is_constantPoolCache() const { return true; }
448
449 int length() const { return _length; }
450 void metaspace_pointers_do(MetaspaceClosure* it);
451 MetaspaceObj::Type type() const { return ConstantPoolCacheType; }
452
453 oop archived_references() NOT_CDS_JAVA_HEAP_RETURN_(NULL);
454 void set_archived_references(oop o) NOT_CDS_JAVA_HEAP_RETURN;
455
456 oop resolved_references() { return _resolved_references.resolve(); }
|