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 "runtime/orderAccess.hpp"
32 #include "utilities/align.hpp"
33
34 class PSPromotionManager;
35
36 // The ConstantPoolCache is not a cache! It is the resolution table that the
37 // interpreter uses to avoid going into the runtime and a way to access resolved
38 // values.
39
40 // A ConstantPoolCacheEntry describes an individual entry of the constant
41 // pool cache. There's 2 principal kinds of entries: field entries for in-
42 // stance & static field access, and method entries for invokes. Some of
43 // the entry layout is shared and looks as follows:
44 //
45 // bit number |31 0|
46 // bit length |-8--|-8--|---16----|
47 // --------------------------------
48 // _indices [ b2 | b1 | index ] index = constant_pool_index
49 // _f1 [ entry specific ] metadata ptr (method or klass)
50 // _f2 [ entry specific ] vtable or res_ref index, or vfinal method ptr
396
397
398 // A constant pool cache is a runtime data structure set aside to a constant pool. The cache
399 // holds interpreter runtime information for all field access and invoke bytecodes. The cache
400 // is created and initialized before a class is actively used (i.e., initialized), the indivi-
401 // dual cache entries are filled at resolution (i.e., "link") time (see also: rewriter.*).
402
403 class ConstantPoolCache: public MetaspaceObj {
404 friend class VMStructs;
405 friend class MetadataFactory;
406 private:
407 // If you add a new field that points to any metaspace object, you
408 // must add this field to ConstantPoolCache::metaspace_pointers_do().
409 int _length;
410 ConstantPool* _constant_pool; // the corresponding constant pool
411
412 // The following fields need to be modified at runtime, so they cannot be
413 // stored in the ConstantPool, which is read-only.
414 // Array of resolved objects from the constant pool and map from resolved
415 // object index to original constant pool index
416 jobject _resolved_references;
417 Array<u2>* _reference_map;
418
419 // Sizing
420 debug_only(friend class ClassVerifier;)
421
422 // Constructor
423 ConstantPoolCache(int length,
424 const intStack& inverse_index_map,
425 const intStack& invokedynamic_inverse_index_map,
426 const intStack& invokedynamic_references_map) :
427 _length(length),
428 _constant_pool(NULL) {
429 initialize(inverse_index_map, invokedynamic_inverse_index_map,
430 invokedynamic_references_map);
431 for (int i = 0; i < length; i++) {
432 assert(entry_at(i)->is_f1_null(), "Failed to clear?");
433 }
434 }
435
436 // Initialization
437 void initialize(const intArray& inverse_index_map,
438 const intArray& invokedynamic_inverse_index_map,
439 const intArray& invokedynamic_references_map);
440 public:
441 static ConstantPoolCache* allocate(ClassLoaderData* loader_data,
442 const intStack& cp_cache_map,
443 const intStack& invokedynamic_cp_cache_map,
444 const intStack& invokedynamic_references_map, TRAPS);
445 bool is_constantPoolCache() const { return true; }
446
447 int length() const { return _length; }
448 void metaspace_pointers_do(MetaspaceClosure* it);
449 MetaspaceObj::Type type() const { return ConstantPoolCacheType; }
450
451 jobject resolved_references() { return _resolved_references; }
452 void set_resolved_references(jobject s) { _resolved_references = s; }
453 Array<u2>* reference_map() const { return _reference_map; }
454 void set_reference_map(Array<u2>* o) { _reference_map = o; }
455
456 // Assembly code support
457 static int resolved_references_offset_in_bytes() { return offset_of(ConstantPoolCache, _resolved_references); }
458
459 private:
460 void set_length(int length) { _length = length; }
461
462 static int header_size() { return sizeof(ConstantPoolCache) / wordSize; }
463 static int size(int length) { return align_metadata_size(header_size() + length * in_words(ConstantPoolCacheEntry::size())); }
464 public:
465 int size() const { return size(length()); }
466 private:
467
468 // Helpers
469 ConstantPool** constant_pool_addr() { return &_constant_pool; }
470 ConstantPoolCacheEntry* base() const { return (ConstantPoolCacheEntry*)((address)this + in_bytes(base_offset())); }
471
472 friend class constantPoolCacheKlass;
|
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
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
397
398
399 // A constant pool cache is a runtime data structure set aside to a constant pool. The cache
400 // holds interpreter runtime information for all field access and invoke bytecodes. The cache
401 // is created and initialized before a class is actively used (i.e., initialized), the indivi-
402 // dual cache entries are filled at resolution (i.e., "link") time (see also: rewriter.*).
403
404 class ConstantPoolCache: public MetaspaceObj {
405 friend class VMStructs;
406 friend class MetadataFactory;
407 private:
408 // If you add a new field that points to any metaspace object, you
409 // must add this field to ConstantPoolCache::metaspace_pointers_do().
410 int _length;
411 ConstantPool* _constant_pool; // the corresponding constant pool
412
413 // The following fields need to be modified at runtime, so they cannot be
414 // stored in the ConstantPool, which is read-only.
415 // Array of resolved objects from the constant pool and map from resolved
416 // object index to original constant pool index
417 OopHandle _resolved_references;
418 Array<u2>* _reference_map;
419
420 // Sizing
421 debug_only(friend class ClassVerifier;)
422
423 // Constructor
424 ConstantPoolCache(int length,
425 const intStack& inverse_index_map,
426 const intStack& invokedynamic_inverse_index_map,
427 const intStack& invokedynamic_references_map) :
428 _length(length),
429 _constant_pool(NULL) {
430 initialize(inverse_index_map, invokedynamic_inverse_index_map,
431 invokedynamic_references_map);
432 for (int i = 0; i < length; i++) {
433 assert(entry_at(i)->is_f1_null(), "Failed to clear?");
434 }
435 }
436
437 // Initialization
438 void initialize(const intArray& inverse_index_map,
439 const intArray& invokedynamic_inverse_index_map,
440 const intArray& invokedynamic_references_map);
441 public:
442 static ConstantPoolCache* allocate(ClassLoaderData* loader_data,
443 const intStack& cp_cache_map,
444 const intStack& invokedynamic_cp_cache_map,
445 const intStack& invokedynamic_references_map, TRAPS);
446 bool is_constantPoolCache() const { return true; }
447
448 int length() const { return _length; }
449 void metaspace_pointers_do(MetaspaceClosure* it);
450 MetaspaceObj::Type type() const { return ConstantPoolCacheType; }
451
452 oop resolved_references() { return _resolved_references.resolve(); }
453 void set_resolved_references(OopHandle s) { _resolved_references = s; }
454 Array<u2>* reference_map() const { return _reference_map; }
455 void set_reference_map(Array<u2>* o) { _reference_map = o; }
456
457 // Assembly code support
458 static int resolved_references_offset_in_bytes() { return offset_of(ConstantPoolCache, _resolved_references); }
459
460 private:
461 void set_length(int length) { _length = length; }
462
463 static int header_size() { return sizeof(ConstantPoolCache) / wordSize; }
464 static int size(int length) { return align_metadata_size(header_size() + length * in_words(ConstantPoolCacheEntry::size())); }
465 public:
466 int size() const { return size(length()); }
467 private:
468
469 // Helpers
470 ConstantPool** constant_pool_addr() { return &_constant_pool; }
471 ConstantPoolCacheEntry* base() const { return (ConstantPoolCacheEntry*)((address)this + in_bytes(base_offset())); }
472
473 friend class constantPoolCacheKlass;
|