hotspot/src/share/vm/classfile/javaClasses.cpp
changeset 13391 30245956af37
parent 13293 c2b4f191c489
child 13392 1ef07ae0723d
equal deleted inserted replaced
13309:50c604cb0d5f 13391:30245956af37
   124   fieldDescriptor fd;
   124   fieldDescriptor fd;
   125   instanceKlass* ik = instanceKlass::cast(klass_oop);
   125   instanceKlass* ik = instanceKlass::cast(klass_oop);
   126   if (!find_field(ik, name_symbol, signature_symbol, &fd, allow_super)) {
   126   if (!find_field(ik, name_symbol, signature_symbol, &fd, allow_super)) {
   127     ResourceMark rm;
   127     ResourceMark rm;
   128     tty->print_cr("Invalid layout of %s at %s", ik->external_name(), name_symbol->as_C_string());
   128     tty->print_cr("Invalid layout of %s at %s", ik->external_name(), name_symbol->as_C_string());
       
   129 #ifndef PRODUCT
       
   130     klass_oop->print();
       
   131     tty->print_cr("all fields:");
       
   132     for (AllFieldStream fs(instanceKlass::cast(klass_oop)); !fs.done(); fs.next()) {
       
   133       tty->print_cr("  name: %s, sig: %s, flags: %08x", fs.name()->as_C_string(), fs.signature()->as_C_string(), fs.access_flags().as_int());
       
   134     }
       
   135 #endif //PRODUCT
   129     fatal("Invalid layout of preloaded class");
   136     fatal("Invalid layout of preloaded class");
   130   }
   137   }
   131   dest_offset = fd.offset();
   138   dest_offset = fd.offset();
   132 }
   139 }
   133 
   140 
  1453   RegisterMap map(thread, false);
  1460   RegisterMap map(thread, false);
  1454   int decode_offset = 0;
  1461   int decode_offset = 0;
  1455   nmethod* nm = NULL;
  1462   nmethod* nm = NULL;
  1456   bool skip_fillInStackTrace_check = false;
  1463   bool skip_fillInStackTrace_check = false;
  1457   bool skip_throwableInit_check = false;
  1464   bool skip_throwableInit_check = false;
       
  1465   bool skip_hidden = false;
  1458 
  1466 
  1459   for (frame fr = thread->last_frame(); max_depth != total_count;) {
  1467   for (frame fr = thread->last_frame(); max_depth != total_count;) {
  1460     methodOop method = NULL;
  1468     methodOop method = NULL;
  1461     int bci = 0;
  1469     int bci = 0;
  1462 
  1470 
  1532       } else {
  1540       } else {
  1533         // there are none or we've seen them all - either way stop checking
  1541         // there are none or we've seen them all - either way stop checking
  1534         skip_throwableInit_check = true;
  1542         skip_throwableInit_check = true;
  1535       }
  1543       }
  1536     }
  1544     }
       
  1545     if (method->is_hidden()) {
       
  1546       if (skip_hidden)  continue;
       
  1547     } else {
       
  1548       // start skipping hidden frames after first non-hidden frame
       
  1549       skip_hidden = !ShowHiddenFrames;
       
  1550     }
  1537     bt.push(method, bci, CHECK);
  1551     bt.push(method, bci, CHECK);
  1538     total_count++;
  1552     total_count++;
  1539   }
  1553   }
  1540 
  1554 
  1541   // Put completed stack trace into throwable object
  1555   // Put completed stack trace into throwable object
  1722   // Fill in method name
  1736   // Fill in method name
  1723   oop methodname = StringTable::intern(method->name(), CHECK_0);
  1737   oop methodname = StringTable::intern(method->name(), CHECK_0);
  1724   java_lang_StackTraceElement::set_methodName(element(), methodname);
  1738   java_lang_StackTraceElement::set_methodName(element(), methodname);
  1725   // Fill in source file name
  1739   // Fill in source file name
  1726   Symbol* source = instanceKlass::cast(method->method_holder())->source_file_name();
  1740   Symbol* source = instanceKlass::cast(method->method_holder())->source_file_name();
       
  1741   if (ShowHiddenFrames && source == NULL)
       
  1742     source = vmSymbols::unknown_class_name();
  1727   oop filename = StringTable::intern(source, CHECK_0);
  1743   oop filename = StringTable::intern(source, CHECK_0);
  1728   java_lang_StackTraceElement::set_fileName(element(), filename);
  1744   java_lang_StackTraceElement::set_fileName(element(), filename);
  1729   // File in source line number
  1745   // File in source line number
  1730   int line_number;
  1746   int line_number;
  1731   if (method->is_native()) {
  1747   if (method->is_native()) {
  1734     // "no LineNumberTable".
  1750     // "no LineNumberTable".
  1735     line_number = -2;
  1751     line_number = -2;
  1736   } else {
  1752   } else {
  1737     // Returns -1 if no LineNumberTable, and otherwise actual line number
  1753     // Returns -1 if no LineNumberTable, and otherwise actual line number
  1738     line_number = method->line_number_from_bci(bci);
  1754     line_number = method->line_number_from_bci(bci);
       
  1755     if (line_number == -1 && ShowHiddenFrames) {
       
  1756       line_number = bci + 1000000;
       
  1757     }
  1739   }
  1758   }
  1740   java_lang_StackTraceElement::set_lineNumber(element(), line_number);
  1759   java_lang_StackTraceElement::set_lineNumber(element(), line_number);
  1741 
  1760 
  1742   return element();
  1761   return element();
  1743 }
  1762 }
  2375 
  2394 
  2376 
  2395 
  2377 // Support for java_lang_invoke_MethodHandle
  2396 // Support for java_lang_invoke_MethodHandle
  2378 
  2397 
  2379 int java_lang_invoke_MethodHandle::_type_offset;
  2398 int java_lang_invoke_MethodHandle::_type_offset;
  2380 int java_lang_invoke_MethodHandle::_vmtarget_offset;
  2399 int java_lang_invoke_MethodHandle::_form_offset;
  2381 int java_lang_invoke_MethodHandle::_vmentry_offset;
       
  2382 
  2400 
  2383 int java_lang_invoke_MemberName::_clazz_offset;
  2401 int java_lang_invoke_MemberName::_clazz_offset;
  2384 int java_lang_invoke_MemberName::_name_offset;
  2402 int java_lang_invoke_MemberName::_name_offset;
  2385 int java_lang_invoke_MemberName::_type_offset;
  2403 int java_lang_invoke_MemberName::_type_offset;
  2386 int java_lang_invoke_MemberName::_flags_offset;
  2404 int java_lang_invoke_MemberName::_flags_offset;
  2387 int java_lang_invoke_MemberName::_vmtarget_offset;
  2405 int java_lang_invoke_MemberName::_vmtarget_offset;
  2388 int java_lang_invoke_MemberName::_vmindex_offset;
  2406 int java_lang_invoke_MemberName::_vmindex_offset;
  2389 
  2407 
  2390 int java_lang_invoke_DirectMethodHandle::_vmindex_offset;
  2408 int java_lang_invoke_LambdaForm::_vmentry_offset;
  2391 
       
  2392 int java_lang_invoke_BoundMethodHandle::_argument_offset;
       
  2393 int java_lang_invoke_BoundMethodHandle::_vmargslot_offset;
       
  2394 
       
  2395 int java_lang_invoke_AdapterMethodHandle::_conversion_offset;
       
  2396 
       
  2397 int java_lang_invoke_CountingMethodHandle::_vmcount_offset;
       
  2398 
  2409 
  2399 void java_lang_invoke_MethodHandle::compute_offsets() {
  2410 void java_lang_invoke_MethodHandle::compute_offsets() {
  2400   klassOop klass_oop = SystemDictionary::MethodHandle_klass();
  2411   klassOop klass_oop = SystemDictionary::MethodHandle_klass();
  2401   if (klass_oop != NULL && EnableInvokeDynamic) {
  2412   if (klass_oop != NULL && EnableInvokeDynamic) {
  2402     bool allow_super = false;
  2413     compute_offset(_type_offset, klass_oop, vmSymbols::type_name(), vmSymbols::java_lang_invoke_MethodType_signature());
  2403     compute_offset(_type_offset,      klass_oop, vmSymbols::type_name(),      vmSymbols::java_lang_invoke_MethodType_signature(), allow_super);
  2414     compute_optional_offset(_form_offset, klass_oop, vmSymbols::form_name(), vmSymbols::java_lang_invoke_LambdaForm_signature());
  2404     METHODHANDLE_INJECTED_FIELDS(INJECTED_FIELD_COMPUTE_OFFSET);
  2415     if (_form_offset == 0) {
       
  2416       EnableInvokeDynamic = false;
       
  2417     }
  2405   }
  2418   }
  2406 }
  2419 }
  2407 
  2420 
  2408 void java_lang_invoke_MemberName::compute_offsets() {
  2421 void java_lang_invoke_MemberName::compute_offsets() {
  2409   klassOop klass_oop = SystemDictionary::MemberName_klass();
  2422   klassOop klass_oop = SystemDictionary::MemberName_klass();
  2410   if (klass_oop != NULL && EnableInvokeDynamic) {
  2423   if (klass_oop != NULL && EnableInvokeDynamic) {
  2411     compute_offset(_clazz_offset,     klass_oop, vmSymbols::clazz_name(),     vmSymbols::class_signature());
  2424     compute_offset(_clazz_offset,     klass_oop, vmSymbols::clazz_name(),     vmSymbols::class_signature());
  2412     compute_offset(_name_offset,      klass_oop, vmSymbols::name_name(),      vmSymbols::string_signature());
  2425     compute_offset(_name_offset,      klass_oop, vmSymbols::name_name(),      vmSymbols::string_signature());
  2413     compute_offset(_type_offset,      klass_oop, vmSymbols::type_name(),      vmSymbols::object_signature());
  2426     compute_offset(_type_offset,      klass_oop, vmSymbols::type_name(),      vmSymbols::object_signature());
  2414     compute_offset(_flags_offset,     klass_oop, vmSymbols::flags_name(),     vmSymbols::int_signature());
  2427     compute_offset(_flags_offset,     klass_oop, vmSymbols::flags_name(),     vmSymbols::int_signature());
  2415     compute_offset(_vmindex_offset,   klass_oop, vmSymbols::vmindex_name(),   vmSymbols::int_signature());
       
  2416     MEMBERNAME_INJECTED_FIELDS(INJECTED_FIELD_COMPUTE_OFFSET);
  2428     MEMBERNAME_INJECTED_FIELDS(INJECTED_FIELD_COMPUTE_OFFSET);
  2417   }
  2429   }
  2418 }
  2430 }
  2419 
  2431 
  2420 void java_lang_invoke_DirectMethodHandle::compute_offsets() {
  2432 void java_lang_invoke_LambdaForm::compute_offsets() {
  2421   klassOop k = SystemDictionary::DirectMethodHandle_klass();
  2433   klassOop klass_oop = SystemDictionary::LambdaForm_klass();
  2422   if (k != NULL && EnableInvokeDynamic) {
  2434   if (klass_oop != NULL && EnableInvokeDynamic) {
  2423     DIRECTMETHODHANDLE_INJECTED_FIELDS(INJECTED_FIELD_COMPUTE_OFFSET);
  2435     compute_offset(_vmentry_offset, klass_oop, vmSymbols::vmentry_name(), vmSymbols::java_lang_invoke_MemberName_signature());
  2424   }
  2436   }
  2425 }
       
  2426 
       
  2427 void java_lang_invoke_BoundMethodHandle::compute_offsets() {
       
  2428   klassOop k = SystemDictionary::BoundMethodHandle_klass();
       
  2429   if (k != NULL && EnableInvokeDynamic) {
       
  2430     compute_offset(_vmargslot_offset, k, vmSymbols::vmargslot_name(), vmSymbols::int_signature(),    true);
       
  2431     compute_offset(_argument_offset,  k, vmSymbols::argument_name(),  vmSymbols::object_signature(), true);
       
  2432   }
       
  2433 }
       
  2434 
       
  2435 void java_lang_invoke_AdapterMethodHandle::compute_offsets() {
       
  2436   klassOop k = SystemDictionary::AdapterMethodHandle_klass();
       
  2437   if (k != NULL && EnableInvokeDynamic) {
       
  2438     compute_offset(_conversion_offset, k, vmSymbols::conversion_name(), vmSymbols::int_signature(), true);
       
  2439   }
       
  2440 }
       
  2441 
       
  2442 void java_lang_invoke_CountingMethodHandle::compute_offsets() {
       
  2443   klassOop k = SystemDictionary::CountingMethodHandle_klass();
       
  2444   if (k != NULL && EnableInvokeDynamic) {
       
  2445     compute_offset(_vmcount_offset, k, vmSymbols::vmcount_name(), vmSymbols::int_signature(), true);
       
  2446   }
       
  2447 }
       
  2448 
       
  2449 int java_lang_invoke_CountingMethodHandle::vmcount(oop mh) {
       
  2450   assert(is_instance(mh), "CMH only");
       
  2451   return mh->int_field(_vmcount_offset);
       
  2452 }
       
  2453 
       
  2454 void java_lang_invoke_CountingMethodHandle::set_vmcount(oop mh, int count) {
       
  2455   assert(is_instance(mh), "CMH only");
       
  2456   mh->int_field_put(_vmcount_offset, count);
       
  2457 }
  2437 }
  2458 
  2438 
  2459 oop java_lang_invoke_MethodHandle::type(oop mh) {
  2439 oop java_lang_invoke_MethodHandle::type(oop mh) {
  2460   return mh->obj_field(_type_offset);
  2440   return mh->obj_field(_type_offset);
  2461 }
  2441 }
  2462 
  2442 
  2463 void java_lang_invoke_MethodHandle::set_type(oop mh, oop mtype) {
  2443 void java_lang_invoke_MethodHandle::set_type(oop mh, oop mtype) {
  2464   mh->obj_field_put(_type_offset, mtype);
  2444   mh->obj_field_put(_type_offset, mtype);
  2465 }
  2445 }
  2466 
  2446 
  2467 // fetch type.form.vmslots, which is the number of JVM stack slots
  2447 oop java_lang_invoke_MethodHandle::form(oop mh) {
  2468 // required to carry the arguments of this MH
  2448   assert(_form_offset != 0, "");
  2469 int java_lang_invoke_MethodHandle::vmslots(oop mh) {
  2449   return mh->obj_field(_form_offset);
  2470   oop mtype = type(mh);
  2450 }
  2471   if (mtype == NULL)  return 0;  // Java code would get NPE
  2451 
  2472   oop form = java_lang_invoke_MethodType::form(mtype);
  2452 void java_lang_invoke_MethodHandle::set_form(oop mh, oop lform) {
  2473   if (form == NULL)   return 0;  // Java code would get NPE
  2453   assert(_form_offset != 0, "");
  2474   return java_lang_invoke_MethodTypeForm::vmslots(form);
  2454   mh->obj_field_put(_form_offset, lform);
  2475 }
       
  2476 
       
  2477 // fetch the low-level entry point for this mh
       
  2478 MethodHandleEntry* java_lang_invoke_MethodHandle::vmentry(oop mh) {
       
  2479   return (MethodHandleEntry*) mh->address_field(_vmentry_offset);
       
  2480 }
       
  2481 
       
  2482 void java_lang_invoke_MethodHandle::set_vmentry(oop mh, MethodHandleEntry* me) {
       
  2483   assert(_vmentry_offset != 0, "must be present");
       
  2484 
       
  2485   // This is always the final step that initializes a valid method handle:
       
  2486   mh->release_address_field_put(_vmentry_offset, (address) me);
       
  2487 
       
  2488   // There should be enough memory barriers on exit from native methods
       
  2489   // to ensure that the MH is fully initialized to all threads before
       
  2490   // Java code can publish it in global data structures.
       
  2491   // But just in case, we use release_address_field_put.
       
  2492 }
  2455 }
  2493 
  2456 
  2494 /// MemberName accessors
  2457 /// MemberName accessors
  2495 
  2458 
  2496 oop java_lang_invoke_MemberName::clazz(oop mname) {
  2459 oop java_lang_invoke_MemberName::clazz(oop mname) {
  2538   return mname->obj_field(_vmtarget_offset);
  2501   return mname->obj_field(_vmtarget_offset);
  2539 }
  2502 }
  2540 
  2503 
  2541 void java_lang_invoke_MemberName::set_vmtarget(oop mname, oop ref) {
  2504 void java_lang_invoke_MemberName::set_vmtarget(oop mname, oop ref) {
  2542   assert(is_instance(mname), "wrong type");
  2505   assert(is_instance(mname), "wrong type");
       
  2506 #ifdef ASSERT
       
  2507   // check the type of the vmtarget
       
  2508   if (ref != NULL) {
       
  2509     switch (flags(mname) & (MN_IS_METHOD |
       
  2510                             MN_IS_CONSTRUCTOR |
       
  2511                             MN_IS_FIELD)) {
       
  2512     case MN_IS_METHOD:
       
  2513     case MN_IS_CONSTRUCTOR:
       
  2514       assert(ref->is_method(), "should be a method");
       
  2515       break;
       
  2516     case MN_IS_FIELD:
       
  2517       assert(ref->is_klass(), "should be a class");
       
  2518       break;
       
  2519     default:
       
  2520       ShouldNotReachHere();
       
  2521     }
       
  2522   }
       
  2523 #endif //ASSERT
  2543   mname->obj_field_put(_vmtarget_offset, ref);
  2524   mname->obj_field_put(_vmtarget_offset, ref);
  2544 }
  2525 }
  2545 
  2526 
  2546 int java_lang_invoke_MemberName::vmindex(oop mname) {
  2527 intptr_t java_lang_invoke_MemberName::vmindex(oop mname) {
  2547   assert(is_instance(mname), "wrong type");
  2528   assert(is_instance(mname), "wrong type");
  2548   return mname->int_field(_vmindex_offset);
  2529   return (intptr_t) mname->address_field(_vmindex_offset);
  2549 }
  2530 }
  2550 
  2531 
  2551 void java_lang_invoke_MemberName::set_vmindex(oop mname, int index) {
  2532 void java_lang_invoke_MemberName::set_vmindex(oop mname, intptr_t index) {
  2552   assert(is_instance(mname), "wrong type");
  2533   assert(is_instance(mname), "wrong type");
  2553   mname->int_field_put(_vmindex_offset, index);
  2534   mname->address_field_put(_vmindex_offset, (address) index);
  2554 }
  2535 }
  2555 
  2536 
  2556 oop java_lang_invoke_MethodHandle::vmtarget(oop mh) {
  2537 oop java_lang_invoke_LambdaForm::vmentry(oop lform) {
  2557   assert(is_instance(mh), "MH only");
  2538   assert(is_instance(lform), "wrong type");
  2558   return mh->obj_field(_vmtarget_offset);
  2539   return lform->obj_field(_vmentry_offset);
  2559 }
       
  2560 
       
  2561 void java_lang_invoke_MethodHandle::set_vmtarget(oop mh, oop ref) {
       
  2562   assert(is_instance(mh), "MH only");
       
  2563   mh->obj_field_put(_vmtarget_offset, ref);
       
  2564 }
       
  2565 
       
  2566 int java_lang_invoke_DirectMethodHandle::vmindex(oop mh) {
       
  2567   assert(is_instance(mh), "DMH only");
       
  2568   return mh->int_field(_vmindex_offset);
       
  2569 }
       
  2570 
       
  2571 void java_lang_invoke_DirectMethodHandle::set_vmindex(oop mh, int index) {
       
  2572   assert(is_instance(mh), "DMH only");
       
  2573   mh->int_field_put(_vmindex_offset, index);
       
  2574 }
       
  2575 
       
  2576 int java_lang_invoke_BoundMethodHandle::vmargslot(oop mh) {
       
  2577   assert(is_instance(mh), "BMH only");
       
  2578   return mh->int_field(_vmargslot_offset);
       
  2579 }
       
  2580 
       
  2581 oop java_lang_invoke_BoundMethodHandle::argument(oop mh) {
       
  2582   assert(is_instance(mh), "BMH only");
       
  2583   return mh->obj_field(_argument_offset);
       
  2584 }
       
  2585 
       
  2586 int java_lang_invoke_AdapterMethodHandle::conversion(oop mh) {
       
  2587   assert(is_instance(mh), "AMH only");
       
  2588   return mh->int_field(_conversion_offset);
       
  2589 }
       
  2590 
       
  2591 void java_lang_invoke_AdapterMethodHandle::set_conversion(oop mh, int conv) {
       
  2592   assert(is_instance(mh), "AMH only");
       
  2593   mh->int_field_put(_conversion_offset, conv);
       
  2594 }
  2540 }
  2595 
  2541 
  2596 
  2542 
  2597 // Support for java_lang_invoke_MethodType
  2543 // Support for java_lang_invoke_MethodType
  2598 
  2544 
  2599 int java_lang_invoke_MethodType::_rtype_offset;
  2545 int java_lang_invoke_MethodType::_rtype_offset;
  2600 int java_lang_invoke_MethodType::_ptypes_offset;
  2546 int java_lang_invoke_MethodType::_ptypes_offset;
  2601 int java_lang_invoke_MethodType::_form_offset;
       
  2602 
  2547 
  2603 void java_lang_invoke_MethodType::compute_offsets() {
  2548 void java_lang_invoke_MethodType::compute_offsets() {
  2604   klassOop k = SystemDictionary::MethodType_klass();
  2549   klassOop k = SystemDictionary::MethodType_klass();
  2605   if (k != NULL) {
  2550   if (k != NULL) {
  2606     compute_offset(_rtype_offset,  k, vmSymbols::rtype_name(),  vmSymbols::class_signature());
  2551     compute_offset(_rtype_offset,  k, vmSymbols::rtype_name(),  vmSymbols::class_signature());
  2607     compute_offset(_ptypes_offset, k, vmSymbols::ptypes_name(), vmSymbols::class_array_signature());
  2552     compute_offset(_ptypes_offset, k, vmSymbols::ptypes_name(), vmSymbols::class_array_signature());
  2608     compute_offset(_form_offset,   k, vmSymbols::form_name(),   vmSymbols::java_lang_invoke_MethodTypeForm_signature());
       
  2609   }
  2553   }
  2610 }
  2554 }
  2611 
  2555 
  2612 void java_lang_invoke_MethodType::print_signature(oop mt, outputStream* st) {
  2556 void java_lang_invoke_MethodType::print_signature(oop mt, outputStream* st) {
  2613   st->print("(");
  2557   st->print("(");
  2633   }
  2577   }
  2634   return name;
  2578   return name;
  2635 }
  2579 }
  2636 
  2580 
  2637 bool java_lang_invoke_MethodType::equals(oop mt1, oop mt2) {
  2581 bool java_lang_invoke_MethodType::equals(oop mt1, oop mt2) {
       
  2582   if (mt1 == mt2)
       
  2583     return true;
  2638   if (rtype(mt1) != rtype(mt2))
  2584   if (rtype(mt1) != rtype(mt2))
  2639     return false;
  2585     return false;
  2640   if (ptype_count(mt1) != ptype_count(mt2))
  2586   if (ptype_count(mt1) != ptype_count(mt2))
  2641     return false;
  2587     return false;
  2642   for (int i = ptype_count(mt1) - 1; i >= 0; i--) {
  2588   for (int i = ptype_count(mt1) - 1; i >= 0; i--) {
  2654 objArrayOop java_lang_invoke_MethodType::ptypes(oop mt) {
  2600 objArrayOop java_lang_invoke_MethodType::ptypes(oop mt) {
  2655   assert(is_instance(mt), "must be a MethodType");
  2601   assert(is_instance(mt), "must be a MethodType");
  2656   return (objArrayOop) mt->obj_field(_ptypes_offset);
  2602   return (objArrayOop) mt->obj_field(_ptypes_offset);
  2657 }
  2603 }
  2658 
  2604 
  2659 oop java_lang_invoke_MethodType::form(oop mt) {
       
  2660   assert(is_instance(mt), "must be a MethodType");
       
  2661   return mt->obj_field(_form_offset);
       
  2662 }
       
  2663 
       
  2664 oop java_lang_invoke_MethodType::ptype(oop mt, int idx) {
  2605 oop java_lang_invoke_MethodType::ptype(oop mt, int idx) {
  2665   return ptypes(mt)->obj_at(idx);
  2606   return ptypes(mt)->obj_at(idx);
  2666 }
  2607 }
  2667 
  2608 
  2668 int java_lang_invoke_MethodType::ptype_count(oop mt) {
  2609 int java_lang_invoke_MethodType::ptype_count(oop mt) {
  2669   return ptypes(mt)->length();
  2610   return ptypes(mt)->length();
  2670 }
  2611 }
  2671 
  2612 
  2672 
  2613 int java_lang_invoke_MethodType::ptype_slot_count(oop mt) {
  2673 
  2614   objArrayOop pts = ptypes(mt);
  2674 // Support for java_lang_invoke_MethodTypeForm
  2615   int count = pts->length();
  2675 
  2616   int slots = 0;
  2676 int java_lang_invoke_MethodTypeForm::_vmslots_offset;
  2617   for (int i = 0; i < count; i++) {
  2677 int java_lang_invoke_MethodTypeForm::_vmlayout_offset;
  2618     BasicType bt = java_lang_Class::as_BasicType(pts->obj_at(i));
  2678 int java_lang_invoke_MethodTypeForm::_erasedType_offset;
  2619     slots += type2size[bt];
  2679 int java_lang_invoke_MethodTypeForm::_genericInvoker_offset;
  2620   }
  2680 
  2621   return slots;
  2681 void java_lang_invoke_MethodTypeForm::compute_offsets() {
  2622 }
  2682   klassOop k = SystemDictionary::MethodTypeForm_klass();
  2623 
  2683   if (k != NULL) {
  2624 int java_lang_invoke_MethodType::rtype_slot_count(oop mt) {
  2684     compute_optional_offset(_vmslots_offset,    k, vmSymbols::vmslots_name(),    vmSymbols::int_signature(), true);
  2625   BasicType bt = java_lang_Class::as_BasicType(rtype(mt));
  2685     compute_optional_offset(_vmlayout_offset,   k, vmSymbols::vmlayout_name(),   vmSymbols::object_signature());
  2626   return type2size[bt];
  2686     compute_optional_offset(_erasedType_offset, k, vmSymbols::erasedType_name(), vmSymbols::java_lang_invoke_MethodType_signature(), true);
       
  2687     compute_optional_offset(_genericInvoker_offset, k, vmSymbols::genericInvoker_name(), vmSymbols::java_lang_invoke_MethodHandle_signature(), true);
       
  2688     if (_genericInvoker_offset == 0)  _genericInvoker_offset = -1;  // set to explicit "empty" value
       
  2689     METHODTYPEFORM_INJECTED_FIELDS(INJECTED_FIELD_COMPUTE_OFFSET);
       
  2690   }
       
  2691 }
       
  2692 
       
  2693 int java_lang_invoke_MethodTypeForm::vmslots(oop mtform) {
       
  2694   assert(mtform->klass() == SystemDictionary::MethodTypeForm_klass(), "MTForm only");
       
  2695   assert(_vmslots_offset > 0, "");
       
  2696   return mtform->int_field(_vmslots_offset);
       
  2697 }
       
  2698 
       
  2699 oop java_lang_invoke_MethodTypeForm::vmlayout(oop mtform) {
       
  2700   assert(mtform->klass() == SystemDictionary::MethodTypeForm_klass(), "MTForm only");
       
  2701   assert(_vmlayout_offset > 0, "");
       
  2702   return mtform->obj_field(_vmlayout_offset);
       
  2703 }
       
  2704 
       
  2705 oop java_lang_invoke_MethodTypeForm::init_vmlayout(oop mtform, oop cookie) {
       
  2706   assert(mtform->klass() == SystemDictionary::MethodTypeForm_klass(), "MTForm only");
       
  2707   oop previous = vmlayout(mtform);
       
  2708   if (previous != NULL) {
       
  2709     return previous;  // someone else beat us to it
       
  2710   }
       
  2711   HeapWord* cookie_addr = (HeapWord*) mtform->obj_field_addr<oop>(_vmlayout_offset);
       
  2712   OrderAccess::storestore();  // make sure our copy is fully committed
       
  2713   previous = oopDesc::atomic_compare_exchange_oop(cookie, cookie_addr, previous);
       
  2714   if (previous != NULL) {
       
  2715     return previous;  // someone else beat us to it
       
  2716   }
       
  2717   return cookie;
       
  2718 }
       
  2719 
       
  2720 oop java_lang_invoke_MethodTypeForm::erasedType(oop mtform) {
       
  2721   assert(mtform->klass() == SystemDictionary::MethodTypeForm_klass(), "MTForm only");
       
  2722   return mtform->obj_field(_erasedType_offset);
       
  2723 }
       
  2724 
       
  2725 oop java_lang_invoke_MethodTypeForm::genericInvoker(oop mtform) {
       
  2726   assert(mtform->klass() == SystemDictionary::MethodTypeForm_klass(), "MTForm only");
       
  2727   return mtform->obj_field(_genericInvoker_offset);
       
  2728 }
  2627 }
  2729 
  2628 
  2730 
  2629 
  2731 // Support for java_lang_invoke_CallSite
  2630 // Support for java_lang_invoke_CallSite
  2732 
  2631 
  2796   compute_optional_offset(parallelCapable_offset,
  2695   compute_optional_offset(parallelCapable_offset,
  2797     k1, vmSymbols::parallelCapable_name(), vmSymbols::concurrenthashmap_signature());
  2696     k1, vmSymbols::parallelCapable_name(), vmSymbols::concurrenthashmap_signature());
  2798 }
  2697 }
  2799 
  2698 
  2800 oop java_lang_ClassLoader::parent(oop loader) {
  2699 oop java_lang_ClassLoader::parent(oop loader) {
  2801   assert(loader->is_oop(), "loader must be oop");
  2700   assert(is_instance(loader), "loader must be oop");
  2802   return loader->obj_field(parent_offset);
  2701   return loader->obj_field(parent_offset);
       
  2702 }
       
  2703 
       
  2704 bool java_lang_ClassLoader::isAncestor(oop loader, oop cl) {
       
  2705   assert(is_instance(loader), "loader must be oop");
       
  2706   assert(cl == NULL || is_instance(cl), "cl argument must be oop");
       
  2707   oop acl = loader;
       
  2708   debug_only(jint loop_count = 0);
       
  2709   // This loop taken verbatim from ClassLoader.java:
       
  2710   do {
       
  2711     acl = parent(acl);
       
  2712     if (cl == acl) {
       
  2713       return true;
       
  2714     }
       
  2715     assert(++loop_count > 0, "loop_count overflow");
       
  2716   } while (acl != NULL);
       
  2717   return false;
  2803 }
  2718 }
  2804 
  2719 
  2805 
  2720 
  2806 // For class loader classes, parallelCapable defined
  2721 // For class loader classes, parallelCapable defined
  2807 // based on non-null field
  2722 // based on non-null field
  3059   java_lang_Thread::compute_offsets();
  2974   java_lang_Thread::compute_offsets();
  3060   java_lang_ThreadGroup::compute_offsets();
  2975   java_lang_ThreadGroup::compute_offsets();
  3061   if (EnableInvokeDynamic) {
  2976   if (EnableInvokeDynamic) {
  3062     java_lang_invoke_MethodHandle::compute_offsets();
  2977     java_lang_invoke_MethodHandle::compute_offsets();
  3063     java_lang_invoke_MemberName::compute_offsets();
  2978     java_lang_invoke_MemberName::compute_offsets();
  3064     java_lang_invoke_DirectMethodHandle::compute_offsets();
  2979     java_lang_invoke_LambdaForm::compute_offsets();
  3065     java_lang_invoke_BoundMethodHandle::compute_offsets();
       
  3066     java_lang_invoke_AdapterMethodHandle::compute_offsets();
       
  3067     java_lang_invoke_MethodType::compute_offsets();
  2980     java_lang_invoke_MethodType::compute_offsets();
  3068     java_lang_invoke_MethodTypeForm::compute_offsets();
       
  3069     java_lang_invoke_CallSite::compute_offsets();
  2981     java_lang_invoke_CallSite::compute_offsets();
  3070     java_lang_invoke_CountingMethodHandle::compute_offsets();
       
  3071   }
  2982   }
  3072   java_security_AccessControlContext::compute_offsets();
  2983   java_security_AccessControlContext::compute_offsets();
  3073   // Initialize reflection classes. The layouts of these classes
  2984   // Initialize reflection classes. The layouts of these classes
  3074   // changed with the new reflection implementation in JDK 1.4, and
  2985   // changed with the new reflection implementation in JDK 1.4, and
  3075   // since the Universe doesn't know what JDK version it is until this
  2986   // since the Universe doesn't know what JDK version it is until this
  3293     if (fs.name() == name() && fs.signature() == signature()) {
  3204     if (fs.name() == name() && fs.signature() == signature()) {
  3294       return fs.offset();
  3205       return fs.offset();
  3295     }
  3206     }
  3296   }
  3207   }
  3297   ResourceMark rm;
  3208   ResourceMark rm;
  3298   tty->print_cr("Invalid layout of %s at %s", instanceKlass::cast(klass_oop)->external_name(), name()->as_C_string());
  3209   tty->print_cr("Invalid layout of %s at %s/%s%s", instanceKlass::cast(klass_oop)->external_name(), name()->as_C_string(), signature()->as_C_string(), may_be_java ? " (may_be_java)" : "");
       
  3210 #ifndef PRODUCT
       
  3211   klass_oop->print();
       
  3212   tty->print_cr("all fields:");
       
  3213   for (AllFieldStream fs(instanceKlass::cast(klass_oop)); !fs.done(); fs.next()) {
       
  3214     tty->print_cr("  name: %s, sig: %s, flags: %08x", fs.name()->as_C_string(), fs.signature()->as_C_string(), fs.access_flags().as_int());
       
  3215   }
       
  3216 #endif //PRODUCT
  3299   fatal("Invalid layout of preloaded class");
  3217   fatal("Invalid layout of preloaded class");
  3300   return -1;
  3218   return -1;
  3301 }
  3219 }
  3302 
  3220 
  3303 void javaClasses_init() {
  3221 void javaClasses_init() {