src/share/vm/oops/klassVtable.cpp

changeset 8716
619700f41f8e
parent 8509
cb4af293fe70
child 8856
ac27a9c85bea
child 8997
f8a45a60bc6b
     1.1 --- a/src/share/vm/oops/klassVtable.cpp	Fri Jan 20 16:22:39 2017 +0000
     1.2 +++ b/src/share/vm/oops/klassVtable.cpp	Thu Feb 02 00:29:28 2017 +0000
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 - * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
     1.6 + * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
     1.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8   *
     1.9   * This code is free software; you can redistribute it and/or modify it
    1.10 @@ -696,7 +696,7 @@
    1.11    // this check for all access permissions.
    1.12    InstanceKlass *sk = InstanceKlass::cast(super);
    1.13    if (sk->has_miranda_methods()) {
    1.14 -    if (sk->lookup_method_in_all_interfaces(name, signature, Klass::normal) != NULL) {
    1.15 +    if (sk->lookup_method_in_all_interfaces(name, signature, Klass::find_defaults) != NULL) {
    1.16        return false;  // found a matching miranda; we do not need a new entry
    1.17      }
    1.18    }
    1.19 @@ -729,7 +729,6 @@
    1.20    if (mhk->is_interface()) {
    1.21      assert(m->is_public(), "should be public");
    1.22      assert(ik()->implements_interface(method_holder) , "this class should implement the interface");
    1.23 -    // the search could find a miranda or a default method
    1.24      if (is_miranda(m, ik()->methods(), ik()->default_methods(), ik()->super())) {
    1.25        return true;
    1.26      }
    1.27 @@ -737,25 +736,57 @@
    1.28    return false;
    1.29  }
    1.30  
    1.31 -// check if a method is a miranda method, given a class's methods table,
    1.32 -// its default_method table  and its super
    1.33 -// Miranda methods are calculated twice:
    1.34 -// first: before vtable size calculation: including abstract and superinterface default
    1.35 +// Check if a method is a miranda method, given a class's methods array,
    1.36 +// its default_method table and its super class.
    1.37 +// "Miranda" means an abstract non-private method that would not be
    1.38 +// overridden for the local class.
    1.39 +// A "miranda" method should only include non-private interface
    1.40 +// instance methods, i.e. not private methods, not static methods,
    1.41 +// not default methods (concrete interface methods), not overpass methods.
    1.42 +// If a given class already has a local (including overpass) method, a
    1.43 +// default method, or any of its superclasses has the same which would have
    1.44 +// overridden an abstract method, then this is not a miranda method.
    1.45 +//
    1.46 +// Miranda methods are checked multiple times.
    1.47 +// Pass 1: during class load/class file parsing: before vtable size calculation:
    1.48 +// include superinterface abstract and default methods (non-private instance).
    1.49  // We include potential default methods to give them space in the vtable.
    1.50 -// During the first run, the default_methods list is empty
    1.51 -// This is seen by default method creation
    1.52 -// Second: recalculated during vtable initialization: only include abstract methods.
    1.53 +// During the first run, the current instanceKlass has not yet been
    1.54 +// created, the superclasses and superinterfaces do have instanceKlasses
    1.55 +// but may not have vtables, the default_methods list is empty, no overpasses.
    1.56 +// This is seen by default method creation.
    1.57 +//
    1.58 +// Pass 2: recalculated during vtable initialization: only include abstract methods.
    1.59 +// The goal of pass 2 is to walk through the superinterfaces to see if any of
    1.60 +// the superinterface methods (which were all abstract pre-default methods)
    1.61 +// need to be added to the vtable.
    1.62 +// With the addition of default methods, we have three new challenges:
    1.63 +// overpasses, static interface methods and private interface methods.
    1.64 +// Static and private interface methods do not get added to the vtable and
    1.65 +// are not seen by the method resolution process, so we skip those.
    1.66 +// Overpass methods are already in the vtable, so vtable lookup will
    1.67 +// find them and we don't need to add a miranda method to the end of
    1.68 +// the vtable. So we look for overpass methods and if they are found we
    1.69 +// return false. Note that we inherit our superclasses vtable, so
    1.70 +// the superclass' search also needs to use find_overpass so that if
    1.71 +// one is found we return false.
    1.72 +// False means - we don't need a miranda method added to the vtable.
    1.73 +//
    1.74  // During the second run, default_methods is set up, so concrete methods from
    1.75  // superinterfaces with matching names/signatures to default_methods are already
    1.76  // in the default_methods list and do not need to be appended to the vtable
    1.77 -// as mirandas
    1.78 -// This is seen by link resolution and selection.
    1.79 -// "miranda" means not static, not defined by this class.
    1.80 -// private methods in interfaces do not belong in the miranda list.
    1.81 -// the caller must make sure that the method belongs to an interface implemented by the class
    1.82 -// Miranda methods only include public interface instance methods
    1.83 -// Not private methods, not static methods, not default == concrete abstract
    1.84 -// Miranda methods also do not include overpass methods in interfaces
    1.85 +// as mirandas. Abstract methods may already have been handled via
    1.86 +// overpasses - either local or superclass overpasses, which may be
    1.87 +// in the vtable already.
    1.88 +//
    1.89 +// Pass 3: They are also checked by link resolution and selection,
    1.90 +// for invocation on a method (not interface method) reference that
    1.91 +// resolves to a method with an interface as its method_holder.
    1.92 +// Used as part of walking from the bottom of the vtable to find
    1.93 +// the vtable index for the miranda method.
    1.94 +//
    1.95 +// Part of the Miranda Rights in the US mean that if you do not have
    1.96 +// an attorney one will be appointed for you.
    1.97  bool klassVtable::is_miranda(Method* m, Array<Method*>* class_methods,
    1.98                               Array<Method*>* default_methods, Klass* super) {
    1.99    if (m->is_static() || m->is_private() || m->is_overpass()) {
   1.100 @@ -763,44 +794,36 @@
   1.101    }
   1.102    Symbol* name = m->name();
   1.103    Symbol* signature = m->signature();
   1.104 -  Method* mo;
   1.105  
   1.106 -  if ((mo = InstanceKlass::find_instance_method(class_methods, name, signature)) == NULL) {
   1.107 -    // did not find it in the method table of the current class
   1.108 -    if ((default_methods == NULL) ||
   1.109 -        InstanceKlass::find_method(default_methods, name, signature) == NULL) {
   1.110 -      if (super == NULL) {
   1.111 -        // super doesn't exist
   1.112 -        return true;
   1.113 -      }
   1.114 -
   1.115 -      mo = InstanceKlass::cast(super)->lookup_method(name, signature);
   1.116 -      while (mo != NULL && mo->access_flags().is_static()
   1.117 -             && mo->method_holder() != NULL
   1.118 -             && mo->method_holder()->super() != NULL)
   1.119 -      {
   1.120 -         mo = mo->method_holder()->super()->uncached_lookup_method(name, signature, Klass::normal);
   1.121 -      }
   1.122 -      if (mo == NULL || mo->access_flags().is_private() ) {
   1.123 -        // super class hierarchy does not implement it or protection is different
   1.124 -        return true;
   1.125 -      }
   1.126 -    }
   1.127 -  } else {
   1.128 -     // if the local class has a private method, the miranda will not
   1.129 -     // override it, so a vtable slot is needed
   1.130 -     if (mo->access_flags().is_private()) {
   1.131 -
   1.132 -       // Second round, weed out any superinterface methods that turned
   1.133 -       // into default methods, i.e. were concrete not abstract in the end
   1.134 -       if ((default_methods == NULL) ||
   1.135 -         InstanceKlass::find_method(default_methods, name, signature) == NULL) {
   1.136 -         return true;
   1.137 -       }
   1.138 -    }
   1.139 +  // First look in local methods to see if already covered
   1.140 +  if (InstanceKlass::find_local_method(class_methods, name, signature,
   1.141 +              Klass::find_overpass, Klass::skip_static, Klass::skip_private) != NULL)
   1.142 +  {
   1.143 +    return false;
   1.144    }
   1.145  
   1.146 -  return false;
   1.147 +  // Check local default methods
   1.148 +  if ((default_methods != NULL) &&
   1.149 +    (InstanceKlass::find_method(default_methods, name, signature) != NULL))
   1.150 +   {
   1.151 +     return false;
   1.152 +   }
   1.153 +
   1.154 +  InstanceKlass* cursuper;
   1.155 +  // Iterate on all superclasses, which should have instanceKlasses
   1.156 +  // Note that we explicitly look for overpasses at each level.
   1.157 +  // Overpasses may or may not exist for supers for pass 1,
   1.158 +  // they should have been created for pass 2 and later.
   1.159 +
   1.160 +  for (cursuper = InstanceKlass::cast(super); cursuper != NULL;  cursuper = (InstanceKlass*)cursuper->super())
   1.161 +  {
   1.162 +     if (cursuper->find_local_method(name, signature,
   1.163 +           Klass::find_overpass, Klass::skip_static, Klass::skip_private) != NULL) {
   1.164 +       return false;
   1.165 +     }
   1.166 +  }
   1.167 +
   1.168 +  return true;
   1.169  }
   1.170  
   1.171  // Scans current_interface_methods for miranda methods that do not
   1.172 @@ -836,7 +859,7 @@
   1.173        if (is_miranda(im, class_methods, default_methods, super)) { // is it a miranda at all?
   1.174          InstanceKlass *sk = InstanceKlass::cast(super);
   1.175          // check if it is a duplicate of a super's miranda
   1.176 -        if (sk->lookup_method_in_all_interfaces(im->name(), im->signature(), Klass::normal) == NULL) {
   1.177 +        if (sk->lookup_method_in_all_interfaces(im->name(), im->signature(), Klass::find_defaults) == NULL) {
   1.178            new_mirandas->append(im);
   1.179          }
   1.180          if (all_mirandas != NULL) {

mercurial