Merge

Wed, 09 Oct 2013 22:01:59 -0400

author
coleenp
date
Wed, 09 Oct 2013 22:01:59 -0400
changeset 5885
e831448418ac
parent 5884
b4a4fdc1f464
parent 5853
d25557d03ec0
child 5886
cd7ea1d79dac
child 5887
539144972c1e

Merge

     1.1 --- a/agent/src/share/classes/sun/jvm/hotspot/memory/SymbolTable.java	Wed Oct 09 21:45:28 2013 -0400
     1.2 +++ b/agent/src/share/classes/sun/jvm/hotspot/memory/SymbolTable.java	Wed Oct 09 22:01:59 2013 -0400
     1.3 @@ -44,12 +44,10 @@
     1.4    private static synchronized void initialize(TypeDataBase db) {
     1.5      Type type = db.lookupType("SymbolTable");
     1.6      theTableField  = type.getAddressField("_the_table");
     1.7 -    symbolTableSize = db.lookupIntConstant("SymbolTable::symbol_table_size").intValue();
     1.8    }
     1.9  
    1.10    // Fields
    1.11    private static AddressField theTableField;
    1.12 -  private static int symbolTableSize;
    1.13  
    1.14    // Accessors
    1.15    public static SymbolTable getTheTable() {
    1.16 @@ -57,10 +55,6 @@
    1.17      return (SymbolTable) VMObjectFactory.newObject(SymbolTable.class, tmp);
    1.18    }
    1.19  
    1.20 -  public static int getSymbolTableSize() {
    1.21 -    return symbolTableSize;
    1.22 -  }
    1.23 -
    1.24    public SymbolTable(Address addr) {
    1.25      super(addr);
    1.26    }
     2.1 --- a/src/share/vm/classfile/classFileParser.cpp	Wed Oct 09 21:45:28 2013 -0400
     2.2 +++ b/src/share/vm/classfile/classFileParser.cpp	Wed Oct 09 22:01:59 2013 -0400
     2.3 @@ -4080,8 +4080,7 @@
     2.4  
     2.5      // Generate any default methods - default methods are interface methods
     2.6      // that have a default implementation.  This is new with Lambda project.
     2.7 -    if (has_default_methods && !access_flags.is_interface() &&
     2.8 -        local_interfaces->length() > 0) {
     2.9 +    if (has_default_methods && !access_flags.is_interface() ) {
    2.10        DefaultMethods::generate_default_methods(
    2.11            this_klass(), &all_mirandas, CHECK_(nullHandle));
    2.12      }
     3.1 --- a/src/share/vm/classfile/defaultMethods.cpp	Wed Oct 09 21:45:28 2013 -0400
     3.2 +++ b/src/share/vm/classfile/defaultMethods.cpp	Wed Oct 09 22:01:59 2013 -0400
     3.3 @@ -345,7 +345,6 @@
     3.4    }
     3.5  
     3.6    Symbol* generate_no_defaults_message(TRAPS) const;
     3.7 -  Symbol* generate_abstract_method_message(Method* method, TRAPS) const;
     3.8    Symbol* generate_conflicts_message(GrowableArray<Method*>* methods, TRAPS) const;
     3.9  
    3.10   public:
    3.11 @@ -404,20 +403,19 @@
    3.12        _exception_message = generate_no_defaults_message(CHECK);
    3.13        _exception_name = vmSymbols::java_lang_AbstractMethodError();
    3.14      } else if (qualified_methods.length() == 1) {
    3.15 +      // leave abstract methods alone, they will be found via normal search path
    3.16        Method* method = qualified_methods.at(0);
    3.17 -      if (method->is_abstract()) {
    3.18 -        _exception_message = generate_abstract_method_message(method, CHECK);
    3.19 -        _exception_name = vmSymbols::java_lang_AbstractMethodError();
    3.20 -      } else {
    3.21 +      if (!method->is_abstract()) {
    3.22          _selected_target = qualified_methods.at(0);
    3.23        }
    3.24      } else {
    3.25        _exception_message = generate_conflicts_message(&qualified_methods,CHECK);
    3.26        _exception_name = vmSymbols::java_lang_IncompatibleClassChangeError();
    3.27 +      if (TraceDefaultMethods) {
    3.28 +        _exception_message->print_value_on(tty);
    3.29 +        tty->print_cr("");
    3.30 +      }
    3.31      }
    3.32 -
    3.33 -    assert((has_target() ^ throws_exception()) == 1,
    3.34 -           "One and only one must be true");
    3.35    }
    3.36  
    3.37    bool contains_signature(Symbol* query) {
    3.38 @@ -475,20 +473,6 @@
    3.39    return SymbolTable::new_symbol("No qualifying defaults found", CHECK_NULL);
    3.40  }
    3.41  
    3.42 -Symbol* MethodFamily::generate_abstract_method_message(Method* method, TRAPS) const {
    3.43 -  Symbol* klass = method->klass_name();
    3.44 -  Symbol* name = method->name();
    3.45 -  Symbol* sig = method->signature();
    3.46 -  stringStream ss;
    3.47 -  ss.print("Method ");
    3.48 -  ss.write((const char*)klass->bytes(), klass->utf8_length());
    3.49 -  ss.print(".");
    3.50 -  ss.write((const char*)name->bytes(), name->utf8_length());
    3.51 -  ss.write((const char*)sig->bytes(), sig->utf8_length());
    3.52 -  ss.print(" is abstract");
    3.53 -  return SymbolTable::new_symbol(ss.base(), (int)ss.size(), CHECK_NULL);
    3.54 -}
    3.55 -
    3.56  Symbol* MethodFamily::generate_conflicts_message(GrowableArray<Method*>* methods, TRAPS) const {
    3.57    stringStream ss;
    3.58    ss.print("Conflicting default methods:");
    3.59 @@ -595,6 +579,18 @@
    3.60  #endif // ndef PRODUCT
    3.61  };
    3.62  
    3.63 +static bool already_in_vtable_slots(GrowableArray<EmptyVtableSlot*>* slots, Method* m) {
    3.64 +  bool found = false;
    3.65 +  for (int j = 0; j < slots->length(); ++j) {
    3.66 +    if (slots->at(j)->name() == m->name() &&
    3.67 +        slots->at(j)->signature() == m->signature() ) {
    3.68 +      found = true;
    3.69 +      break;
    3.70 +    }
    3.71 +  }
    3.72 +  return found;
    3.73 +}
    3.74 +
    3.75  static GrowableArray<EmptyVtableSlot*>* find_empty_vtable_slots(
    3.76      InstanceKlass* klass, GrowableArray<Method*>* mirandas, TRAPS) {
    3.77  
    3.78 @@ -604,8 +600,10 @@
    3.79  
    3.80    // All miranda methods are obvious candidates
    3.81    for (int i = 0; i < mirandas->length(); ++i) {
    3.82 -    EmptyVtableSlot* slot = new EmptyVtableSlot(mirandas->at(i));
    3.83 -    slots->append(slot);
    3.84 +    Method* m = mirandas->at(i);
    3.85 +    if (!already_in_vtable_slots(slots, m)) {
    3.86 +      slots->append(new EmptyVtableSlot(m));
    3.87 +    }
    3.88    }
    3.89  
    3.90    // Also any overpasses in our superclasses, that we haven't implemented.
    3.91 @@ -621,7 +619,26 @@
    3.92          // unless we have a real implementation of it in the current class.
    3.93          Method* impl = klass->lookup_method(m->name(), m->signature());
    3.94          if (impl == NULL || impl->is_overpass()) {
    3.95 -          slots->append(new EmptyVtableSlot(m));
    3.96 +          if (!already_in_vtable_slots(slots, m)) {
    3.97 +            slots->append(new EmptyVtableSlot(m));
    3.98 +          }
    3.99 +        }
   3.100 +      }
   3.101 +    }
   3.102 +
   3.103 +    // also any default methods in our superclasses
   3.104 +    if (super->default_methods() != NULL) {
   3.105 +      for (int i = 0; i < super->default_methods()->length(); ++i) {
   3.106 +        Method* m = super->default_methods()->at(i);
   3.107 +        // m is a method that would have been a miranda if not for the
   3.108 +        // default method processing that occurred on behalf of our superclass,
   3.109 +        // so it's a method we want to re-examine in this new context.  That is,
   3.110 +        // unless we have a real implementation of it in the current class.
   3.111 +        Method* impl = klass->lookup_method(m->name(), m->signature());
   3.112 +        if (impl == NULL || impl->is_overpass()) {
   3.113 +          if (!already_in_vtable_slots(slots, m)) {
   3.114 +            slots->append(new EmptyVtableSlot(m));
   3.115 +          }
   3.116          }
   3.117        }
   3.118      }
   3.119 @@ -679,7 +696,7 @@
   3.120      // private interface methods are not candidates for default methods
   3.121      // invokespecial to private interface methods doesn't use default method logic
   3.122      // future: take access controls into account for superclass methods
   3.123 -    if (m != NULL && (!iklass->is_interface() || m->is_public())) {
   3.124 +    if (m != NULL && !m->is_static() && (!iklass->is_interface() || m->is_public())) {
   3.125        if (_family == NULL) {
   3.126          _family = new StatefulMethodFamily();
   3.127        }
   3.128 @@ -700,7 +717,7 @@
   3.129  
   3.130  
   3.131  
   3.132 -static void create_overpasses(
   3.133 +static void create_defaults_and_exceptions(
   3.134      GrowableArray<EmptyVtableSlot*>* slots, InstanceKlass* klass, TRAPS);
   3.135  
   3.136  static void generate_erased_defaults(
   3.137 @@ -721,6 +738,8 @@
   3.138  
   3.139  static void merge_in_new_methods(InstanceKlass* klass,
   3.140      GrowableArray<Method*>* new_methods, TRAPS);
   3.141 +static void create_default_methods( InstanceKlass* klass,
   3.142 +    GrowableArray<Method*>* new_methods, TRAPS);
   3.143  
   3.144  // This is the guts of the default methods implementation.  This is called just
   3.145  // after the classfile has been parsed if some ancestor has default methods.
   3.146 @@ -782,7 +801,7 @@
   3.147    }
   3.148  #endif // ndef PRODUCT
   3.149  
   3.150 -  create_overpasses(empty_slots, klass, CHECK);
   3.151 +  create_defaults_and_exceptions(empty_slots, klass, CHECK);
   3.152  
   3.153  #ifndef PRODUCT
   3.154    if (TraceDefaultMethods) {
   3.155 @@ -791,66 +810,6 @@
   3.156  #endif // ndef PRODUCT
   3.157  }
   3.158  
   3.159 -
   3.160 -
   3.161 -#ifdef ASSERT
   3.162 -// Return true is broad type is a covariant return of narrow type
   3.163 -static bool covariant_return_type(BasicType narrow, BasicType broad) {
   3.164 -  if (narrow == broad) {
   3.165 -    return true;
   3.166 -  }
   3.167 -  if (broad == T_OBJECT) {
   3.168 -    return true;
   3.169 -  }
   3.170 -  return false;
   3.171 -}
   3.172 -#endif
   3.173 -
   3.174 -static int assemble_redirect(
   3.175 -    BytecodeConstantPool* cp, BytecodeBuffer* buffer,
   3.176 -    Symbol* incoming, Method* target, TRAPS) {
   3.177 -
   3.178 -  BytecodeAssembler assem(buffer, cp);
   3.179 -
   3.180 -  SignatureStream in(incoming, true);
   3.181 -  SignatureStream out(target->signature(), true);
   3.182 -  u2 parameter_count = 0;
   3.183 -
   3.184 -  assem.aload(parameter_count++); // load 'this'
   3.185 -
   3.186 -  while (!in.at_return_type()) {
   3.187 -    assert(!out.at_return_type(), "Parameter counts do not match");
   3.188 -    BasicType bt = in.type();
   3.189 -    assert(out.type() == bt, "Parameter types are not compatible");
   3.190 -    assem.load(bt, parameter_count);
   3.191 -    if (in.is_object() && in.as_symbol(THREAD) != out.as_symbol(THREAD)) {
   3.192 -      assem.checkcast(out.as_symbol(THREAD));
   3.193 -    } else if (bt == T_LONG || bt == T_DOUBLE) {
   3.194 -      ++parameter_count; // longs and doubles use two slots
   3.195 -    }
   3.196 -    ++parameter_count;
   3.197 -    in.next();
   3.198 -    out.next();
   3.199 -  }
   3.200 -  assert(out.at_return_type(), "Parameter counts do not match");
   3.201 -  assert(covariant_return_type(out.type(), in.type()), "Return types are not compatible");
   3.202 -
   3.203 -  if (parameter_count == 1 && (in.type() == T_LONG || in.type() == T_DOUBLE)) {
   3.204 -    ++parameter_count; // need room for return value
   3.205 -  }
   3.206 -  if (target->method_holder()->is_interface()) {
   3.207 -    assem.invokespecial(target);
   3.208 -  } else {
   3.209 -    assem.invokevirtual(target);
   3.210 -  }
   3.211 -
   3.212 -  if (in.is_object() && in.as_symbol(THREAD) != out.as_symbol(THREAD)) {
   3.213 -    assem.checkcast(in.as_symbol(THREAD));
   3.214 -  }
   3.215 -  assem._return(in.type());
   3.216 -  return parameter_count;
   3.217 -}
   3.218 -
   3.219  static int assemble_method_error(
   3.220      BytecodeConstantPool* cp, BytecodeBuffer* buffer, Symbol* errorName, Symbol* message, TRAPS) {
   3.221  
   3.222 @@ -924,18 +883,18 @@
   3.223    }
   3.224  }
   3.225  
   3.226 -// A "bridge" is a method created by javac to bridge the gap between
   3.227 -// an implementation and a generically-compatible, but different, signature.
   3.228 -// Bridges have actual bytecode implementation in classfiles.
   3.229 -// An "overpass", on the other hand, performs the same function as a bridge
   3.230 -// but does not occur in a classfile; the VM creates overpass itself,
   3.231 -// when it needs a path to get from a call site to an default method, and
   3.232 -// a bridge doesn't exist.
   3.233 -static void create_overpasses(
   3.234 +// Create default_methods list for the current class.
   3.235 +// With the VM only processing erased signatures, the VM only
   3.236 +// creates an overpass in a conflict case or a case with no candidates.
   3.237 +// This allows virtual methods to override the overpass, but ensures
   3.238 +// that a local method search will find the exception rather than an abstract
   3.239 +// or default method that is not a valid candidate.
   3.240 +static void create_defaults_and_exceptions(
   3.241      GrowableArray<EmptyVtableSlot*>* slots,
   3.242      InstanceKlass* klass, TRAPS) {
   3.243  
   3.244    GrowableArray<Method*> overpasses;
   3.245 +  GrowableArray<Method*> defaults;
   3.246    BytecodeConstantPool bpool(klass->constants());
   3.247  
   3.248    for (int i = 0; i < slots->length(); ++i) {
   3.249 @@ -943,7 +902,6 @@
   3.250  
   3.251      if (slot->is_bound()) {
   3.252        MethodFamily* method = slot->get_binding();
   3.253 -      int max_stack = 0;
   3.254        BytecodeBuffer buffer;
   3.255  
   3.256  #ifndef PRODUCT
   3.257 @@ -953,26 +911,27 @@
   3.258          tty->print_cr("");
   3.259          if (method->has_target()) {
   3.260            method->print_selected(tty, 1);
   3.261 -        } else {
   3.262 +        } else if (method->throws_exception()) {
   3.263            method->print_exception(tty, 1);
   3.264          }
   3.265        }
   3.266  #endif // ndef PRODUCT
   3.267 +
   3.268        if (method->has_target()) {
   3.269          Method* selected = method->get_selected_target();
   3.270          if (selected->method_holder()->is_interface()) {
   3.271 -          max_stack = assemble_redirect(
   3.272 -            &bpool, &buffer, slot->signature(), selected, CHECK);
   3.273 +          defaults.push(selected);
   3.274          }
   3.275        } else if (method->throws_exception()) {
   3.276 -        max_stack = assemble_method_error(&bpool, &buffer, method->get_exception_name(), method->get_exception_message(), CHECK);
   3.277 -      }
   3.278 -      if (max_stack != 0) {
   3.279 +        int max_stack = assemble_method_error(&bpool, &buffer,
   3.280 +           method->get_exception_name(), method->get_exception_message(), CHECK);
   3.281          AccessFlags flags = accessFlags_from(
   3.282            JVM_ACC_PUBLIC | JVM_ACC_SYNTHETIC | JVM_ACC_BRIDGE);
   3.283 -        Method* m = new_method(&bpool, &buffer, slot->name(), slot->signature(),
   3.284 +         Method* m = new_method(&bpool, &buffer, slot->name(), slot->signature(),
   3.285            flags, max_stack, slot->size_of_parameters(),
   3.286            ConstMethod::OVERPASS, CHECK);
   3.287 +        // We push to the methods list:
   3.288 +        // overpass methods which are exception throwing methods
   3.289          if (m != NULL) {
   3.290            overpasses.push(m);
   3.291          }
   3.292 @@ -983,11 +942,31 @@
   3.293  #ifndef PRODUCT
   3.294    if (TraceDefaultMethods) {
   3.295      tty->print_cr("Created %d overpass methods", overpasses.length());
   3.296 +    tty->print_cr("Created %d default  methods", defaults.length());
   3.297    }
   3.298  #endif // ndef PRODUCT
   3.299  
   3.300 -  switchover_constant_pool(&bpool, klass, &overpasses, CHECK);
   3.301 -  merge_in_new_methods(klass, &overpasses, CHECK);
   3.302 +  if (overpasses.length() > 0) {
   3.303 +    switchover_constant_pool(&bpool, klass, &overpasses, CHECK);
   3.304 +    merge_in_new_methods(klass, &overpasses, CHECK);
   3.305 +  }
   3.306 +  if (defaults.length() > 0) {
   3.307 +    create_default_methods(klass, &defaults, CHECK);
   3.308 +  }
   3.309 +}
   3.310 +
   3.311 +static void create_default_methods( InstanceKlass* klass,
   3.312 +    GrowableArray<Method*>* new_methods, TRAPS) {
   3.313 +
   3.314 +  int new_size = new_methods->length();
   3.315 +  Array<Method*>* total_default_methods = MetadataFactory::new_array<Method*>(
   3.316 +      klass->class_loader_data(), new_size, NULL, CHECK);
   3.317 +  for (int index = 0; index < new_size; index++ ) {
   3.318 +    total_default_methods->at_put(index, new_methods->at(index));
   3.319 +  }
   3.320 +  Method::sort_methods(total_default_methods, false, false);
   3.321 +
   3.322 +  klass->set_default_methods(total_default_methods);
   3.323  }
   3.324  
   3.325  static void sort_methods(GrowableArray<Method*>* methods) {
     4.1 --- a/src/share/vm/classfile/symbolTable.hpp	Wed Oct 09 21:45:28 2013 -0400
     4.2 +++ b/src/share/vm/classfile/symbolTable.hpp	Wed Oct 09 22:01:59 2013 -0400
     4.3 @@ -107,18 +107,13 @@
     4.4      add(loader_data, cp, names_count, name, lengths, cp_indices, hashValues, THREAD);
     4.5    }
     4.6  
     4.7 -  // Table size
     4.8 -  enum {
     4.9 -    symbol_table_size = 20011
    4.10 -  };
    4.11 -
    4.12    Symbol* lookup(int index, const char* name, int len, unsigned int hash);
    4.13  
    4.14    SymbolTable()
    4.15 -    : Hashtable<Symbol*, mtSymbol>(symbol_table_size, sizeof (HashtableEntry<Symbol*, mtSymbol>)) {}
    4.16 +    : Hashtable<Symbol*, mtSymbol>(SymbolTableSize, sizeof (HashtableEntry<Symbol*, mtSymbol>)) {}
    4.17  
    4.18    SymbolTable(HashtableBucket<mtSymbol>* t, int number_of_entries)
    4.19 -    : Hashtable<Symbol*, mtSymbol>(symbol_table_size, sizeof (HashtableEntry<Symbol*, mtSymbol>), t,
    4.20 +    : Hashtable<Symbol*, mtSymbol>(SymbolTableSize, sizeof (HashtableEntry<Symbol*, mtSymbol>), t,
    4.21                  number_of_entries) {}
    4.22  
    4.23    // Arena for permanent symbols (null class loader) that are never unloaded
    4.24 @@ -136,6 +131,9 @@
    4.25    // The symbol table
    4.26    static SymbolTable* the_table() { return _the_table; }
    4.27  
    4.28 +  // Size of one bucket in the string table.  Used when checking for rollover.
    4.29 +  static uint bucket_size() { return sizeof(HashtableBucket<mtSymbol>); }
    4.30 +
    4.31    static void create_table() {
    4.32      assert(_the_table == NULL, "One symbol table allowed.");
    4.33      _the_table = new SymbolTable();
    4.34 @@ -145,8 +143,11 @@
    4.35    static void create_table(HashtableBucket<mtSymbol>* t, int length,
    4.36                             int number_of_entries) {
    4.37      assert(_the_table == NULL, "One symbol table allowed.");
    4.38 -    assert(length == symbol_table_size * sizeof(HashtableBucket<mtSymbol>),
    4.39 -           "bad shared symbol size.");
    4.40 +
    4.41 +    // If CDS archive used a different symbol table size, use that size instead
    4.42 +    // which is better than giving an error.
    4.43 +    SymbolTableSize = length/bucket_size();
    4.44 +
    4.45      _the_table = new SymbolTable(t, number_of_entries);
    4.46      // if CDS give symbol table a default arena size since most symbols
    4.47      // are already allocated in the shared misc section.
     5.1 --- a/src/share/vm/classfile/verifier.cpp	Wed Oct 09 21:45:28 2013 -0400
     5.2 +++ b/src/share/vm/classfile/verifier.cpp	Wed Oct 09 22:01:59 2013 -0400
     5.3 @@ -2442,10 +2442,16 @@
     5.4      bool subtype = ref_class_type.is_assignable_from(
     5.5        current_type(), this, CHECK_VERIFY(this));
     5.6      if (!subtype) {
     5.7 -      verify_error(ErrorContext::bad_code(bci),
     5.8 -          "Bad invokespecial instruction: "
     5.9 -          "current class isn't assignable to reference class.");
    5.10 -       return;
    5.11 +      if (current_class()->is_anonymous()) {
    5.12 +        subtype = ref_class_type.is_assignable_from(VerificationType::reference_type(
    5.13 +                   current_class()->host_klass()->name()), this, CHECK_VERIFY(this));
    5.14 +      }
    5.15 +      if (!subtype) {
    5.16 +        verify_error(ErrorContext::bad_code(bci),
    5.17 +            "Bad invokespecial instruction: "
    5.18 +            "current class isn't assignable to reference class.");
    5.19 +         return;
    5.20 +      }
    5.21      }
    5.22    }
    5.23    // Match method descriptor with operand stack
    5.24 @@ -2461,7 +2467,28 @@
    5.25      } else {   // other methods
    5.26        // Ensures that target class is assignable to method class.
    5.27        if (opcode == Bytecodes::_invokespecial) {
    5.28 -        current_frame->pop_stack(current_type(), CHECK_VERIFY(this));
    5.29 +        if (!current_class()->is_anonymous()) {
    5.30 +          current_frame->pop_stack(current_type(), CHECK_VERIFY(this));
    5.31 +        } else {
    5.32 +          // anonymous class invokespecial calls: either the
    5.33 +          // operand stack/objectref  is a subtype of the current class OR
    5.34 +          // the objectref is a subtype of the host_klass of the current class
    5.35 +          // to allow an anonymous class to reference methods in the host_klass
    5.36 +          VerificationType top = current_frame->pop_stack(CHECK_VERIFY(this));
    5.37 +          bool subtype = current_type().is_assignable_from(top, this, CHECK_VERIFY(this));
    5.38 +          if (!subtype) {
    5.39 +            VerificationType hosttype =
    5.40 +              VerificationType::reference_type(current_class()->host_klass()->name());
    5.41 +            subtype = hosttype.is_assignable_from(top, this, CHECK_VERIFY(this));
    5.42 +          }
    5.43 +          if (!subtype) {
    5.44 +            verify_error( ErrorContext::bad_type(current_frame->offset(),
    5.45 +              current_frame->stack_top_ctx(),
    5.46 +              TypeOrigin::implicit(top)),
    5.47 +              "Bad type on operand stack");
    5.48 +            return;
    5.49 +          }
    5.50 +        }
    5.51        } else if (opcode == Bytecodes::_invokevirtual) {
    5.52          VerificationType stack_object_type =
    5.53            current_frame->pop_stack(ref_class_type, CHECK_VERIFY(this));
     6.1 --- a/src/share/vm/code/dependencies.cpp	Wed Oct 09 21:45:28 2013 -0400
     6.2 +++ b/src/share/vm/code/dependencies.cpp	Wed Oct 09 22:01:59 2013 -0400
     6.3 @@ -1,5 +1,5 @@
     6.4  /*
     6.5 - * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
     6.6 + * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
     6.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     6.8   *
     6.9   * This code is free software; you can redistribute it and/or modify it
    6.10 @@ -812,8 +812,8 @@
    6.11      Klass* k = ctxk;
    6.12      Method* lm = k->lookup_method(m->name(), m->signature());
    6.13      if (lm == NULL && k->oop_is_instance()) {
    6.14 -      // It might be an abstract interface method, devoid of mirandas.
    6.15 -      lm = ((InstanceKlass*)k)->lookup_method_in_all_interfaces(m->name(),
    6.16 +      // It might be an interface method
    6.17 +        lm = ((InstanceKlass*)k)->lookup_method_in_ordered_interfaces(m->name(),
    6.18                                                                  m->signature());
    6.19      }
    6.20      if (lm == m)
     7.1 --- a/src/share/vm/interpreter/linkResolver.cpp	Wed Oct 09 21:45:28 2013 -0400
     7.2 +++ b/src/share/vm/interpreter/linkResolver.cpp	Wed Oct 09 22:01:59 2013 -0400
     7.3 @@ -1,4 +1,5 @@
     7.4  /*
     7.5 + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
     7.6   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     7.7   *
     7.8   * This code is free software; you can redistribute it and/or modify it
     7.9 @@ -221,8 +222,17 @@
    7.10  //
    7.11  // According to JVM spec. $5.4.3c & $5.4.3d
    7.12  
    7.13 +// Look up method in klasses, including static methods
    7.14 +// Then look up local default methods
    7.15  void LinkResolver::lookup_method_in_klasses(methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS) {
    7.16    Method* result_oop = klass->uncached_lookup_method(name, signature);
    7.17 +  if (result_oop == NULL) {
    7.18 +    Array<Method*>* default_methods = InstanceKlass::cast(klass())->default_methods();
    7.19 +    if (default_methods != NULL) {
    7.20 +      result_oop = InstanceKlass::find_method(default_methods, name, signature);
    7.21 +    }
    7.22 +  }
    7.23 +
    7.24    if (EnableInvokeDynamic && result_oop != NULL) {
    7.25      vmIntrinsics::ID iid = result_oop->intrinsic_id();
    7.26      if (MethodHandles::is_signature_polymorphic(iid)) {
    7.27 @@ -234,6 +244,7 @@
    7.28  }
    7.29  
    7.30  // returns first instance method
    7.31 +// Looks up method in classes, then looks up local default methods
    7.32  void LinkResolver::lookup_instance_method_in_klasses(methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS) {
    7.33    Method* result_oop = klass->uncached_lookup_method(name, signature);
    7.34    result = methodHandle(THREAD, result_oop);
    7.35 @@ -241,13 +252,38 @@
    7.36      klass = KlassHandle(THREAD, result->method_holder()->super());
    7.37      result = methodHandle(THREAD, klass->uncached_lookup_method(name, signature));
    7.38    }
    7.39 +
    7.40 +  if (result.is_null()) {
    7.41 +    Array<Method*>* default_methods = InstanceKlass::cast(klass())->default_methods();
    7.42 +    if (default_methods != NULL) {
    7.43 +      result = methodHandle(InstanceKlass::find_method(default_methods, name, signature));
    7.44 +      assert(result.is_null() || !result->is_static(), "static defaults not allowed");
    7.45 +    }
    7.46 +  }
    7.47  }
    7.48  
    7.49 +int LinkResolver::vtable_index_of_interface_method(KlassHandle klass,
    7.50 +                                          methodHandle resolved_method, TRAPS) {
    7.51  
    7.52 -int LinkResolver::vtable_index_of_miranda_method(KlassHandle klass, Symbol* name, Symbol* signature, TRAPS) {
    7.53 -  ResourceMark rm(THREAD);
    7.54 -  klassVtable *vt = InstanceKlass::cast(klass())->vtable();
    7.55 -  return vt->index_of_miranda(name, signature);
    7.56 +  int vtable_index = Method::invalid_vtable_index;
    7.57 +  Symbol* name = resolved_method->name();
    7.58 +  Symbol* signature = resolved_method->signature();
    7.59 +
    7.60 +  // First check in default method array
    7.61 +  if (!resolved_method->is_abstract()  &&
    7.62 +    (InstanceKlass::cast(klass())->default_methods() != NULL)) {
    7.63 +    int index = InstanceKlass::find_method_index(InstanceKlass::cast(klass())->default_methods(), name, signature);
    7.64 +    if (index >= 0 ) {
    7.65 +      vtable_index = InstanceKlass::cast(klass())->default_vtable_indices()->at(index);
    7.66 +    }
    7.67 +  }
    7.68 +  if (vtable_index == Method::invalid_vtable_index) {
    7.69 +    // get vtable_index for miranda methods
    7.70 +    ResourceMark rm(THREAD);
    7.71 +    klassVtable *vt = InstanceKlass::cast(klass())->vtable();
    7.72 +    vtable_index = vt->index_of_miranda(name, signature);
    7.73 +  }
    7.74 +  return vtable_index;
    7.75  }
    7.76  
    7.77  void LinkResolver::lookup_method_in_interfaces(methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS) {
    7.78 @@ -625,6 +661,12 @@
    7.79                     resolved_method->method_holder()->internal_name()
    7.80                    );
    7.81      resolved_method->access_flags().print_on(tty);
    7.82 +    if (resolved_method->is_default_method()) {
    7.83 +      tty->print("default");
    7.84 +    }
    7.85 +    if (resolved_method->is_overpass()) {
    7.86 +      tty->print("overpass");
    7.87 +    }
    7.88      tty->cr();
    7.89    }
    7.90  }
    7.91 @@ -853,6 +895,7 @@
    7.92                                                           resolved_method->signature()));
    7.93      THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
    7.94    }
    7.95 +
    7.96    if (TraceItables && Verbose) {
    7.97      ResourceMark rm(THREAD);
    7.98      tty->print("invokespecial resolved method: caller-class:%s, compile-time-class:%s, method:%s, method_holder:%s, access_flags: ",
    7.99 @@ -864,8 +907,7 @@
   7.100                  resolved_method->method_holder()->internal_name()
   7.101                 );
   7.102      resolved_method->access_flags().print_on(tty);
   7.103 -    if (resolved_method->method_holder()->is_interface() &&
   7.104 -        !resolved_method->is_abstract()) {
   7.105 +    if (resolved_method->is_default_method()) {
   7.106        tty->print("default");
   7.107      }
   7.108      if (resolved_method->is_overpass()) {
   7.109 @@ -945,10 +987,12 @@
   7.110                   sel_method->method_holder()->internal_name()
   7.111                  );
   7.112      sel_method->access_flags().print_on(tty);
   7.113 -    if (sel_method->method_holder()->is_interface() &&
   7.114 -        !sel_method->is_abstract()) {
   7.115 +    if (sel_method->is_default_method()) {
   7.116        tty->print("default");
   7.117      }
   7.118 +    if (sel_method->is_overpass()) {
   7.119 +      tty->print("overpass");
   7.120 +    }
   7.121      tty->cr();
   7.122    }
   7.123  
   7.124 @@ -996,26 +1040,25 @@
   7.125      THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), buf);
   7.126    }
   7.127  
   7.128 - if (PrintVtables && Verbose) {
   7.129 -   ResourceMark rm(THREAD);
   7.130 -   tty->print("invokevirtual resolved method: caller-class:%s, compile-time-class:%s, method:%s, method_holder:%s, access_flags: ",
   7.131 -                  (current_klass.is_null() ? "<NULL>" : current_klass->internal_name()),
   7.132 -                  (resolved_klass.is_null() ? "<NULL>" : resolved_klass->internal_name()),
   7.133 -                  Method::name_and_sig_as_C_string(resolved_klass(),
   7.134 -                                                   resolved_method->name(),
   7.135 -                                                   resolved_method->signature()),
   7.136 -                  resolved_method->method_holder()->internal_name()
   7.137 -                 );
   7.138 -   resolved_method->access_flags().print_on(tty);
   7.139 -   if (resolved_method->method_holder()->is_interface() &&
   7.140 -       !resolved_method->is_abstract()) {
   7.141 -     tty->print("default");
   7.142 -   }
   7.143 -   if (resolved_method->is_overpass()) {
   7.144 -     tty->print("overpass");
   7.145 -   }
   7.146 -   tty->cr();
   7.147 - }
   7.148 +  if (PrintVtables && Verbose) {
   7.149 +    ResourceMark rm(THREAD);
   7.150 +    tty->print("invokevirtual resolved method: caller-class:%s, compile-time-class:%s, method:%s, method_holder:%s, access_flags: ",
   7.151 +                   (current_klass.is_null() ? "<NULL>" : current_klass->internal_name()),
   7.152 +                   (resolved_klass.is_null() ? "<NULL>" : resolved_klass->internal_name()),
   7.153 +                   Method::name_and_sig_as_C_string(resolved_klass(),
   7.154 +                                                    resolved_method->name(),
   7.155 +                                                    resolved_method->signature()),
   7.156 +                   resolved_method->method_holder()->internal_name()
   7.157 +                  );
   7.158 +    resolved_method->access_flags().print_on(tty);
   7.159 +    if (resolved_method->is_default_method()) {
   7.160 +      tty->print("default");
   7.161 +    }
   7.162 +    if (resolved_method->is_overpass()) {
   7.163 +      tty->print("overpass");
   7.164 +    }
   7.165 +    tty->cr();
   7.166 +  }
   7.167  }
   7.168  
   7.169  // throws runtime exceptions
   7.170 @@ -1045,10 +1088,8 @@
   7.171  
   7.172    // do lookup based on receiver klass using the vtable index
   7.173    if (resolved_method->method_holder()->is_interface()) { // miranda method
   7.174 -    vtable_index = vtable_index_of_miranda_method(resolved_klass,
   7.175 -                           resolved_method->name(),
   7.176 -                           resolved_method->signature(), CHECK);
   7.177 -
   7.178 +    vtable_index = vtable_index_of_interface_method(resolved_klass,
   7.179 +                           resolved_method, CHECK);
   7.180      assert(vtable_index >= 0 , "we should have valid vtable index at this point");
   7.181  
   7.182      InstanceKlass* inst = InstanceKlass::cast(recv_klass());
   7.183 @@ -1104,11 +1145,10 @@
   7.184                     vtable_index
   7.185                    );
   7.186      selected_method->access_flags().print_on(tty);
   7.187 -    if (selected_method->method_holder()->is_interface() &&
   7.188 -        !selected_method->is_abstract()) {
   7.189 +    if (selected_method->is_default_method()) {
   7.190        tty->print("default");
   7.191      }
   7.192 -    if (resolved_method->is_overpass()) {
   7.193 +    if (selected_method->is_overpass()) {
   7.194        tty->print("overpass");
   7.195      }
   7.196      tty->cr();
   7.197 @@ -1191,7 +1231,6 @@
   7.198                                                 sel_method->name(),
   7.199                                                 sel_method->signature()));
   7.200    }
   7.201 -
   7.202    // check if abstract
   7.203    if (check_null_and_abstract && sel_method->is_abstract()) {
   7.204      ResourceMark rm(THREAD);
   7.205 @@ -1220,11 +1259,10 @@
   7.206                     sel_method->method_holder()->internal_name()
   7.207                    );
   7.208      sel_method->access_flags().print_on(tty);
   7.209 -    if (sel_method->method_holder()->is_interface() &&
   7.210 -        !sel_method->is_abstract()) {
   7.211 +    if (sel_method->is_default_method()) {
   7.212        tty->print("default");
   7.213      }
   7.214 -    if (resolved_method->is_overpass()) {
   7.215 +    if (sel_method->is_overpass()) {
   7.216        tty->print("overpass");
   7.217      }
   7.218      tty->cr();
     8.1 --- a/src/share/vm/interpreter/linkResolver.hpp	Wed Oct 09 21:45:28 2013 -0400
     8.2 +++ b/src/share/vm/interpreter/linkResolver.hpp	Wed Oct 09 22:01:59 2013 -0400
     8.3 @@ -130,8 +130,7 @@
     8.4    static void lookup_polymorphic_method         (methodHandle& result, KlassHandle klass, Symbol* name, Symbol* signature,
     8.5                                                   KlassHandle current_klass, Handle *appendix_result_or_null, Handle *method_type_result, TRAPS);
     8.6  
     8.7 -  static int vtable_index_of_miranda_method(KlassHandle klass, Symbol* name, Symbol* signature, TRAPS);
     8.8 -
     8.9 +  static int vtable_index_of_interface_method(KlassHandle klass, methodHandle resolved_method, TRAPS);
    8.10    static void resolve_klass           (KlassHandle& result, constantPoolHandle  pool, int index, TRAPS);
    8.11  
    8.12    static void resolve_pool  (KlassHandle& resolved_klass, Symbol*& method_name, Symbol*& method_signature, KlassHandle& current_klass, constantPoolHandle pool, int index, TRAPS);
     9.1 --- a/src/share/vm/memory/heapInspection.hpp	Wed Oct 09 21:45:28 2013 -0400
     9.2 +++ b/src/share/vm/memory/heapInspection.hpp	Wed Oct 09 22:01:59 2013 -0400
     9.3 @@ -73,6 +73,10 @@
     9.4          "Number of bytes used by the InstanceKlass::methods() array") \
     9.5      f(method_ordering_bytes, IK_method_ordering, \
     9.6          "Number of bytes used by the InstanceKlass::method_ordering() array") \
     9.7 +    f(default_methods_array_bytes, IK_default_methods, \
     9.8 +        "Number of bytes used by the InstanceKlass::default_methods() array") \
     9.9 +    f(default_vtable_indices_bytes, IK_default_vtable_indices, \
    9.10 +        "Number of bytes used by the InstanceKlass::default_vtable_indices() array") \
    9.11      f(local_interfaces_bytes, IK_local_interfaces, \
    9.12          "Number of bytes used by the InstanceKlass::local_interfaces() array") \
    9.13      f(transitive_interfaces_bytes, IK_transitive_interfaces, \
    10.1 --- a/src/share/vm/oops/instanceKlass.cpp	Wed Oct 09 21:45:28 2013 -0400
    10.2 +++ b/src/share/vm/oops/instanceKlass.cpp	Wed Oct 09 22:01:59 2013 -0400
    10.3 @@ -238,6 +238,13 @@
    10.4    }
    10.5  }
    10.6  
    10.7 +// create a new array of vtable_indices for default methods
    10.8 +Array<int>* InstanceKlass::create_new_default_vtable_indices(int len, TRAPS) {
    10.9 +  Array<int>* vtable_indices = MetadataFactory::new_array<int>(class_loader_data(), len, CHECK_NULL);
   10.10 +  assert(default_vtable_indices() == NULL, "only create once");
   10.11 +  set_default_vtable_indices(vtable_indices);
   10.12 +  return vtable_indices;
   10.13 +}
   10.14  
   10.15  InstanceKlass::InstanceKlass(int vtable_len,
   10.16                               int itable_len,
   10.17 @@ -263,6 +270,8 @@
   10.18    set_array_klasses(NULL);
   10.19    set_methods(NULL);
   10.20    set_method_ordering(NULL);
   10.21 +  set_default_methods(NULL);
   10.22 +  set_default_vtable_indices(NULL);
   10.23    set_local_interfaces(NULL);
   10.24    set_transitive_interfaces(NULL);
   10.25    init_implementor();
   10.26 @@ -376,6 +385,21 @@
   10.27    }
   10.28    set_method_ordering(NULL);
   10.29  
   10.30 +  // default methods can be empty
   10.31 +  if (default_methods() != NULL &&
   10.32 +      default_methods() != Universe::the_empty_method_array()) {
   10.33 +    MetadataFactory::free_array<Method*>(loader_data, default_methods());
   10.34 +  }
   10.35 +  // Do NOT deallocate the default methods, they are owned by superinterfaces.
   10.36 +  set_default_methods(NULL);
   10.37 +
   10.38 +  // default methods vtable indices can be empty
   10.39 +  if (default_vtable_indices() != NULL) {
   10.40 +    MetadataFactory::free_array<int>(loader_data, default_vtable_indices());
   10.41 +  }
   10.42 +  set_default_vtable_indices(NULL);
   10.43 +
   10.44 +
   10.45    // This array is in Klass, but remove it with the InstanceKlass since
   10.46    // this place would be the only caller and it can share memory with transitive
   10.47    // interfaces.
   10.48 @@ -1354,32 +1378,44 @@
   10.49    return -1;
   10.50  }
   10.51  
   10.52 +// find_method looks up the name/signature in the local methods array
   10.53  Method* InstanceKlass::find_method(Symbol* name, Symbol* signature) const {
   10.54    return InstanceKlass::find_method(methods(), name, signature);
   10.55  }
   10.56  
   10.57 +// find_method looks up the name/signature in the local methods array
   10.58  Method* InstanceKlass::find_method(
   10.59      Array<Method*>* methods, Symbol* name, Symbol* signature) {
   10.60 +  int hit = find_method_index(methods, name, signature);
   10.61 +  return hit >= 0 ? methods->at(hit): NULL;
   10.62 +}
   10.63 +
   10.64 +// Used directly for default_methods to find the index into the
   10.65 +// default_vtable_indices, and indirectly by find_method
   10.66 +// find_method_index looks in the local methods array to return the index
   10.67 +// of the matching name/signature
   10.68 +int InstanceKlass::find_method_index(
   10.69 +    Array<Method*>* methods, Symbol* name, Symbol* signature) {
   10.70    int hit = binary_search(methods, name);
   10.71    if (hit != -1) {
   10.72      Method* m = methods->at(hit);
   10.73      // Do linear search to find matching signature.  First, quick check
   10.74      // for common case
   10.75 -    if (m->signature() == signature) return m;
   10.76 +    if (m->signature() == signature) return hit;
   10.77      // search downwards through overloaded methods
   10.78      int i;
   10.79      for (i = hit - 1; i >= 0; --i) {
   10.80          Method* m = methods->at(i);
   10.81          assert(m->is_method(), "must be method");
   10.82          if (m->name() != name) break;
   10.83 -        if (m->signature() == signature) return m;
   10.84 +        if (m->signature() == signature) return i;
   10.85      }
   10.86      // search upwards
   10.87      for (i = hit + 1; i < methods->length(); ++i) {
   10.88          Method* m = methods->at(i);
   10.89          assert(m->is_method(), "must be method");
   10.90          if (m->name() != name) break;
   10.91 -        if (m->signature() == signature) return m;
   10.92 +        if (m->signature() == signature) return i;
   10.93      }
   10.94      // not found
   10.95  #ifdef ASSERT
   10.96 @@ -1387,9 +1423,8 @@
   10.97      assert(index == -1, err_msg("binary search should have found entry %d", index));
   10.98  #endif
   10.99    }
  10.100 -  return NULL;
  10.101 +  return -1;
  10.102  }
  10.103 -
  10.104  int InstanceKlass::find_method_by_name(Symbol* name, int* end) {
  10.105    return find_method_by_name(methods(), name, end);
  10.106  }
  10.107 @@ -1408,6 +1443,7 @@
  10.108    return -1;
  10.109  }
  10.110  
  10.111 +// lookup_method searches both the local methods array and all superclasses methods arrays
  10.112  Method* InstanceKlass::uncached_lookup_method(Symbol* name, Symbol* signature) const {
  10.113    Klass* klass = const_cast<InstanceKlass*>(this);
  10.114    while (klass != NULL) {
  10.115 @@ -1418,6 +1454,21 @@
  10.116    return NULL;
  10.117  }
  10.118  
  10.119 +// lookup a method in the default methods list then in all transitive interfaces
  10.120 +// Do NOT return private or static methods
  10.121 +Method* InstanceKlass::lookup_method_in_ordered_interfaces(Symbol* name,
  10.122 +                                                         Symbol* signature) const {
  10.123 +  Method* m = NULL;
  10.124 +  if (default_methods() != NULL) {
  10.125 +    m = find_method(default_methods(), name, signature);
  10.126 +  }
  10.127 +  // Look up interfaces
  10.128 +  if (m == NULL) {
  10.129 +    m = lookup_method_in_all_interfaces(name, signature);
  10.130 +  }
  10.131 +  return m;
  10.132 +}
  10.133 +
  10.134  // lookup a method in all the interfaces that this class implements
  10.135  // Do NOT return private or static methods, new in JDK8 which are not externally visible
  10.136  // They should only be found in the initial InterfaceMethodRef
  10.137 @@ -2548,6 +2599,42 @@
  10.138    return m;
  10.139  }
  10.140  
  10.141 +
  10.142 +#if INCLUDE_JVMTI
  10.143 +// update default_methods for redefineclasses for methods that are
  10.144 +// not yet in the vtable due to concurrent subclass define and superinterface
  10.145 +// redefinition
  10.146 +// Note: those in the vtable, should have been updated via adjust_method_entries
  10.147 +void InstanceKlass::adjust_default_methods(Method** old_methods, Method** new_methods,
  10.148 +                                           int methods_length, bool* trace_name_printed) {
  10.149 +  // search the default_methods for uses of either obsolete or EMCP methods
  10.150 +  if (default_methods() != NULL) {
  10.151 +    for (int j = 0; j < methods_length; j++) {
  10.152 +      Method* old_method = old_methods[j];
  10.153 +      Method* new_method = new_methods[j];
  10.154 +
  10.155 +      for (int index = 0; index < default_methods()->length(); index ++) {
  10.156 +        if (default_methods()->at(index) == old_method) {
  10.157 +          default_methods()->at_put(index, new_method);
  10.158 +          if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
  10.159 +            if (!(*trace_name_printed)) {
  10.160 +              // RC_TRACE_MESG macro has an embedded ResourceMark
  10.161 +              RC_TRACE_MESG(("adjust: klassname=%s default methods from name=%s",
  10.162 +                             external_name(),
  10.163 +                             old_method->method_holder()->external_name()));
  10.164 +              *trace_name_printed = true;
  10.165 +            }
  10.166 +            RC_TRACE(0x00100000, ("default method update: %s(%s) ",
  10.167 +                                  new_method->name()->as_C_string(),
  10.168 +                                  new_method->signature()->as_C_string()));
  10.169 +          }
  10.170 +        }
  10.171 +      }
  10.172 +    }
  10.173 +  }
  10.174 +}
  10.175 +#endif // INCLUDE_JVMTI
  10.176 +
  10.177  // On-stack replacement stuff
  10.178  void InstanceKlass::add_osr_nmethod(nmethod* n) {
  10.179    // only one compilation can be active
  10.180 @@ -2742,11 +2829,21 @@
  10.181    st->print(BULLET"methods:           "); methods()->print_value_on(st);                  st->cr();
  10.182    if (Verbose || WizardMode) {
  10.183      Array<Method*>* method_array = methods();
  10.184 -    for(int i = 0; i < method_array->length(); i++) {
  10.185 +    for (int i = 0; i < method_array->length(); i++) {
  10.186        st->print("%d : ", i); method_array->at(i)->print_value(); st->cr();
  10.187      }
  10.188    }
  10.189 -  st->print(BULLET"method ordering:   "); method_ordering()->print_value_on(st);       st->cr();
  10.190 +  st->print(BULLET"method ordering:   "); method_ordering()->print_value_on(st);      st->cr();
  10.191 +  st->print(BULLET"default_methods:   "); default_methods()->print_value_on(st);      st->cr();
  10.192 +  if (Verbose && default_methods() != NULL) {
  10.193 +    Array<Method*>* method_array = default_methods();
  10.194 +    for (int i = 0; i < method_array->length(); i++) {
  10.195 +      st->print("%d : ", i); method_array->at(i)->print_value(); st->cr();
  10.196 +    }
  10.197 +  }
  10.198 +  if (default_vtable_indices() != NULL) {
  10.199 +    st->print(BULLET"default vtable indices:   "); default_vtable_indices()->print_value_on(st);       st->cr();
  10.200 +  }
  10.201    st->print(BULLET"local interfaces:  "); local_interfaces()->print_value_on(st);      st->cr();
  10.202    st->print(BULLET"trans. interfaces: "); transitive_interfaces()->print_value_on(st); st->cr();
  10.203    st->print(BULLET"constants:         "); constants()->print_value_on(st);         st->cr();
  10.204 @@ -3099,6 +3196,19 @@
  10.205      }
  10.206    }
  10.207  
  10.208 +  // Verify default methods
  10.209 +  if (default_methods() != NULL) {
  10.210 +    Array<Method*>* methods = this->default_methods();
  10.211 +    for (int j = 0; j < methods->length(); j++) {
  10.212 +      guarantee(methods->at(j)->is_method(), "non-method in methods array");
  10.213 +    }
  10.214 +    for (int j = 0; j < methods->length() - 1; j++) {
  10.215 +      Method* m1 = methods->at(j);
  10.216 +      Method* m2 = methods->at(j + 1);
  10.217 +      guarantee(m1->name()->fast_compare(m2->name()) <= 0, "methods not sorted correctly");
  10.218 +    }
  10.219 +  }
  10.220 +
  10.221    // Verify JNI static field identifiers
  10.222    if (jni_ids() != NULL) {
  10.223      jni_ids()->verify(this);
    11.1 --- a/src/share/vm/oops/instanceKlass.hpp	Wed Oct 09 21:45:28 2013 -0400
    11.2 +++ b/src/share/vm/oops/instanceKlass.hpp	Wed Oct 09 22:01:59 2013 -0400
    11.3 @@ -269,12 +269,18 @@
    11.4  
    11.5    // Method array.
    11.6    Array<Method*>* _methods;
    11.7 +  // Default Method Array, concrete methods inherited from interfaces
    11.8 +  Array<Method*>* _default_methods;
    11.9    // Interface (Klass*s) this class declares locally to implement.
   11.10    Array<Klass*>* _local_interfaces;
   11.11    // Interface (Klass*s) this class implements transitively.
   11.12    Array<Klass*>* _transitive_interfaces;
   11.13    // Int array containing the original order of method in the class file (for JVMTI).
   11.14    Array<int>*     _method_ordering;
   11.15 +  // Int array containing the vtable_indices for default_methods
   11.16 +  // offset matches _default_methods offset
   11.17 +  Array<int>*     _default_vtable_indices;
   11.18 +
   11.19    // Instance and static variable information, starts with 6-tuples of shorts
   11.20    // [access, name index, sig index, initval index, low_offset, high_offset]
   11.21    // for all fields, followed by the generic signature data at the end of
   11.22 @@ -356,6 +362,15 @@
   11.23    void set_method_ordering(Array<int>* m) { _method_ordering = m; }
   11.24    void copy_method_ordering(intArray* m, TRAPS);
   11.25  
   11.26 +  // default_methods
   11.27 +  Array<Method*>* default_methods() const  { return _default_methods; }
   11.28 +  void set_default_methods(Array<Method*>* a) { _default_methods = a; }
   11.29 +
   11.30 +  // default method vtable_indices
   11.31 +  Array<int>* default_vtable_indices() const { return _default_vtable_indices; }
   11.32 +  void set_default_vtable_indices(Array<int>* v) { _default_vtable_indices = v; }
   11.33 +  Array<int>* create_new_default_vtable_indices(int len, TRAPS);
   11.34 +
   11.35    // interfaces
   11.36    Array<Klass*>* local_interfaces() const          { return _local_interfaces; }
   11.37    void set_local_interfaces(Array<Klass*>* a)      {
   11.38 @@ -501,12 +516,18 @@
   11.39    Method* find_method(Symbol* name, Symbol* signature) const;
   11.40    static Method* find_method(Array<Method*>* methods, Symbol* name, Symbol* signature);
   11.41  
   11.42 +  // find a local method index in default_methods (returns -1 if not found)
   11.43 +  static int find_method_index(Array<Method*>* methods, Symbol* name, Symbol* signature);
   11.44 +
   11.45    // lookup operation (returns NULL if not found)
   11.46    Method* uncached_lookup_method(Symbol* name, Symbol* signature) const;
   11.47  
   11.48    // lookup a method in all the interfaces that this class implements
   11.49    // (returns NULL if not found)
   11.50    Method* lookup_method_in_all_interfaces(Symbol* name, Symbol* signature) const;
   11.51 +  // lookup a method in local defaults then in all interfaces
   11.52 +  // (returns NULL if not found)
   11.53 +  Method* lookup_method_in_ordered_interfaces(Symbol* name, Symbol* signature) const;
   11.54  
   11.55    // Find method indices by name.  If a method with the specified name is
   11.56    // found the index to the first method is returned, and 'end' is filled in
   11.57 @@ -910,6 +931,11 @@
   11.58    klassItable* itable() const;        // return new klassItable wrapper
   11.59    Method* method_at_itable(Klass* holder, int index, TRAPS);
   11.60  
   11.61 +#if INCLUDE_JVMTI
   11.62 +  void adjust_default_methods(Method** old_methods, Method** new_methods,
   11.63 +                              int methods_length, bool* trace_name_printed);
   11.64 +#endif // INCLUDE_JVMTI
   11.65 +
   11.66    // Garbage collection
   11.67    void oop_follow_contents(oop obj);
   11.68    int  oop_adjust_pointers(oop obj);
    12.1 --- a/src/share/vm/oops/klassVtable.cpp	Wed Oct 09 21:45:28 2013 -0400
    12.2 +++ b/src/share/vm/oops/klassVtable.cpp	Wed Oct 09 22:01:59 2013 -0400
    12.3 @@ -83,7 +83,7 @@
    12.4  
    12.5    GrowableArray<Method*> new_mirandas(20);
    12.6    // compute the number of mirandas methods that must be added to the end
    12.7 -  get_mirandas(&new_mirandas, all_mirandas, super, methods, local_interfaces);
    12.8 +  get_mirandas(&new_mirandas, all_mirandas, super, methods, NULL, local_interfaces);
    12.9    *num_new_mirandas = new_mirandas.length();
   12.10  
   12.11    vtable_length += *num_new_mirandas * vtableEntry::size();
   12.12 @@ -186,7 +186,7 @@
   12.13        assert(methods->at(i)->is_method(), "must be a Method*");
   12.14        methodHandle mh(THREAD, methods->at(i));
   12.15  
   12.16 -      bool needs_new_entry = update_inherited_vtable(ik(), mh, super_vtable_len, checkconstraints, CHECK);
   12.17 +      bool needs_new_entry = update_inherited_vtable(ik(), mh, super_vtable_len, -1, checkconstraints, CHECK);
   12.18  
   12.19        if (needs_new_entry) {
   12.20          put_method_at(mh(), initialized);
   12.21 @@ -195,7 +195,35 @@
   12.22        }
   12.23      }
   12.24  
   12.25 -    // add miranda methods to end of vtable.
   12.26 +    // update vtable with default_methods
   12.27 +    Array<Method*>* default_methods = ik()->default_methods();
   12.28 +    if (default_methods != NULL) {
   12.29 +      len = default_methods->length();
   12.30 +      if (len > 0) {
   12.31 +        Array<int>* def_vtable_indices = NULL;
   12.32 +        if ((def_vtable_indices = ik()->default_vtable_indices()) == NULL) {
   12.33 +          def_vtable_indices = ik()->create_new_default_vtable_indices(len, CHECK);
   12.34 +        } else {
   12.35 +          assert(def_vtable_indices->length() == len, "reinit vtable len?");
   12.36 +        }
   12.37 +        for (int i = 0; i < len; i++) {
   12.38 +          HandleMark hm(THREAD);
   12.39 +          assert(default_methods->at(i)->is_method(), "must be a Method*");
   12.40 +          methodHandle mh(THREAD, default_methods->at(i));
   12.41 +
   12.42 +          bool needs_new_entry = update_inherited_vtable(ik(), mh, super_vtable_len, i, checkconstraints, CHECK);
   12.43 +
   12.44 +          // needs new entry
   12.45 +          if (needs_new_entry) {
   12.46 +            put_method_at(mh(), initialized);
   12.47 +            def_vtable_indices->at_put(i, initialized); //set vtable index
   12.48 +            initialized++;
   12.49 +          }
   12.50 +        }
   12.51 +      }
   12.52 +    }
   12.53 +
   12.54 +    // add miranda methods; it will also return the updated initialized
   12.55      initialized = fill_in_mirandas(initialized);
   12.56  
   12.57      // In class hierarchies where the accessibility is not increasing (i.e., going from private ->
   12.58 @@ -230,14 +258,19 @@
   12.59  #ifndef PRODUCT
   12.60          if (PrintVtables && Verbose) {
   12.61            ResourceMark rm(THREAD);
   12.62 +          char* sig = target_method()->name_and_sig_as_C_string();
   12.63            tty->print("transitive overriding superclass %s with %s::%s index %d, original flags: ",
   12.64             supersuperklass->internal_name(),
   12.65 -           _klass->internal_name(), (target_method() != NULL) ?
   12.66 -           target_method()->name()->as_C_string() : "<NULL>", vtable_index);
   12.67 +           _klass->internal_name(), sig, vtable_index);
   12.68             super_method->access_flags().print_on(tty);
   12.69 +           if (super_method->is_default_method()) {
   12.70 +             tty->print("default");
   12.71 +           }
   12.72             tty->print("overriders flags: ");
   12.73             target_method->access_flags().print_on(tty);
   12.74 -           tty->cr();
   12.75 +           if (target_method->is_default_method()) {
   12.76 +             tty->print("default");
   12.77 +           }
   12.78          }
   12.79  #endif /*PRODUCT*/
   12.80          break; // return found superk
   12.81 @@ -258,16 +291,31 @@
   12.82  // OR return true if a new vtable entry is required.
   12.83  // Only called for InstanceKlass's, i.e. not for arrays
   12.84  // If that changed, could not use _klass as handle for klass
   12.85 -bool klassVtable::update_inherited_vtable(InstanceKlass* klass, methodHandle target_method, int super_vtable_len,
   12.86 -                  bool checkconstraints, TRAPS) {
   12.87 +bool klassVtable::update_inherited_vtable(InstanceKlass* klass, methodHandle target_method,
   12.88 +                                          int super_vtable_len, int default_index,
   12.89 +                                          bool checkconstraints, TRAPS) {
   12.90    ResourceMark rm;
   12.91    bool allocate_new = true;
   12.92    assert(klass->oop_is_instance(), "must be InstanceKlass");
   12.93 -  assert(klass == target_method()->method_holder(), "caller resp.");
   12.94  
   12.95 -  // Initialize the method's vtable index to "nonvirtual".
   12.96 -  // If we allocate a vtable entry, we will update it to a non-negative number.
   12.97 -  target_method()->set_vtable_index(Method::nonvirtual_vtable_index);
   12.98 +  Array<int>* def_vtable_indices = NULL;
   12.99 +  bool is_default = false;
  12.100 +  // default methods are concrete methods in superinterfaces which are added to the vtable
  12.101 +  // with their real method_holder
  12.102 +  // Since vtable and itable indices share the same storage, don't touch
  12.103 +  // the default method's real vtable/itable index
  12.104 +  // default_vtable_indices stores the vtable value relative to this inheritor
  12.105 +  if (default_index >= 0 ) {
  12.106 +    is_default = true;
  12.107 +    def_vtable_indices = klass->default_vtable_indices();
  12.108 +    assert(def_vtable_indices != NULL, "def vtable alloc?");
  12.109 +    assert(default_index <= def_vtable_indices->length(), "def vtable len?");
  12.110 +  } else {
  12.111 +    assert(klass == target_method()->method_holder(), "caller resp.");
  12.112 +    // Initialize the method's vtable index to "nonvirtual".
  12.113 +    // If we allocate a vtable entry, we will update it to a non-negative number.
  12.114 +    target_method()->set_vtable_index(Method::nonvirtual_vtable_index);
  12.115 +  }
  12.116  
  12.117    // Static and <init> methods are never in
  12.118    if (target_method()->is_static() || target_method()->name() ==  vmSymbols::object_initializer_name()) {
  12.119 @@ -284,6 +332,8 @@
  12.120      // An interface never allocates new vtable slots, only inherits old ones.
  12.121      // This method will either be assigned its own itable index later,
  12.122      // or be assigned an inherited vtable index in the loop below.
  12.123 +    // default methods store their vtable indices in the inheritors default_vtable_indices
  12.124 +    assert (default_index == -1, "interfaces don't store resolved default methods");
  12.125      target_method()->set_vtable_index(Method::pending_itable_index);
  12.126    }
  12.127  
  12.128 @@ -307,8 +357,15 @@
  12.129  
  12.130    Symbol* name = target_method()->name();
  12.131    Symbol* signature = target_method()->signature();
  12.132 -  Handle target_loader(THREAD, _klass()->class_loader());
  12.133 -  Symbol*  target_classname = _klass->name();
  12.134 +
  12.135 +  KlassHandle target_klass(THREAD, target_method()->method_holder());
  12.136 +  if (target_klass == NULL) {
  12.137 +    target_klass = _klass;
  12.138 +  }
  12.139 +
  12.140 +  Handle target_loader(THREAD, target_klass->class_loader());
  12.141 +
  12.142 +  Symbol* target_classname = target_klass->name();
  12.143    for(int i = 0; i < super_vtable_len; i++) {
  12.144      Method* super_method = method_at(i);
  12.145      // Check if method name matches
  12.146 @@ -317,10 +374,14 @@
  12.147        // get super_klass for method_holder for the found method
  12.148        InstanceKlass* super_klass =  super_method->method_holder();
  12.149  
  12.150 -      if ((super_klass->is_override(super_method, target_loader, target_classname, THREAD)) ||
  12.151 -      ((klass->major_version() >= VTABLE_TRANSITIVE_OVERRIDE_VERSION)
  12.152 -        && ((super_klass = find_transitive_override(super_klass, target_method, i, target_loader,
  12.153 -             target_classname, THREAD)) != (InstanceKlass*)NULL))) {
  12.154 +      if (is_default
  12.155 +          || ((super_klass->is_override(super_method, target_loader, target_classname, THREAD))
  12.156 +          || ((klass->major_version() >= VTABLE_TRANSITIVE_OVERRIDE_VERSION)
  12.157 +          && ((super_klass = find_transitive_override(super_klass,
  12.158 +                             target_method, i, target_loader,
  12.159 +                             target_classname, THREAD))
  12.160 +                             != (InstanceKlass*)NULL))))
  12.161 +        {
  12.162          // overriding, so no new entry
  12.163          allocate_new = false;
  12.164  
  12.165 @@ -347,7 +408,7 @@
  12.166                  "%s used in the signature";
  12.167                char* sig = target_method()->name_and_sig_as_C_string();
  12.168                const char* loader1 = SystemDictionary::loader_name(target_loader());
  12.169 -              char* current = _klass->name()->as_C_string();
  12.170 +              char* current = target_klass->name()->as_C_string();
  12.171                const char* loader2 = SystemDictionary::loader_name(super_loader());
  12.172                char* failed_type_name = failed_type_symbol->as_C_string();
  12.173                size_t buflen = strlen(msg) + strlen(sig) + strlen(loader1) +
  12.174 @@ -360,16 +421,39 @@
  12.175            }
  12.176         }
  12.177  
  12.178 -        put_method_at(target_method(), i);
  12.179 -        target_method()->set_vtable_index(i);
  12.180 +       put_method_at(target_method(), i);
  12.181 +       if (!is_default) {
  12.182 +         target_method()->set_vtable_index(i);
  12.183 +       } else {
  12.184 +         if (def_vtable_indices != NULL) {
  12.185 +           def_vtable_indices->at_put(default_index, i);
  12.186 +         }
  12.187 +         assert(super_method->is_default_method() || super_method->is_overpass()
  12.188 +                || super_method->is_abstract(), "default override error");
  12.189 +       }
  12.190 +
  12.191 +
  12.192  #ifndef PRODUCT
  12.193          if (PrintVtables && Verbose) {
  12.194 +          ResourceMark rm(THREAD);
  12.195 +          char* sig = target_method()->name_and_sig_as_C_string();
  12.196            tty->print("overriding with %s::%s index %d, original flags: ",
  12.197 -           _klass->internal_name(), (target_method() != NULL) ?
  12.198 -           target_method()->name()->as_C_string() : "<NULL>", i);
  12.199 +           target_klass->internal_name(), sig, i);
  12.200             super_method->access_flags().print_on(tty);
  12.201 +           if (super_method->is_default_method()) {
  12.202 +             tty->print("default");
  12.203 +           }
  12.204 +           if (super_method->is_overpass()) {
  12.205 +             tty->print("overpass");
  12.206 +           }
  12.207             tty->print("overriders flags: ");
  12.208             target_method->access_flags().print_on(tty);
  12.209 +           if (target_method->is_default_method()) {
  12.210 +             tty->print("default");
  12.211 +           }
  12.212 +           if (target_method->is_overpass()) {
  12.213 +             tty->print("overpass");
  12.214 +           }
  12.215             tty->cr();
  12.216          }
  12.217  #endif /*PRODUCT*/
  12.218 @@ -378,12 +462,25 @@
  12.219          // but not override another. Once we override one, not need new
  12.220  #ifndef PRODUCT
  12.221          if (PrintVtables && Verbose) {
  12.222 +          ResourceMark rm(THREAD);
  12.223 +          char* sig = target_method()->name_and_sig_as_C_string();
  12.224            tty->print("NOT overriding with %s::%s index %d, original flags: ",
  12.225 -           _klass->internal_name(), (target_method() != NULL) ?
  12.226 -           target_method()->name()->as_C_string() : "<NULL>", i);
  12.227 +           target_klass->internal_name(), sig,i);
  12.228             super_method->access_flags().print_on(tty);
  12.229 +           if (super_method->is_default_method()) {
  12.230 +             tty->print("default");
  12.231 +           }
  12.232 +           if (super_method->is_overpass()) {
  12.233 +             tty->print("overpass");
  12.234 +           }
  12.235             tty->print("overriders flags: ");
  12.236             target_method->access_flags().print_on(tty);
  12.237 +           if (target_method->is_default_method()) {
  12.238 +             tty->print("default");
  12.239 +           }
  12.240 +           if (target_method->is_overpass()) {
  12.241 +             tty->print("overpass");
  12.242 +           }
  12.243             tty->cr();
  12.244          }
  12.245  #endif /*PRODUCT*/
  12.246 @@ -438,6 +535,14 @@
  12.247      return false;
  12.248    }
  12.249  
  12.250 +  // Concrete interface methods do not need new entries, they override
  12.251 +  // abstract method entries using default inheritance rules
  12.252 +  if (target_method()->method_holder() != NULL &&
  12.253 +      target_method()->method_holder()->is_interface()  &&
  12.254 +      !target_method()->is_abstract() ) {
  12.255 +    return false;
  12.256 +  }
  12.257 +
  12.258    // we need a new entry if there is no superclass
  12.259    if (super == NULL) {
  12.260      return true;
  12.261 @@ -446,7 +551,7 @@
  12.262    // private methods in classes always have a new entry in the vtable
  12.263    // specification interpretation since classic has
  12.264    // private methods not overriding
  12.265 -  // JDK8 adds private methods in interfaces which require invokespecial
  12.266 +  // JDK8 adds private  methods in interfaces which require invokespecial
  12.267    if (target_method()->is_private()) {
  12.268      return true;
  12.269    }
  12.270 @@ -526,35 +631,40 @@
  12.271    if (mhk->is_interface()) {
  12.272      assert(m->is_public(), "should be public");
  12.273      assert(ik()->implements_interface(method_holder) , "this class should implement the interface");
  12.274 -    assert(is_miranda(m, ik()->methods(), ik()->super()), "should be a miranda_method");
  12.275 +    assert(is_miranda(m, ik()->methods(), ik()->default_methods(), ik()->super()), "should be a miranda_method");
  12.276      return true;
  12.277    }
  12.278    return false;
  12.279  }
  12.280  
  12.281 -// check if a method is a miranda method, given a class's methods table and its super
  12.282 -// "miranda" means not static, not defined by this class, and not defined
  12.283 -// in super unless it is private and therefore inaccessible to this class.
  12.284 +// check if a method is a miranda method, given a class's methods table,
  12.285 +// its default_method table  and its super
  12.286 +// "miranda" means not static, not defined by this class.
  12.287 +// private methods in interfaces do not belong in the miranda list.
  12.288  // the caller must make sure that the method belongs to an interface implemented by the class
  12.289  // Miranda methods only include public interface instance methods
  12.290 -// Not private methods, not static methods, not default = concrete abstract
  12.291 -bool klassVtable::is_miranda(Method* m, Array<Method*>* class_methods, Klass* super) {
  12.292 -  if (m->is_static()) {
  12.293 +// Not private methods, not static methods, not default == concrete abstract
  12.294 +bool klassVtable::is_miranda(Method* m, Array<Method*>* class_methods,
  12.295 +                             Array<Method*>* default_methods, Klass* super) {
  12.296 +  if (m->is_static() || m->is_private()) {
  12.297      return false;
  12.298    }
  12.299    Symbol* name = m->name();
  12.300    Symbol* signature = m->signature();
  12.301    if (InstanceKlass::find_method(class_methods, name, signature) == NULL) {
  12.302      // did not find it in the method table of the current class
  12.303 -    if (super == NULL) {
  12.304 -      // super doesn't exist
  12.305 -      return true;
  12.306 -    }
  12.307 +    if ((default_methods == NULL) ||
  12.308 +        InstanceKlass::find_method(default_methods, name, signature) == NULL) {
  12.309 +      if (super == NULL) {
  12.310 +        // super doesn't exist
  12.311 +        return true;
  12.312 +      }
  12.313  
  12.314 -    Method* mo = InstanceKlass::cast(super)->lookup_method(name, signature);
  12.315 -    if (mo == NULL || mo->access_flags().is_private() ) {
  12.316 -      // super class hierarchy does not implement it or protection is different
  12.317 -      return true;
  12.318 +      Method* mo = InstanceKlass::cast(super)->lookup_method(name, signature);
  12.319 +      if (mo == NULL || mo->access_flags().is_private() ) {
  12.320 +        // super class hierarchy does not implement it or protection is different
  12.321 +        return true;
  12.322 +      }
  12.323      }
  12.324    }
  12.325  
  12.326 @@ -562,7 +672,7 @@
  12.327  }
  12.328  
  12.329  // Scans current_interface_methods for miranda methods that do not
  12.330 -// already appear in new_mirandas and are also not defined-and-non-private
  12.331 +// already appear in new_mirandas, or default methods,  and are also not defined-and-non-private
  12.332  // in super (superclass).  These mirandas are added to all_mirandas if it is
  12.333  // not null; in addition, those that are not duplicates of miranda methods
  12.334  // inherited by super from its interfaces are added to new_mirandas.
  12.335 @@ -572,7 +682,8 @@
  12.336  void klassVtable::add_new_mirandas_to_lists(
  12.337      GrowableArray<Method*>* new_mirandas, GrowableArray<Method*>* all_mirandas,
  12.338      Array<Method*>* current_interface_methods, Array<Method*>* class_methods,
  12.339 -    Klass* super) {
  12.340 +    Array<Method*>* default_methods, Klass* super) {
  12.341 +
  12.342    // iterate thru the current interface's method to see if it a miranda
  12.343    int num_methods = current_interface_methods->length();
  12.344    for (int i = 0; i < num_methods; i++) {
  12.345 @@ -590,7 +701,7 @@
  12.346      }
  12.347  
  12.348      if (!is_duplicate) { // we don't want duplicate miranda entries in the vtable
  12.349 -      if (is_miranda(im, class_methods, super)) { // is it a miranda at all?
  12.350 +      if (is_miranda(im, class_methods, default_methods, super)) { // is it a miranda at all?
  12.351          InstanceKlass *sk = InstanceKlass::cast(super);
  12.352          // check if it is a duplicate of a super's miranda
  12.353          if (sk->lookup_method_in_all_interfaces(im->name(), im->signature()) == NULL) {
  12.354 @@ -607,6 +718,7 @@
  12.355  void klassVtable::get_mirandas(GrowableArray<Method*>* new_mirandas,
  12.356                                 GrowableArray<Method*>* all_mirandas,
  12.357                                 Klass* super, Array<Method*>* class_methods,
  12.358 +                               Array<Method*>* default_methods,
  12.359                                 Array<Klass*>* local_interfaces) {
  12.360    assert((new_mirandas->length() == 0) , "current mirandas must be 0");
  12.361  
  12.362 @@ -615,14 +727,16 @@
  12.363    for (int i = 0; i < num_local_ifs; i++) {
  12.364      InstanceKlass *ik = InstanceKlass::cast(local_interfaces->at(i));
  12.365      add_new_mirandas_to_lists(new_mirandas, all_mirandas,
  12.366 -                              ik->methods(), class_methods, super);
  12.367 +                              ik->methods(), class_methods,
  12.368 +                              default_methods, super);
  12.369      // iterate thru each local's super interfaces
  12.370      Array<Klass*>* super_ifs = ik->transitive_interfaces();
  12.371      int num_super_ifs = super_ifs->length();
  12.372      for (int j = 0; j < num_super_ifs; j++) {
  12.373        InstanceKlass *sik = InstanceKlass::cast(super_ifs->at(j));
  12.374        add_new_mirandas_to_lists(new_mirandas, all_mirandas,
  12.375 -                                sik->methods(), class_methods, super);
  12.376 +                                sik->methods(), class_methods,
  12.377 +                                default_methods, super);
  12.378      }
  12.379    }
  12.380  }
  12.381 @@ -633,8 +747,22 @@
  12.382  int klassVtable::fill_in_mirandas(int initialized) {
  12.383    GrowableArray<Method*> mirandas(20);
  12.384    get_mirandas(&mirandas, NULL, ik()->super(), ik()->methods(),
  12.385 -               ik()->local_interfaces());
  12.386 +               ik()->default_methods(), ik()->local_interfaces());
  12.387    for (int i = 0; i < mirandas.length(); i++) {
  12.388 +    if (PrintVtables && Verbose) {
  12.389 +      Method* meth = mirandas.at(i);
  12.390 +      ResourceMark rm(Thread::current());
  12.391 +      if (meth != NULL) {
  12.392 +        char* sig = meth->name_and_sig_as_C_string();
  12.393 +        tty->print("fill in mirandas with %s index %d, flags: ",
  12.394 +          sig, initialized);
  12.395 +        meth->access_flags().print_on(tty);
  12.396 +        if (meth->is_default_method()) {
  12.397 +          tty->print("default");
  12.398 +        }
  12.399 +        tty->cr();
  12.400 +      }
  12.401 +    }
  12.402      put_method_at(mirandas.at(i), initialized);
  12.403      ++initialized;
  12.404    }
  12.405 @@ -648,6 +776,26 @@
  12.406  }
  12.407  
  12.408  #if INCLUDE_JVMTI
  12.409 +bool klassVtable::adjust_default_method(int vtable_index, Method* old_method, Method* new_method) {
  12.410 +  // If old_method is default, find this vtable index in default_vtable_indices
  12.411 +  // and replace that method in the _default_methods list
  12.412 +  bool updated = false;
  12.413 +
  12.414 +  Array<Method*>* default_methods = ik()->default_methods();
  12.415 +  if (default_methods != NULL) {
  12.416 +    int len = default_methods->length();
  12.417 +    for (int idx = 0; idx < len; idx++) {
  12.418 +      if (vtable_index == ik()->default_vtable_indices()->at(idx)) {
  12.419 +        if (default_methods->at(idx) == old_method) {
  12.420 +          default_methods->at_put(idx, new_method);
  12.421 +          updated = true;
  12.422 +        }
  12.423 +        break;
  12.424 +      }
  12.425 +    }
  12.426 +  }
  12.427 +  return updated;
  12.428 +}
  12.429  void klassVtable::adjust_method_entries(Method** old_methods, Method** new_methods,
  12.430                                          int methods_length, bool * trace_name_printed) {
  12.431    // search the vtable for uses of either obsolete or EMCP methods
  12.432 @@ -663,18 +811,26 @@
  12.433      for (int index = 0; index < length(); index++) {
  12.434        if (unchecked_method_at(index) == old_method) {
  12.435          put_method_at(new_method, index);
  12.436 +          // For default methods, need to update the _default_methods array
  12.437 +          // which can only have one method entry for a given signature
  12.438 +          bool updated_default = false;
  12.439 +          if (old_method->is_default_method()) {
  12.440 +            updated_default = adjust_default_method(index, old_method, new_method);
  12.441 +          }
  12.442  
  12.443          if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
  12.444            if (!(*trace_name_printed)) {
  12.445              // RC_TRACE_MESG macro has an embedded ResourceMark
  12.446 -            RC_TRACE_MESG(("adjust: name=%s",
  12.447 +            RC_TRACE_MESG(("adjust: klassname=%s for methods from name=%s",
  12.448 +                           klass()->external_name(),
  12.449                             old_method->method_holder()->external_name()));
  12.450              *trace_name_printed = true;
  12.451            }
  12.452            // RC_TRACE macro has an embedded ResourceMark
  12.453 -          RC_TRACE(0x00100000, ("vtable method update: %s(%s)",
  12.454 +          RC_TRACE(0x00100000, ("vtable method update: %s(%s), updated default = %s",
  12.455                                  new_method->name()->as_C_string(),
  12.456 -                                new_method->signature()->as_C_string()));
  12.457 +                                new_method->signature()->as_C_string(),
  12.458 +                                updated_default ? "true" : "false"));
  12.459          }
  12.460          // cannot 'break' here; see for-loop comment above.
  12.461        }
  12.462 @@ -701,6 +857,12 @@
  12.463      if (m != NULL) {
  12.464        tty->print("      (%5d)  ", i);
  12.465        m->access_flags().print_on(tty);
  12.466 +      if (m->is_default_method()) {
  12.467 +        tty->print("default");
  12.468 +      }
  12.469 +      if (m->is_overpass()) {
  12.470 +        tty->print("overpass");
  12.471 +      }
  12.472        tty->print(" --  ");
  12.473        m->print_name(tty);
  12.474        tty->cr();
  12.475 @@ -757,9 +919,9 @@
  12.476  // Initialization
  12.477  void klassItable::initialize_itable(bool checkconstraints, TRAPS) {
  12.478    if (_klass->is_interface()) {
  12.479 -    // This needs to go after vtable indexes are assigned but
  12.480 -    // before implementors need to know the number of itable indexes.
  12.481 -    assign_itable_indexes_for_interface(_klass());
  12.482 +    // This needs to go after vtable indices are assigned but
  12.483 +    // before implementors need to know the number of itable indices.
  12.484 +    assign_itable_indices_for_interface(_klass());
  12.485    }
  12.486  
  12.487    // Cannot be setup doing bootstrapping, interfaces don't have
  12.488 @@ -803,7 +965,7 @@
  12.489    return true;
  12.490  }
  12.491  
  12.492 -int klassItable::assign_itable_indexes_for_interface(Klass* klass) {
  12.493 +int klassItable::assign_itable_indices_for_interface(Klass* klass) {
  12.494    // an interface does not have an itable, but its methods need to be numbered
  12.495    if (TraceItables) tty->print_cr("%3d: Initializing itable for interface %s", ++initialize_count,
  12.496                                    klass->name()->as_C_string());
  12.497 @@ -846,7 +1008,7 @@
  12.498      }
  12.499      nof_methods -= 1;
  12.500    }
  12.501 -  // no methods have itable indexes
  12.502 +  // no methods have itable indices
  12.503    return 0;
  12.504  }
  12.505  
  12.506 @@ -907,6 +1069,21 @@
  12.507        int ime_num = m->itable_index();
  12.508        assert(ime_num < ime_count, "oob");
  12.509        itableOffsetEntry::method_entry(_klass(), method_table_offset)[ime_num].initialize(target());
  12.510 +      if (TraceItables && Verbose) {
  12.511 +        ResourceMark rm(THREAD);
  12.512 +        if (target() != NULL) {
  12.513 +          char* sig = target()->name_and_sig_as_C_string();
  12.514 +          tty->print("interface: %s, ime_num: %d, target: %s, method_holder: %s ",
  12.515 +                    interf_h()->internal_name(), ime_num, sig,
  12.516 +                    target()->method_holder()->internal_name());
  12.517 +          tty->print("target_method flags: ");
  12.518 +          target()->access_flags().print_on(tty);
  12.519 +          if (target()->is_default_method()) {
  12.520 +            tty->print("default");
  12.521 +          }
  12.522 +          tty->cr();
  12.523 +        }
  12.524 +      }
  12.525      }
  12.526    }
  12.527  }
  12.528 @@ -980,6 +1157,9 @@
  12.529      if (m != NULL) {
  12.530        tty->print("      (%5d)  ", i);
  12.531        m->access_flags().print_on(tty);
  12.532 +      if (m->is_default_method()) {
  12.533 +        tty->print("default");
  12.534 +      }
  12.535        tty->print(" --  ");
  12.536        m->print_name(tty);
  12.537        tty->cr();
  12.538 @@ -1116,7 +1296,7 @@
  12.539    Array<Method*>* methods = InstanceKlass::cast(intf)->methods();
  12.540  
  12.541    if (itable_index < 0 || itable_index >= method_count_for_interface(intf))
  12.542 -    return NULL;                // help caller defend against bad indexes
  12.543 +    return NULL;                // help caller defend against bad indices
  12.544  
  12.545    int index = itable_index;
  12.546    Method* m = methods->at(index);
    13.1 --- a/src/share/vm/oops/klassVtable.hpp	Wed Oct 09 21:45:28 2013 -0400
    13.2 +++ b/src/share/vm/oops/klassVtable.hpp	Wed Oct 09 22:01:59 2013 -0400
    13.3 @@ -97,6 +97,7 @@
    13.4    // trace_name_printed is set to true if the current call has
    13.5    // printed the klass name so that other routines in the adjust_*
    13.6    // group don't print the klass name.
    13.7 +  bool adjust_default_method(int vtable_index, Method* old_method, Method* new_method);
    13.8    void adjust_method_entries(Method** old_methods, Method** new_methods,
    13.9                               int methods_length, bool * trace_name_printed);
   13.10    bool check_no_old_or_obsolete_entries();
   13.11 @@ -118,24 +119,28 @@
   13.12    void put_method_at(Method* m, int index);
   13.13    static bool needs_new_vtable_entry(methodHandle m, Klass* super, Handle classloader, Symbol* classname, AccessFlags access_flags, TRAPS);
   13.14  
   13.15 -  bool update_inherited_vtable(InstanceKlass* klass, methodHandle target_method, int super_vtable_len, bool checkconstraints, TRAPS);
   13.16 +  bool update_inherited_vtable(InstanceKlass* klass, methodHandle target_method, int super_vtable_len, int default_index, bool checkconstraints, TRAPS);
   13.17   InstanceKlass* find_transitive_override(InstanceKlass* initialsuper, methodHandle target_method, int vtable_index,
   13.18                                           Handle target_loader, Symbol* target_classname, Thread* THREAD);
   13.19  
   13.20    // support for miranda methods
   13.21    bool is_miranda_entry_at(int i);
   13.22    int fill_in_mirandas(int initialized);
   13.23 -  static bool is_miranda(Method* m, Array<Method*>* class_methods, Klass* super);
   13.24 +  static bool is_miranda(Method* m, Array<Method*>* class_methods,
   13.25 +                         Array<Method*>* default_methods, Klass* super);
   13.26    static void add_new_mirandas_to_lists(
   13.27        GrowableArray<Method*>* new_mirandas,
   13.28        GrowableArray<Method*>* all_mirandas,
   13.29 -      Array<Method*>* current_interface_methods, Array<Method*>* class_methods,
   13.30 +      Array<Method*>* current_interface_methods,
   13.31 +      Array<Method*>* class_methods,
   13.32 +      Array<Method*>* default_methods,
   13.33        Klass* super);
   13.34    static void get_mirandas(
   13.35        GrowableArray<Method*>* new_mirandas,
   13.36        GrowableArray<Method*>* all_mirandas, Klass* super,
   13.37 -      Array<Method*>* class_methods, Array<Klass*>* local_interfaces);
   13.38 -
   13.39 +      Array<Method*>* class_methods,
   13.40 +      Array<Method*>* default_methods,
   13.41 +      Array<Klass*>* local_interfaces);
   13.42    void verify_against(outputStream* st, klassVtable* vt, int index);
   13.43    inline InstanceKlass* ik() const;
   13.44  };
   13.45 @@ -290,7 +295,7 @@
   13.46  #endif // INCLUDE_JVMTI
   13.47  
   13.48    // Setup of itable
   13.49 -  static int assign_itable_indexes_for_interface(Klass* klass);
   13.50 +  static int assign_itable_indices_for_interface(Klass* klass);
   13.51    static int method_count_for_interface(Klass* klass);
   13.52    static int compute_itable_size(Array<Klass*>* transitive_interfaces);
   13.53    static void setup_itable_offset_table(instanceKlassHandle klass);
    14.1 --- a/src/share/vm/oops/method.cpp	Wed Oct 09 21:45:28 2013 -0400
    14.2 +++ b/src/share/vm/oops/method.cpp	Wed Oct 09 22:01:59 2013 -0400
    14.3 @@ -511,9 +511,9 @@
    14.4  
    14.5  bool Method::is_final_method(AccessFlags class_access_flags) const {
    14.6    // or "does_not_require_vtable_entry"
    14.7 -  // overpass can occur, is not final (reuses vtable entry)
    14.8 +  // default method or overpass can occur, is not final (reuses vtable entry)
    14.9    // private methods get vtable entries for backward class compatibility.
   14.10 -  if (is_overpass())  return false;
   14.11 +  if (is_overpass() || is_default_method())  return false;
   14.12    return is_final() || class_access_flags.is_final();
   14.13  }
   14.14  
   14.15 @@ -521,11 +521,24 @@
   14.16    return is_final_method(method_holder()->access_flags());
   14.17  }
   14.18  
   14.19 +bool Method::is_default_method() const {
   14.20 +  if (method_holder() != NULL &&
   14.21 +      method_holder()->is_interface() &&
   14.22 +      !is_abstract()) {
   14.23 +    return true;
   14.24 +  } else {
   14.25 +    return false;
   14.26 +  }
   14.27 +}
   14.28 +
   14.29  bool Method::can_be_statically_bound(AccessFlags class_access_flags) const {
   14.30    if (is_final_method(class_access_flags))  return true;
   14.31  #ifdef ASSERT
   14.32 +  ResourceMark rm;
   14.33    bool is_nonv = (vtable_index() == nonvirtual_vtable_index);
   14.34 -  if (class_access_flags.is_interface())  assert(is_nonv == is_static(), err_msg("is_nonv=%s", is_nonv));
   14.35 +  if (class_access_flags.is_interface()) {
   14.36 +      assert(is_nonv == is_static(), err_msg("is_nonv=%s", name_and_sig_as_C_string()));
   14.37 +  }
   14.38  #endif
   14.39    assert(valid_vtable_index() || valid_itable_index(), "method must be linked before we ask this question");
   14.40    return vtable_index() == nonvirtual_vtable_index;
   14.41 @@ -1371,7 +1384,8 @@
   14.42  }
   14.43  
   14.44  // This is only done during class loading, so it is OK to assume method_idnum matches the methods() array
   14.45 -void Method::sort_methods(Array<Method*>* methods, bool idempotent) {
   14.46 +// default_methods also uses this without the ordering for fast find_method
   14.47 +void Method::sort_methods(Array<Method*>* methods, bool idempotent, bool set_idnums) {
   14.48    int length = methods->length();
   14.49    if (length > 1) {
   14.50      {
   14.51 @@ -1379,14 +1393,15 @@
   14.52        QuickSort::sort<Method*>(methods->data(), length, method_comparator, idempotent);
   14.53      }
   14.54      // Reset method ordering
   14.55 -    for (int i = 0; i < length; i++) {
   14.56 -      Method* m = methods->at(i);
   14.57 -      m->set_method_idnum(i);
   14.58 +    if (set_idnums) {
   14.59 +      for (int i = 0; i < length; i++) {
   14.60 +        Method* m = methods->at(i);
   14.61 +        m->set_method_idnum(i);
   14.62 +      }
   14.63      }
   14.64    }
   14.65  }
   14.66  
   14.67 -
   14.68  //-----------------------------------------------------------------------------------
   14.69  // Non-product code unless JVM/TI needs it
   14.70  
    15.1 --- a/src/share/vm/oops/method.hpp	Wed Oct 09 21:45:28 2013 -0400
    15.2 +++ b/src/share/vm/oops/method.hpp	Wed Oct 09 22:01:59 2013 -0400
    15.3 @@ -567,6 +567,7 @@
    15.4    // checks method and its method holder
    15.5    bool is_final_method() const;
    15.6    bool is_final_method(AccessFlags class_access_flags) const;
    15.7 +  bool is_default_method() const;
    15.8  
    15.9    // true if method needs no dynamic dispatch (final and/or no vtable entry)
   15.10    bool can_be_statically_bound() const;
   15.11 @@ -846,7 +847,7 @@
   15.12  #endif
   15.13  
   15.14    // Helper routine used for method sorting
   15.15 -  static void sort_methods(Array<Method*>* methods, bool idempotent = false);
   15.16 +  static void sort_methods(Array<Method*>* methods, bool idempotent = false, bool set_idnums = true);
   15.17  
   15.18    // Deallocation function for redefine classes or if an error occurs
   15.19    void deallocate_contents(ClassLoaderData* loader_data);
    16.1 --- a/src/share/vm/prims/jni.cpp	Wed Oct 09 21:45:28 2013 -0400
    16.2 +++ b/src/share/vm/prims/jni.cpp	Wed Oct 09 22:01:59 2013 -0400
    16.3 @@ -1591,10 +1591,8 @@
    16.4      }
    16.5    } else {
    16.6      m = klass->lookup_method(name, signature);
    16.7 -    // Look up interfaces
    16.8 -    if (m == NULL && klass->oop_is_instance()) {
    16.9 -      m = InstanceKlass::cast(klass())->lookup_method_in_all_interfaces(name,
   16.10 -                                                                   signature);
   16.11 +    if (m == NULL &&  klass->oop_is_instance()) {
   16.12 +      m = InstanceKlass::cast(klass())->lookup_method_in_ordered_interfaces(name, signature);
   16.13      }
   16.14    }
   16.15    if (m == NULL || (m->is_static() != is_static)) {
    17.1 --- a/src/share/vm/prims/jvm.cpp	Wed Oct 09 21:45:28 2013 -0400
    17.2 +++ b/src/share/vm/prims/jvm.cpp	Wed Oct 09 22:01:59 2013 -0400
    17.3 @@ -668,13 +668,12 @@
    17.4  JVM_ENTRY(jclass, JVM_GetCallerClass(JNIEnv* env, int depth))
    17.5    JVMWrapper("JVM_GetCallerClass");
    17.6  
    17.7 -  // Pre-JDK 8 and early builds of JDK 8 don't have a CallerSensitive annotation.
    17.8 -  if (SystemDictionary::reflect_CallerSensitive_klass() == NULL) {
    17.9 +  // Pre-JDK 8 and early builds of JDK 8 don't have a CallerSensitive annotation; or
   17.10 +  // sun.reflect.Reflection.getCallerClass with a depth parameter is provided
   17.11 +  // temporarily for existing code to use until a replacement API is defined.
   17.12 +  if (SystemDictionary::reflect_CallerSensitive_klass() == NULL || depth != JVM_CALLER_DEPTH) {
   17.13      Klass* k = thread->security_get_caller_class(depth);
   17.14      return (k == NULL) ? NULL : (jclass) JNIHandles::make_local(env, k->java_mirror());
   17.15 -  } else {
   17.16 -    // Basic handshaking with Java_sun_reflect_Reflection_getCallerClass
   17.17 -    assert(depth == -1, "wrong handshake depth");
   17.18    }
   17.19  
   17.20    // Getting the class of the caller frame.
    18.1 --- a/src/share/vm/prims/jvm.h	Wed Oct 09 21:45:28 2013 -0400
    18.2 +++ b/src/share/vm/prims/jvm.h	Wed Oct 09 22:01:59 2013 -0400
    18.3 @@ -374,6 +374,9 @@
    18.4  /*
    18.5   * java.lang.Class and java.lang.ClassLoader
    18.6   */
    18.7 +
    18.8 +#define JVM_CALLER_DEPTH -1
    18.9 +
   18.10  /*
   18.11   * Returns the class in which the code invoking the native method
   18.12   * belongs.
    19.1 --- a/src/share/vm/prims/jvmtiRedefineClasses.cpp	Wed Oct 09 21:45:28 2013 -0400
    19.2 +++ b/src/share/vm/prims/jvmtiRedefineClasses.cpp	Wed Oct 09 22:01:59 2013 -0400
    19.3 @@ -2755,13 +2755,26 @@
    19.4      // InstanceKlass around to hold obsolete methods so we don't have
    19.5      // any other InstanceKlass embedded vtables to update. The vtable
    19.6      // holds the Method*s for virtual (but not final) methods.
    19.7 -    if (ik->vtable_length() > 0 && ik->is_subtype_of(_the_class_oop)) {
    19.8 +    // Default methods, or concrete methods in interfaces are stored
    19.9 +    // in the vtable, so if an interface changes we need to check
   19.10 +    // adjust_method_entries() for every InstanceKlass, which will also
   19.11 +    // adjust the default method vtable indices.
   19.12 +    // We also need to adjust any default method entries that are
   19.13 +    // not yet in the vtable, because the vtable setup is in progress.
   19.14 +    // This must be done after we adjust the default_methods and
   19.15 +    // default_vtable_indices for methods already in the vtable.
   19.16 +    if (ik->vtable_length() > 0 && (_the_class_oop->is_interface()
   19.17 +        || ik->is_subtype_of(_the_class_oop))) {
   19.18        // ik->vtable() creates a wrapper object; rm cleans it up
   19.19        ResourceMark rm(_thread);
   19.20        ik->vtable()->adjust_method_entries(_matching_old_methods,
   19.21                                            _matching_new_methods,
   19.22                                            _matching_methods_length,
   19.23                                            &trace_name_printed);
   19.24 +      ik->adjust_default_methods(_matching_old_methods,
   19.25 +                                 _matching_new_methods,
   19.26 +                                 _matching_methods_length,
   19.27 +                                 &trace_name_printed);
   19.28      }
   19.29  
   19.30      // If the current class has an itable and we are either redefining an
    20.1 --- a/src/share/vm/prims/methodHandles.cpp	Wed Oct 09 21:45:28 2013 -0400
    20.2 +++ b/src/share/vm/prims/methodHandles.cpp	Wed Oct 09 22:01:59 2013 -0400
    20.3 @@ -187,12 +187,34 @@
    20.4      receiver_limit = m->method_holder();
    20.5      assert(receiver_limit->verify_itable_index(vmindex), "");
    20.6      flags |= IS_METHOD | (JVM_REF_invokeInterface << REFERENCE_KIND_SHIFT);
    20.7 +    if (TraceInvokeDynamic) {
    20.8 +      ResourceMark rm;
    20.9 +      tty->print_cr("memberName: invokeinterface method_holder::method: %s, receiver: %s, itableindex: %d, access_flags:",
   20.10 +            Method::name_and_sig_as_C_string(receiver_limit(), m->name(), m->signature()),
   20.11 +            receiver_limit()->internal_name(), vmindex);
   20.12 +       m->access_flags().print_on(tty);
   20.13 +       if (!m->is_abstract()) {
   20.14 +         tty->print("default");
   20.15 +       }
   20.16 +       tty->cr();
   20.17 +    }
   20.18      break;
   20.19  
   20.20    case CallInfo::vtable_call:
   20.21      vmindex = info.vtable_index();
   20.22      flags |= IS_METHOD | (JVM_REF_invokeVirtual << REFERENCE_KIND_SHIFT);
   20.23      assert(receiver_limit->is_subtype_of(m->method_holder()), "virtual call must be type-safe");
   20.24 +    if (TraceInvokeDynamic) {
   20.25 +      ResourceMark rm;
   20.26 +      tty->print_cr("memberName: invokevirtual method_holder::method: %s, receiver: %s, vtableindex: %d, access_flags:",
   20.27 +            Method::name_and_sig_as_C_string(receiver_limit(), m->name(), m->signature()),
   20.28 +            receiver_limit()->internal_name(), vmindex);
   20.29 +       m->access_flags().print_on(tty);
   20.30 +       if (m->is_default_method()) {
   20.31 +         tty->print("default");
   20.32 +       }
   20.33 +       tty->cr();
   20.34 +    }
   20.35      break;
   20.36  
   20.37    case CallInfo::direct_call:
    21.1 --- a/src/share/vm/runtime/arguments.cpp	Wed Oct 09 21:45:28 2013 -0400
    21.2 +++ b/src/share/vm/runtime/arguments.cpp	Wed Oct 09 22:01:59 2013 -0400
    21.3 @@ -2045,6 +2045,9 @@
    21.4    status = status && verify_interval(StringTableSize, minimumStringTableSize,
    21.5      (max_uintx / StringTable::bucket_size()), "StringTable size");
    21.6  
    21.7 +  status = status && verify_interval(SymbolTableSize, minimumSymbolTableSize,
    21.8 +    (max_uintx / SymbolTable::bucket_size()), "SymbolTable size");
    21.9 +
   21.10    if (MinHeapFreeRatio > MaxHeapFreeRatio) {
   21.11      jio_fprintf(defaultStream::error_stream(),
   21.12                  "MinHeapFreeRatio (" UINTX_FORMAT ") must be less than or "
    22.1 --- a/src/share/vm/runtime/globals.hpp	Wed Oct 09 21:45:28 2013 -0400
    22.2 +++ b/src/share/vm/runtime/globals.hpp	Wed Oct 09 22:01:59 2013 -0400
    22.3 @@ -3727,6 +3727,9 @@
    22.4    product(uintx, StringTableSize, defaultStringTableSize,                   \
    22.5            "Number of buckets in the interned String table")                 \
    22.6                                                                              \
    22.7 +  experimental(uintx, SymbolTableSize, defaultSymbolTableSize,              \
    22.8 +          "Number of buckets in the JVM internal Symbol table")             \
    22.9 +                                                                            \
   22.10    develop(bool, TraceDefaultMethods, false,                                 \
   22.11            "Trace the default method processing steps")                      \
   22.12                                                                              \
    23.1 --- a/src/share/vm/runtime/reflectionUtils.cpp	Wed Oct 09 21:45:28 2013 -0400
    23.2 +++ b/src/share/vm/runtime/reflectionUtils.cpp	Wed Oct 09 22:01:59 2013 -0400
    23.3 @@ -1,5 +1,5 @@
    23.4  /*
    23.5 - * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
    23.6 + * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
    23.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    23.8   *
    23.9   * This code is free software; you can redistribute it and/or modify it
   23.10 @@ -27,8 +27,11 @@
   23.11  #include "memory/universe.inline.hpp"
   23.12  #include "runtime/reflectionUtils.hpp"
   23.13  
   23.14 -KlassStream::KlassStream(instanceKlassHandle klass, bool local_only, bool classes_only) {
   23.15 -  _klass = klass;
   23.16 +KlassStream::KlassStream(instanceKlassHandle klass, bool local_only,
   23.17 +                         bool classes_only, bool walk_defaults) {
   23.18 +  _klass = _base_klass = klass;
   23.19 +  _base_class_search_defaults = false;
   23.20 +  _defaults_checked = false;
   23.21    if (classes_only) {
   23.22      _interfaces = Universe::the_empty_klass_array();
   23.23    } else {
   23.24 @@ -37,6 +40,7 @@
   23.25    _interface_index = _interfaces->length();
   23.26    _local_only = local_only;
   23.27    _classes_only = classes_only;
   23.28 +  _walk_defaults = walk_defaults;
   23.29  }
   23.30  
   23.31  bool KlassStream::eos() {
   23.32 @@ -45,7 +49,13 @@
   23.33    if (!_klass->is_interface() && _klass->super() != NULL) {
   23.34      // go up superclass chain (not for interfaces)
   23.35      _klass = _klass->super();
   23.36 +  // Next for method walks, walk default methods
   23.37 +  } else if (_walk_defaults && (_defaults_checked == false)  && (_base_klass->default_methods() != NULL)) {
   23.38 +      _base_class_search_defaults = true;
   23.39 +      _klass = _base_klass;
   23.40 +      _defaults_checked = true;
   23.41    } else {
   23.42 +    // Next walk transitive interfaces
   23.43      if (_interface_index > 0) {
   23.44        _klass = _interfaces->at(--_interface_index);
   23.45      } else {
    24.1 --- a/src/share/vm/runtime/reflectionUtils.hpp	Wed Oct 09 21:45:28 2013 -0400
    24.2 +++ b/src/share/vm/runtime/reflectionUtils.hpp	Wed Oct 09 22:01:59 2013 -0400
    24.3 @@ -38,7 +38,7 @@
    24.4  // and (super)interfaces. Streaming is done in reverse order (subclasses first,
    24.5  // interfaces last).
    24.6  //
    24.7 -//    for (KlassStream st(k, false, false); !st.eos(); st.next()) {
    24.8 +//    for (KlassStream st(k, false, false, false); !st.eos(); st.next()) {
    24.9  //      Klass* k = st.klass();
   24.10  //      ...
   24.11  //    }
   24.12 @@ -46,17 +46,21 @@
   24.13  class KlassStream VALUE_OBJ_CLASS_SPEC {
   24.14   protected:
   24.15    instanceKlassHandle _klass;           // current klass/interface iterated over
   24.16 -  Array<Klass*>*    _interfaces;      // transitive interfaces for initial class
   24.17 +  instanceKlassHandle _base_klass;      // initial klass/interface to iterate over
   24.18 +  Array<Klass*>*      _interfaces;      // transitive interfaces for initial class
   24.19    int                 _interface_index; // current interface being processed
   24.20    bool                _local_only;      // process initial class/interface only
   24.21    bool                _classes_only;    // process classes only (no interfaces)
   24.22 +  bool                _walk_defaults;   // process default methods
   24.23 +  bool                _base_class_search_defaults; // time to process default methods
   24.24 +  bool                _defaults_checked; // already checked for default methods
   24.25    int                 _index;
   24.26  
   24.27 -  virtual int length() const = 0;
   24.28 +  virtual int length() = 0;
   24.29  
   24.30   public:
   24.31    // constructor
   24.32 -  KlassStream(instanceKlassHandle klass, bool local_only, bool classes_only);
   24.33 +  KlassStream(instanceKlassHandle klass, bool local_only, bool classes_only, bool walk_defaults);
   24.34  
   24.35    // testing
   24.36    bool eos();
   24.37 @@ -67,6 +71,8 @@
   24.38    // accessors
   24.39    instanceKlassHandle klass() const { return _klass; }
   24.40    int index() const                 { return _index; }
   24.41 +  bool base_class_search_defaults() const { return _base_class_search_defaults; }
   24.42 +  void base_class_search_defaults(bool b) { _base_class_search_defaults = b; }
   24.43  };
   24.44  
   24.45  
   24.46 @@ -81,17 +87,24 @@
   24.47  
   24.48  class MethodStream : public KlassStream {
   24.49   private:
   24.50 -  int length() const          { return methods()->length(); }
   24.51 -  Array<Method*>* methods() const { return _klass->methods(); }
   24.52 +  int length()                    { return methods()->length(); }
   24.53 +  Array<Method*>* methods() {
   24.54 +    if (base_class_search_defaults()) {
   24.55 +      base_class_search_defaults(false);
   24.56 +      return _klass->default_methods();
   24.57 +    } else {
   24.58 +      return _klass->methods();
   24.59 +    }
   24.60 +  }
   24.61   public:
   24.62    MethodStream(instanceKlassHandle klass, bool local_only, bool classes_only)
   24.63 -    : KlassStream(klass, local_only, classes_only) {
   24.64 +    : KlassStream(klass, local_only, classes_only, true) {
   24.65      _index = length();
   24.66      next();
   24.67    }
   24.68  
   24.69    void next() { _index--; }
   24.70 -  Method* method() const { return methods()->at(index()); }
   24.71 +  Method* method() { return methods()->at(index()); }
   24.72  };
   24.73  
   24.74  
   24.75 @@ -107,13 +120,13 @@
   24.76  
   24.77  class FieldStream : public KlassStream {
   24.78   private:
   24.79 -  int length() const                { return _klass->java_fields_count(); }
   24.80 +  int length() { return _klass->java_fields_count(); }
   24.81  
   24.82    fieldDescriptor _fd_buf;
   24.83  
   24.84   public:
   24.85    FieldStream(instanceKlassHandle klass, bool local_only, bool classes_only)
   24.86 -    : KlassStream(klass, local_only, classes_only) {
   24.87 +    : KlassStream(klass, local_only, classes_only, false) {
   24.88      _index = length();
   24.89      next();
   24.90    }
    25.1 --- a/src/share/vm/runtime/vmStructs.cpp	Wed Oct 09 21:45:28 2013 -0400
    25.2 +++ b/src/share/vm/runtime/vmStructs.cpp	Wed Oct 09 22:01:59 2013 -0400
    25.3 @@ -27,7 +27,6 @@
    25.4  #include "classfile/javaClasses.hpp"
    25.5  #include "classfile/loaderConstraints.hpp"
    25.6  #include "classfile/placeholders.hpp"
    25.7 -#include "classfile/symbolTable.hpp"
    25.8  #include "classfile/systemDictionary.hpp"
    25.9  #include "ci/ciField.hpp"
   25.10  #include "ci/ciInstance.hpp"
   25.11 @@ -289,6 +288,7 @@
   25.12    nonstatic_field(ConstantPoolCache,    _constant_pool,                                ConstantPool*)                         \
   25.13    nonstatic_field(InstanceKlass,               _array_klasses,                                Klass*)                                \
   25.14    nonstatic_field(InstanceKlass,               _methods,                                      Array<Method*>*)                       \
   25.15 +  nonstatic_field(InstanceKlass,               _default_methods,                              Array<Method*>*)                       \
   25.16    nonstatic_field(InstanceKlass,               _local_interfaces,                             Array<Klass*>*)                        \
   25.17    nonstatic_field(InstanceKlass,               _transitive_interfaces,                        Array<Klass*>*)                        \
   25.18    nonstatic_field(InstanceKlass,               _fields,                                       Array<u2>*)                            \
   25.19 @@ -323,6 +323,7 @@
   25.20    nonstatic_field(nmethodBucket,               _count,                                        int)                                   \
   25.21    nonstatic_field(nmethodBucket,               _next,                                         nmethodBucket*)                        \
   25.22    nonstatic_field(InstanceKlass,               _method_ordering,                              Array<int>*)                           \
   25.23 +  nonstatic_field(InstanceKlass,               _default_vtable_indices,                       Array<int>*)                           \
   25.24    nonstatic_field(Klass,                       _super_check_offset,                           juint)                                 \
   25.25    nonstatic_field(Klass,                       _secondary_super_cache,                        Klass*)                                \
   25.26    nonstatic_field(Klass,                       _secondary_supers,                             Array<Klass*>*)                        \
   25.27 @@ -2247,12 +2248,6 @@
   25.28    declare_preprocessor_constant("PERFDATA_BIG_ENDIAN", PERFDATA_BIG_ENDIAN)       \
   25.29    declare_preprocessor_constant("PERFDATA_LITTLE_ENDIAN", PERFDATA_LITTLE_ENDIAN) \
   25.30                                                                            \
   25.31 -  /***************/                                                       \
   25.32 -  /* SymbolTable */                                                       \
   25.33 -  /***************/                                                       \
   25.34 -                                                                          \
   25.35 -  declare_constant(SymbolTable::symbol_table_size)                        \
   25.36 -                                                                          \
   25.37    /***********************************/                                   \
   25.38    /* LoaderConstraintTable constants */                                   \
   25.39    /***********************************/                                   \
    26.1 --- a/src/share/vm/utilities/globalDefinitions.hpp	Wed Oct 09 21:45:28 2013 -0400
    26.2 +++ b/src/share/vm/utilities/globalDefinitions.hpp	Wed Oct 09 22:01:59 2013 -0400
    26.3 @@ -333,6 +333,9 @@
    26.4  const int defaultStringTableSize = NOT_LP64(1009) LP64_ONLY(60013);
    26.5  const int minimumStringTableSize=1009;
    26.6  
    26.7 +const int defaultSymbolTableSize = 20011;
    26.8 +const int minimumSymbolTableSize = 1009;
    26.9 +
   26.10  
   26.11  //----------------------------------------------------------------------------------------------------
   26.12  // HotSwap - for JVMTI   aka Class File Replacement and PopFrame

mercurial