comparison src/share/vm/oops/constantPoolOop.hpp @ 1602:136b78722a08

6939203: JSR 292 needs method handle constants Summary: Add new CP types CONSTANT_MethodHandle, CONSTANT_MethodType; extend 'ldc' bytecode. Reviewed-by: twisti, never
author jrose
date Wed, 09 Jun 2010 18:50:45 -0700
parents e9ff18c4ace7
children 083fde3b838e
comparison
equal deleted inserted replaced
1585:49fac4acd688 1602:136b78722a08
144 *obj_at_addr(which) = NULL; 144 *obj_at_addr(which) = NULL;
145 release_tag_at_put(which, JVM_CONSTANT_UnresolvedClass); 145 release_tag_at_put(which, JVM_CONSTANT_UnresolvedClass);
146 oop_store_without_check(obj_at_addr(which), oop(s)); 146 oop_store_without_check(obj_at_addr(which), oop(s));
147 } 147 }
148 148
149 void method_handle_index_at_put(int which, int ref_kind, int ref_index) {
150 tag_at_put(which, JVM_CONSTANT_MethodHandle);
151 *int_at_addr(which) = ((jint) ref_index<<16) | ref_kind;
152 }
153
154 void method_type_index_at_put(int which, int ref_index) {
155 tag_at_put(which, JVM_CONSTANT_MethodType);
156 *int_at_addr(which) = ref_index;
157 }
158
149 // Temporary until actual use 159 // Temporary until actual use
150 void unresolved_string_at_put(int which, symbolOop s) { 160 void unresolved_string_at_put(int which, symbolOop s) {
151 *obj_at_addr(which) = NULL; 161 *obj_at_addr(which) = NULL;
152 release_tag_at_put(which, JVM_CONSTANT_UnresolvedString); 162 release_tag_at_put(which, JVM_CONSTANT_UnresolvedString);
153 oop_store_without_check(obj_at_addr(which), oop(s)); 163 oop_store_without_check(obj_at_addr(which), oop(s));
355 jint name_and_type_at(int which) { 365 jint name_and_type_at(int which) {
356 assert(tag_at(which).is_name_and_type(), "Corrupted constant pool"); 366 assert(tag_at(which).is_name_and_type(), "Corrupted constant pool");
357 return *int_at_addr(which); 367 return *int_at_addr(which);
358 } 368 }
359 369
370 int method_handle_ref_kind_at(int which) {
371 assert(tag_at(which).is_method_handle(), "Corrupted constant pool");
372 return extract_low_short_from_int(*int_at_addr(which)); // mask out unwanted ref_index bits
373 }
374 int method_handle_index_at(int which) {
375 assert(tag_at(which).is_method_handle(), "Corrupted constant pool");
376 return extract_high_short_from_int(*int_at_addr(which)); // shift out unwanted ref_kind bits
377 }
378 int method_type_index_at(int which) {
379 assert(tag_at(which).is_method_type(), "Corrupted constant pool");
380 return *int_at_addr(which);
381 }
382 // Derived queries:
383 symbolOop method_handle_name_ref_at(int which) {
384 int member = method_handle_index_at(which);
385 return impl_name_ref_at(member, true);
386 }
387 symbolOop method_handle_signature_ref_at(int which) {
388 int member = method_handle_index_at(which);
389 return impl_signature_ref_at(member, true);
390 }
391 int method_handle_klass_index_at(int which) {
392 int member = method_handle_index_at(which);
393 return impl_klass_ref_index_at(member, true);
394 }
395 symbolOop method_type_signature_at(int which) {
396 int sym = method_type_index_at(which);
397 return symbol_at(sym);
398 }
399
360 // The following methods (name/signature/klass_ref_at, klass_ref_at_noresolve, 400 // The following methods (name/signature/klass_ref_at, klass_ref_at_noresolve,
361 // name_and_type_ref_index_at) all expect to be passed indices obtained 401 // name_and_type_ref_index_at) all expect to be passed indices obtained
362 // directly from the bytecode, and extracted according to java byte order. 402 // directly from the bytecode, and extracted according to java byte order.
363 // If the indices are meant to refer to fields or methods, they are 403 // If the indices are meant to refer to fields or methods, they are
364 // actually potentially byte-swapped, rewritten constant pool cache indices. 404 // actually potentially byte-swapped, rewritten constant pool cache indices.
386 void resolve_string_constants(TRAPS) { 426 void resolve_string_constants(TRAPS) {
387 constantPoolHandle h_this(THREAD, this); 427 constantPoolHandle h_this(THREAD, this);
388 resolve_string_constants_impl(h_this, CHECK); 428 resolve_string_constants_impl(h_this, CHECK);
389 } 429 }
390 430
431 // Resolve late bound constants.
432 oop resolve_constant_at(int index, TRAPS) {
433 constantPoolHandle h_this(THREAD, this);
434 return resolve_constant_at_impl(h_this, index, -1, THREAD);
435 }
436
437 oop resolve_cached_constant_at(int cache_index, TRAPS) {
438 constantPoolHandle h_this(THREAD, this);
439 return resolve_constant_at_impl(h_this, -1, cache_index, THREAD);
440 }
441
391 // Klass name matches name at offset 442 // Klass name matches name at offset
392 bool klass_name_at_matches(instanceKlassHandle k, int which); 443 bool klass_name_at_matches(instanceKlassHandle k, int which);
393 444
394 // Sizing 445 // Sizing
395 int length() const { return _length; } 446 int length() const { return _length; }
418 static klassOop klass_ref_at_if_loaded_check(constantPoolHandle this_oop, int which, TRAPS); 469 static klassOop klass_ref_at_if_loaded_check(constantPoolHandle this_oop, int which, TRAPS);
419 470
420 // Routines currently used for annotations (only called by jvm.cpp) but which might be used in the 471 // Routines currently used for annotations (only called by jvm.cpp) but which might be used in the
421 // future by other Java code. These take constant pool indices rather than possibly-byte-swapped 472 // future by other Java code. These take constant pool indices rather than possibly-byte-swapped
422 // constant pool cache indices as do the peer methods above. 473 // constant pool cache indices as do the peer methods above.
474 symbolOop uncached_klass_ref_at_noresolve(int which);
423 symbolOop uncached_name_ref_at(int which) { return impl_name_ref_at(which, true); } 475 symbolOop uncached_name_ref_at(int which) { return impl_name_ref_at(which, true); }
424 symbolOop uncached_signature_ref_at(int which) { return impl_signature_ref_at(which, true); } 476 symbolOop uncached_signature_ref_at(int which) { return impl_signature_ref_at(which, true); }
425 int uncached_klass_ref_index_at(int which) { return impl_klass_ref_index_at(which, true); } 477 int uncached_klass_ref_index_at(int which) { return impl_klass_ref_index_at(which, true); }
426 int uncached_name_and_type_ref_index_at(int which) { return impl_name_and_type_ref_index_at(which, true); } 478 int uncached_name_and_type_ref_index_at(int which) { return impl_name_and_type_ref_index_at(which, true); }
427 479
434 // Debugging 486 // Debugging
435 const char* printable_name_at(int which) PRODUCT_RETURN0; 487 const char* printable_name_at(int which) PRODUCT_RETURN0;
436 488
437 #ifdef ASSERT 489 #ifdef ASSERT
438 enum { CPCACHE_INDEX_TAG = 0x10000 }; // helps keep CP cache indices distinct from CP indices 490 enum { CPCACHE_INDEX_TAG = 0x10000 }; // helps keep CP cache indices distinct from CP indices
491 #else
492 enum { CPCACHE_INDEX_TAG = 0 }; // in product mode, this zero value is a no-op
439 #endif //ASSERT 493 #endif //ASSERT
440 494
441 private: 495 private:
442 496
443 symbolOop impl_name_ref_at(int which, bool uncached); 497 symbolOop impl_name_ref_at(int which, bool uncached);
466 static klassOop klass_at_impl(constantPoolHandle this_oop, int which, TRAPS); 520 static klassOop klass_at_impl(constantPoolHandle this_oop, int which, TRAPS);
467 static oop string_at_impl(constantPoolHandle this_oop, int which, TRAPS); 521 static oop string_at_impl(constantPoolHandle this_oop, int which, TRAPS);
468 522
469 // Resolve string constants (to prevent allocation during compilation) 523 // Resolve string constants (to prevent allocation during compilation)
470 static void resolve_string_constants_impl(constantPoolHandle this_oop, TRAPS); 524 static void resolve_string_constants_impl(constantPoolHandle this_oop, TRAPS);
525
526 static oop resolve_constant_at_impl(constantPoolHandle this_oop, int index, int cache_index, TRAPS);
471 527
472 public: 528 public:
473 // Merging constantPoolOop support: 529 // Merging constantPoolOop support:
474 bool compare_entry_to(int index1, constantPoolHandle cp2, int index2, TRAPS); 530 bool compare_entry_to(int index1, constantPoolHandle cp2, int index2, TRAPS);
475 void copy_cp_to(int start_i, int end_i, constantPoolHandle to_cp, int to_i, 531 void copy_cp_to(int start_i, int end_i, constantPoolHandle to_cp, int to_i,