hotspot/src/share/vm/classfile/defaultMethods.cpp
author ehelin
Tue, 25 Feb 2014 11:02:11 +0100
changeset 22905 4b1549d69106
parent 22493 af3de4cee5e5
child 23999 22eb7be3d99d
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
     1
/*
22493
af3de4cee5e5 8031059: invokestatic: ICCE trying to invoke static method when it clashes with an abstract method inherited from an interface
hseigel
parents: 22233
diff changeset
     2
 * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
     4
 *
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
     8
 *
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    13
 * accompanied this code).
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    14
 *
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    18
 *
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    21
 * questions.
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    22
 *
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    23
 */
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    24
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    25
#include "precompiled.hpp"
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    26
#include "classfile/bytecodeAssembler.hpp"
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    27
#include "classfile/defaultMethods.hpp"
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    28
#include "classfile/symbolTable.hpp"
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    29
#include "memory/allocation.hpp"
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    30
#include "memory/metadataFactory.hpp"
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    31
#include "memory/resourceArea.hpp"
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    32
#include "runtime/signature.hpp"
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    33
#include "runtime/thread.hpp"
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    34
#include "oops/instanceKlass.hpp"
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    35
#include "oops/klass.hpp"
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    36
#include "oops/method.hpp"
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    37
#include "utilities/accessFlags.hpp"
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    38
#include "utilities/exceptions.hpp"
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    39
#include "utilities/ostream.hpp"
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    40
#include "utilities/pair.hpp"
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    41
#include "utilities/resourceHash.hpp"
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    42
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    43
typedef enum { QUALIFIED, DISQUALIFIED } QualifiedState;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    44
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    45
// Because we use an iterative algorithm when iterating over the type
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    46
// hierarchy, we can't use traditional scoped objects which automatically do
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    47
// cleanup in the destructor when the scope is exited.  PseudoScope (and
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    48
// PseudoScopeMark) provides a similar functionality, but for when you want a
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    49
// scoped object in non-stack memory (such as in resource memory, as we do
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    50
// here).  You've just got to remember to call 'destroy()' on the scope when
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    51
// leaving it (and marks have to be explicitly added).
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    52
class PseudoScopeMark : public ResourceObj {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    53
 public:
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    54
  virtual void destroy() = 0;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    55
};
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    56
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    57
class PseudoScope : public ResourceObj {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    58
 private:
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    59
  GrowableArray<PseudoScopeMark*> _marks;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    60
 public:
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    61
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    62
  static PseudoScope* cast(void* data) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    63
    return static_cast<PseudoScope*>(data);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    64
  }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    65
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    66
  void add_mark(PseudoScopeMark* psm) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    67
   _marks.append(psm);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    68
  }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    69
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    70
  void destroy() {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    71
    for (int i = 0; i < _marks.length(); ++i) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    72
      _marks.at(i)->destroy();
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    73
    }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    74
  }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    75
};
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    76
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    77
#ifndef PRODUCT
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    78
static void print_slot(outputStream* str, Symbol* name, Symbol* signature) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    79
  ResourceMark rm;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    80
  str->print("%s%s", name->as_C_string(), signature->as_C_string());
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    81
}
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    82
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    83
static void print_method(outputStream* str, Method* mo, bool with_class=true) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    84
  ResourceMark rm;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    85
  if (with_class) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    86
    str->print("%s.", mo->klass_name()->as_C_string());
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    87
  }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    88
  print_slot(str, mo->name(), mo->signature());
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    89
}
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    90
#endif // ndef PRODUCT
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    91
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    92
/**
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    93
 * Perform a depth-first iteration over the class hierarchy, applying
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    94
 * algorithmic logic as it goes.
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    95
 *
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    96
 * This class is one half of the inheritance hierarchy analysis mechanism.
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    97
 * It is meant to be used in conjunction with another class, the algorithm,
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    98
 * which is indicated by the ALGO template parameter.  This class can be
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    99
 * paired with any algorithm class that provides the required methods.
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   100
 *
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   101
 * This class contains all the mechanics for iterating over the class hierarchy
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   102
 * starting at a particular root, without recursing (thus limiting stack growth
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   103
 * from this point).  It visits each superclass (if present) and superinterface
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   104
 * in a depth-first manner, with callbacks to the ALGO class as each class is
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   105
 * encountered (visit()), The algorithm can cut-off further exploration of a
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   106
 * particular branch by returning 'false' from a visit() call.
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   107
 *
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   108
 * The ALGO class, must provide a visit() method, which each of which will be
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   109
 * called once for each node in the inheritance tree during the iteration.  In
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   110
 * addition, it can provide a memory block via new_node_data(InstanceKlass*),
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   111
 * which it can use for node-specific storage (and access via the
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   112
 * current_data() and data_at_depth(int) methods).
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   113
 *
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   114
 * Bare minimum needed to be an ALGO class:
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   115
 * class Algo : public HierarchyVisitor<Algo> {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   116
 *   void* new_node_data(InstanceKlass* cls) { return NULL; }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   117
 *   void free_node_data(void* data) { return; }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   118
 *   bool visit() { return true; }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   119
 * };
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   120
 */
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   121
template <class ALGO>
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   122
class HierarchyVisitor : StackObj {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   123
 private:
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   124
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   125
  class Node : public ResourceObj {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   126
   public:
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   127
    InstanceKlass* _class;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   128
    bool _super_was_visited;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   129
    int _interface_index;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   130
    void* _algorithm_data;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   131
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   132
    Node(InstanceKlass* cls, void* data, bool visit_super)
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   133
        : _class(cls), _super_was_visited(!visit_super),
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   134
          _interface_index(0), _algorithm_data(data) {}
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   135
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   136
    int number_of_interfaces() { return _class->local_interfaces()->length(); }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   137
    int interface_index() { return _interface_index; }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   138
    void set_super_visited() { _super_was_visited = true; }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   139
    void increment_visited_interface() { ++_interface_index; }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   140
    void set_all_interfaces_visited() {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   141
      _interface_index = number_of_interfaces();
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   142
    }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   143
    bool has_visited_super() { return _super_was_visited; }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   144
    bool has_visited_all_interfaces() {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   145
      return interface_index() >= number_of_interfaces();
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   146
    }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   147
    InstanceKlass* interface_at(int index) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   148
      return InstanceKlass::cast(_class->local_interfaces()->at(index));
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   149
    }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   150
    InstanceKlass* next_super() { return _class->java_super(); }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   151
    InstanceKlass* next_interface() {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   152
      return interface_at(interface_index());
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   153
    }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   154
  };
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   155
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   156
  bool _cancelled;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   157
  GrowableArray<Node*> _path;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   158
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   159
  Node* current_top() const { return _path.top(); }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   160
  bool has_more_nodes() const { return !_path.is_empty(); }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   161
  void push(InstanceKlass* cls, void* data) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   162
    assert(cls != NULL, "Requires a valid instance class");
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   163
    Node* node = new Node(cls, data, has_super(cls));
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   164
    _path.push(node);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   165
  }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   166
  void pop() { _path.pop(); }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   167
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   168
  void reset_iteration() {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   169
    _cancelled = false;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   170
    _path.clear();
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   171
  }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   172
  bool is_cancelled() const { return _cancelled; }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   173
21556
e75cd34a59e0 8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents: 21516
diff changeset
   174
  // This code used to skip interface classes because their only
e75cd34a59e0 8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents: 21516
diff changeset
   175
  // superclass was j.l.Object which would be also covered by class
e75cd34a59e0 8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents: 21516
diff changeset
   176
  // superclass hierarchy walks. Now that the starting point can be
e75cd34a59e0 8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents: 21516
diff changeset
   177
  // an interface, we must ensure we catch j.l.Object as the super.
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   178
  static bool has_super(InstanceKlass* cls) {
21556
e75cd34a59e0 8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents: 21516
diff changeset
   179
    return cls->super() != NULL;
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   180
  }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   181
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   182
  Node* node_at_depth(int i) const {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   183
    return (i >= _path.length()) ? NULL : _path.at(_path.length() - i - 1);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   184
  }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   185
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   186
 protected:
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   187
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   188
  // Accessors available to the algorithm
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   189
  int current_depth() const { return _path.length() - 1; }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   190
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   191
  InstanceKlass* class_at_depth(int i) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   192
    Node* n = node_at_depth(i);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   193
    return n == NULL ? NULL : n->_class;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   194
  }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   195
  InstanceKlass* current_class() { return class_at_depth(0); }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   196
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   197
  void* data_at_depth(int i) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   198
    Node* n = node_at_depth(i);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   199
    return n == NULL ? NULL : n->_algorithm_data;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   200
  }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   201
  void* current_data() { return data_at_depth(0); }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   202
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   203
  void cancel_iteration() { _cancelled = true; }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   204
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   205
 public:
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   206
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   207
  void run(InstanceKlass* root) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   208
    ALGO* algo = static_cast<ALGO*>(this);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   209
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   210
    reset_iteration();
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   211
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   212
    void* algo_data = algo->new_node_data(root);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   213
    push(root, algo_data);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   214
    bool top_needs_visit = true;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   215
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   216
    do {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   217
      Node* top = current_top();
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   218
      if (top_needs_visit) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   219
        if (algo->visit() == false) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   220
          // algorithm does not want to continue along this path.  Arrange
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   221
          // it so that this state is immediately popped off the stack
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   222
          top->set_super_visited();
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   223
          top->set_all_interfaces_visited();
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   224
        }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   225
        top_needs_visit = false;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   226
      }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   227
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   228
      if (top->has_visited_super() && top->has_visited_all_interfaces()) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   229
        algo->free_node_data(top->_algorithm_data);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   230
        pop();
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   231
      } else {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   232
        InstanceKlass* next = NULL;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   233
        if (top->has_visited_super() == false) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   234
          next = top->next_super();
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   235
          top->set_super_visited();
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   236
        } else {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   237
          next = top->next_interface();
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   238
          top->increment_visited_interface();
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   239
        }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   240
        assert(next != NULL, "Otherwise we shouldn't be here");
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   241
        algo_data = algo->new_node_data(next);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   242
        push(next, algo_data);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   243
        top_needs_visit = true;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   244
      }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   245
    } while (!is_cancelled() && has_more_nodes());
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   246
  }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   247
};
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   248
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   249
#ifndef PRODUCT
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   250
class PrintHierarchy : public HierarchyVisitor<PrintHierarchy> {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   251
 public:
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   252
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   253
  bool visit() {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   254
    InstanceKlass* cls = current_class();
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   255
    streamIndentor si(tty, current_depth() * 2);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   256
    tty->indent().print_cr("%s", cls->name()->as_C_string());
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   257
    return true;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   258
  }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   259
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   260
  void* new_node_data(InstanceKlass* cls) { return NULL; }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   261
  void free_node_data(void* data) { return; }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   262
};
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   263
#endif // ndef PRODUCT
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   264
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   265
// Used to register InstanceKlass objects and all related metadata structures
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   266
// (Methods, ConstantPools) as "in-use" by the current thread so that they can't
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   267
// be deallocated by class redefinition while we're using them.  The classes are
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   268
// de-registered when this goes out of scope.
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   269
//
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   270
// Once a class is registered, we need not bother with methodHandles or
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   271
// constantPoolHandles for it's associated metadata.
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   272
class KeepAliveRegistrar : public StackObj {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   273
 private:
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   274
  Thread* _thread;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   275
  GrowableArray<ConstantPool*> _keep_alive;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   276
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   277
 public:
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   278
  KeepAliveRegistrar(Thread* thread) : _thread(thread), _keep_alive(20) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   279
    assert(thread == Thread::current(), "Must be current thread");
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   280
  }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   281
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   282
  ~KeepAliveRegistrar() {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   283
    for (int i = _keep_alive.length() - 1; i >= 0; --i) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   284
      ConstantPool* cp = _keep_alive.at(i);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   285
      int idx = _thread->metadata_handles()->find_from_end(cp);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   286
      assert(idx > 0, "Must be in the list");
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   287
      _thread->metadata_handles()->remove_at(idx);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   288
    }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   289
  }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   290
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   291
  // Register a class as 'in-use' by the thread.  It's fine to register a class
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   292
  // multiple times (though perhaps inefficient)
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   293
  void register_class(InstanceKlass* ik) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   294
    ConstantPool* cp = ik->constants();
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   295
    _keep_alive.push(cp);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   296
    _thread->metadata_handles()->push(cp);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   297
  }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   298
};
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   299
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   300
class KeepAliveVisitor : public HierarchyVisitor<KeepAliveVisitor> {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   301
 private:
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   302
  KeepAliveRegistrar* _registrar;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   303
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   304
 public:
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   305
  KeepAliveVisitor(KeepAliveRegistrar* registrar) : _registrar(registrar) {}
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   306
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   307
  void* new_node_data(InstanceKlass* cls) { return NULL; }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   308
  void free_node_data(void* data) { return; }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   309
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   310
  bool visit() {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   311
    _registrar->register_class(current_class());
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   312
    return true;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   313
  }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   314
};
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   315
18695
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   316
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   317
// A method family contains a set of all methods that implement a single
18695
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   318
// erased method. As members of the set are collected while walking over the
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   319
// hierarchy, they are tagged with a qualification state.  The qualification
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   320
// state for an erased method is set to disqualified if there exists a path
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   321
// from the root of hierarchy to the method that contains an interleaving
18695
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   322
// erased method defined in an interface.
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   323
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   324
class MethodFamily : public ResourceObj {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   325
 private:
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   326
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   327
  GrowableArray<Pair<Method*,QualifiedState> > _members;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   328
  ResourceHashtable<Method*, int> _member_index;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   329
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   330
  Method* _selected_target;  // Filled in later, if a unique target exists
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   331
  Symbol* _exception_message; // If no unique target is found
20284
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 19966
diff changeset
   332
  Symbol* _exception_name;    // If no unique target is found
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   333
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   334
  bool contains_method(Method* method) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   335
    int* lookup = _member_index.get(method);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   336
    return lookup != NULL;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   337
  }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   338
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   339
  void add_method(Method* method, QualifiedState state) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   340
    Pair<Method*,QualifiedState> entry(method, state);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   341
    _member_index.put(method, _members.length());
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   342
    _members.append(entry);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   343
  }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   344
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   345
  void disqualify_method(Method* method) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   346
    int* index = _member_index.get(method);
16379
02ed75a9a421 8009578: [parfait] Null pointer deference in hotspot/src/share/vm/classfile/defaultMethods.cpp
morris
parents: 15601
diff changeset
   347
    guarantee(index != NULL && *index >= 0 && *index < _members.length(), "bad index");
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   348
    _members.at(*index).second = DISQUALIFIED;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   349
  }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   350
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   351
  Symbol* generate_no_defaults_message(TRAPS) const;
22232
26acfad336c0 8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents: 21913
diff changeset
   352
  Symbol* generate_method_message(Symbol *klass_name, Method* method, TRAPS) const;
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   353
  Symbol* generate_conflicts_message(GrowableArray<Method*>* methods, TRAPS) const;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   354
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   355
 public:
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   356
18695
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   357
  MethodFamily()
20284
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 19966
diff changeset
   358
      : _selected_target(NULL), _exception_message(NULL), _exception_name(NULL) {}
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   359
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   360
  void set_target_if_empty(Method* m) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   361
    if (_selected_target == NULL && !m->is_overpass()) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   362
      _selected_target = m;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   363
    }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   364
  }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   365
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   366
  void record_qualified_method(Method* m) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   367
    // If the method already exists in the set as qualified, this operation is
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   368
    // redundant.  If it already exists as disqualified, then we leave it as
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   369
    // disqualfied.  Thus we only add to the set if it's not already in the
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   370
    // set.
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   371
    if (!contains_method(m)) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   372
      add_method(m, QUALIFIED);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   373
    }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   374
  }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   375
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   376
  void record_disqualified_method(Method* m) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   377
    // If not in the set, add it as disqualified.  If it's already in the set,
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   378
    // then set the state to disqualified no matter what the previous state was.
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   379
    if (!contains_method(m)) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   380
      add_method(m, DISQUALIFIED);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   381
    } else {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   382
      disqualify_method(m);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   383
    }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   384
  }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   386
  bool has_target() const { return _selected_target != NULL; }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   387
  bool throws_exception() { return _exception_message != NULL; }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   388
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   389
  Method* get_selected_target() { return _selected_target; }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   390
  Symbol* get_exception_message() { return _exception_message; }
20284
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 19966
diff changeset
   391
  Symbol* get_exception_name() { return _exception_name; }
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   392
22493
af3de4cee5e5 8031059: invokestatic: ICCE trying to invoke static method when it clashes with an abstract method inherited from an interface
hseigel
parents: 22233
diff changeset
   393
  // Return true if the specified klass has a static method that matches
af3de4cee5e5 8031059: invokestatic: ICCE trying to invoke static method when it clashes with an abstract method inherited from an interface
hseigel
parents: 22233
diff changeset
   394
  // the name and signature of the target method.
af3de4cee5e5 8031059: invokestatic: ICCE trying to invoke static method when it clashes with an abstract method inherited from an interface
hseigel
parents: 22233
diff changeset
   395
  bool has_matching_static(InstanceKlass* root) {
af3de4cee5e5 8031059: invokestatic: ICCE trying to invoke static method when it clashes with an abstract method inherited from an interface
hseigel
parents: 22233
diff changeset
   396
    if (_members.length() > 0) {
af3de4cee5e5 8031059: invokestatic: ICCE trying to invoke static method when it clashes with an abstract method inherited from an interface
hseigel
parents: 22233
diff changeset
   397
      Pair<Method*,QualifiedState> entry = _members.at(0);
af3de4cee5e5 8031059: invokestatic: ICCE trying to invoke static method when it clashes with an abstract method inherited from an interface
hseigel
parents: 22233
diff changeset
   398
      Method* impl = root->find_method(entry.first->name(),
af3de4cee5e5 8031059: invokestatic: ICCE trying to invoke static method when it clashes with an abstract method inherited from an interface
hseigel
parents: 22233
diff changeset
   399
                                       entry.first->signature());
af3de4cee5e5 8031059: invokestatic: ICCE trying to invoke static method when it clashes with an abstract method inherited from an interface
hseigel
parents: 22233
diff changeset
   400
      if ((impl != NULL) && impl->is_static()) {
af3de4cee5e5 8031059: invokestatic: ICCE trying to invoke static method when it clashes with an abstract method inherited from an interface
hseigel
parents: 22233
diff changeset
   401
        return true;
af3de4cee5e5 8031059: invokestatic: ICCE trying to invoke static method when it clashes with an abstract method inherited from an interface
hseigel
parents: 22233
diff changeset
   402
      }
af3de4cee5e5 8031059: invokestatic: ICCE trying to invoke static method when it clashes with an abstract method inherited from an interface
hseigel
parents: 22233
diff changeset
   403
    }
af3de4cee5e5 8031059: invokestatic: ICCE trying to invoke static method when it clashes with an abstract method inherited from an interface
hseigel
parents: 22233
diff changeset
   404
    return false;
af3de4cee5e5 8031059: invokestatic: ICCE trying to invoke static method when it clashes with an abstract method inherited from an interface
hseigel
parents: 22233
diff changeset
   405
  }
af3de4cee5e5 8031059: invokestatic: ICCE trying to invoke static method when it clashes with an abstract method inherited from an interface
hseigel
parents: 22233
diff changeset
   406
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   407
  // Either sets the target or the exception error message
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   408
  void determine_target(InstanceKlass* root, TRAPS) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   409
    if (has_target() || throws_exception()) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   410
      return;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   411
    }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   412
21556
e75cd34a59e0 8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents: 21516
diff changeset
   413
    // Qualified methods are maximally-specific methods
e75cd34a59e0 8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents: 21516
diff changeset
   414
    // These include public, instance concrete (=default) and abstract methods
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   415
    GrowableArray<Method*> qualified_methods;
21516
8fa5308ab970 8027304: Lambda: inheriting abstract + 1 default -> default, not ICCE
acorn
parents: 20710
diff changeset
   416
    int num_defaults = 0;
8fa5308ab970 8027304: Lambda: inheriting abstract + 1 default -> default, not ICCE
acorn
parents: 20710
diff changeset
   417
    int default_index = -1;
21556
e75cd34a59e0 8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents: 21516
diff changeset
   418
    int qualified_index = -1;
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   419
    for (int i = 0; i < _members.length(); ++i) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   420
      Pair<Method*,QualifiedState> entry = _members.at(i);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   421
      if (entry.second == QUALIFIED) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   422
        qualified_methods.append(entry.first);
21556
e75cd34a59e0 8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents: 21516
diff changeset
   423
        qualified_index++;
21516
8fa5308ab970 8027304: Lambda: inheriting abstract + 1 default -> default, not ICCE
acorn
parents: 20710
diff changeset
   424
        if (entry.first->is_default_method()) {
8fa5308ab970 8027304: Lambda: inheriting abstract + 1 default -> default, not ICCE
acorn
parents: 20710
diff changeset
   425
          num_defaults++;
21556
e75cd34a59e0 8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents: 21516
diff changeset
   426
          default_index = qualified_index;
e75cd34a59e0 8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents: 21516
diff changeset
   427
21516
8fa5308ab970 8027304: Lambda: inheriting abstract + 1 default -> default, not ICCE
acorn
parents: 20710
diff changeset
   428
        }
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   429
      }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   430
    }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   431
22232
26acfad336c0 8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents: 21913
diff changeset
   432
    if (num_defaults == 0) {
22493
af3de4cee5e5 8031059: invokestatic: ICCE trying to invoke static method when it clashes with an abstract method inherited from an interface
hseigel
parents: 22233
diff changeset
   433
      // If the root klass has a static method with matching name and signature
af3de4cee5e5 8031059: invokestatic: ICCE trying to invoke static method when it clashes with an abstract method inherited from an interface
hseigel
parents: 22233
diff changeset
   434
      // then do not generate an overpass method because it will hide the
af3de4cee5e5 8031059: invokestatic: ICCE trying to invoke static method when it clashes with an abstract method inherited from an interface
hseigel
parents: 22233
diff changeset
   435
      // static method during resolution.
af3de4cee5e5 8031059: invokestatic: ICCE trying to invoke static method when it clashes with an abstract method inherited from an interface
hseigel
parents: 22233
diff changeset
   436
      if (!has_matching_static(root)) {
af3de4cee5e5 8031059: invokestatic: ICCE trying to invoke static method when it clashes with an abstract method inherited from an interface
hseigel
parents: 22233
diff changeset
   437
        if (qualified_methods.length() == 0) {
af3de4cee5e5 8031059: invokestatic: ICCE trying to invoke static method when it clashes with an abstract method inherited from an interface
hseigel
parents: 22233
diff changeset
   438
          _exception_message = generate_no_defaults_message(CHECK);
af3de4cee5e5 8031059: invokestatic: ICCE trying to invoke static method when it clashes with an abstract method inherited from an interface
hseigel
parents: 22233
diff changeset
   439
        } else {
af3de4cee5e5 8031059: invokestatic: ICCE trying to invoke static method when it clashes with an abstract method inherited from an interface
hseigel
parents: 22233
diff changeset
   440
          assert(root != NULL, "Null root class");
af3de4cee5e5 8031059: invokestatic: ICCE trying to invoke static method when it clashes with an abstract method inherited from an interface
hseigel
parents: 22233
diff changeset
   441
          _exception_message = generate_method_message(root->name(), qualified_methods.at(0), CHECK);
af3de4cee5e5 8031059: invokestatic: ICCE trying to invoke static method when it clashes with an abstract method inherited from an interface
hseigel
parents: 22233
diff changeset
   442
        }
af3de4cee5e5 8031059: invokestatic: ICCE trying to invoke static method when it clashes with an abstract method inherited from an interface
hseigel
parents: 22233
diff changeset
   443
        _exception_name = vmSymbols::java_lang_AbstractMethodError();
22232
26acfad336c0 8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents: 21913
diff changeset
   444
      }
22493
af3de4cee5e5 8031059: invokestatic: ICCE trying to invoke static method when it clashes with an abstract method inherited from an interface
hseigel
parents: 22233
diff changeset
   445
21556
e75cd34a59e0 8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents: 21516
diff changeset
   446
    // If only one qualified method is default, select that
21516
8fa5308ab970 8027304: Lambda: inheriting abstract + 1 default -> default, not ICCE
acorn
parents: 20710
diff changeset
   447
    } else if (num_defaults == 1) {
8fa5308ab970 8027304: Lambda: inheriting abstract + 1 default -> default, not ICCE
acorn
parents: 20710
diff changeset
   448
        _selected_target = qualified_methods.at(default_index);
22493
af3de4cee5e5 8031059: invokestatic: ICCE trying to invoke static method when it clashes with an abstract method inherited from an interface
hseigel
parents: 22233
diff changeset
   449
af3de4cee5e5 8031059: invokestatic: ICCE trying to invoke static method when it clashes with an abstract method inherited from an interface
hseigel
parents: 22233
diff changeset
   450
    } else if (num_defaults > 1 && !has_matching_static(root)) {
af3de4cee5e5 8031059: invokestatic: ICCE trying to invoke static method when it clashes with an abstract method inherited from an interface
hseigel
parents: 22233
diff changeset
   451
      _exception_message = generate_conflicts_message(&qualified_methods,CHECK);
af3de4cee5e5 8031059: invokestatic: ICCE trying to invoke static method when it clashes with an abstract method inherited from an interface
hseigel
parents: 22233
diff changeset
   452
      _exception_name = vmSymbols::java_lang_IncompatibleClassChangeError();
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   453
      if (TraceDefaultMethods) {
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   454
        _exception_message->print_value_on(tty);
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   455
        tty->print_cr("");
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   456
      }
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   457
    }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   458
  }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   459
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   460
  bool contains_signature(Symbol* query) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   461
    for (int i = 0; i < _members.length(); ++i) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   462
      if (query == _members.at(i).first->signature()) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   463
        return true;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   464
      }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   465
    }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   466
    return false;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   467
  }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   468
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   469
#ifndef PRODUCT
18695
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   470
  void print_sig_on(outputStream* str, Symbol* signature, int indent) const {
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   471
    streamIndentor si(str, indent * 2);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   472
18695
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   473
    str->indent().print_cr("Logical Method %s:", signature->as_C_string());
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   474
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   475
    streamIndentor si2(str);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   476
    for (int i = 0; i < _members.length(); ++i) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   477
      str->indent();
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   478
      print_method(str, _members.at(i).first);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   479
      if (_members.at(i).second == DISQUALIFIED) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   480
        str->print(" (disqualified)");
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   481
      }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   482
      str->print_cr("");
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   483
    }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   484
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   485
    if (_selected_target != NULL) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   486
      print_selected(str, 1);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   487
    }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   488
  }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   489
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   490
  void print_selected(outputStream* str, int indent) const {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   491
    assert(has_target(), "Should be called otherwise");
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   492
    streamIndentor si(str, indent * 2);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   493
    str->indent().print("Selected method: ");
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   494
    print_method(str, _selected_target);
19966
64732b96b5f5 8024647: Default method resolution with private superclass method
acorn
parents: 19690
diff changeset
   495
    Klass* method_holder = _selected_target->method_holder();
64732b96b5f5 8024647: Default method resolution with private superclass method
acorn
parents: 19690
diff changeset
   496
    if (!method_holder->is_interface()) {
64732b96b5f5 8024647: Default method resolution with private superclass method
acorn
parents: 19690
diff changeset
   497
      tty->print(" : in superclass");
64732b96b5f5 8024647: Default method resolution with private superclass method
acorn
parents: 19690
diff changeset
   498
    }
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   499
    str->print_cr("");
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   500
  }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   501
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   502
  void print_exception(outputStream* str, int indent) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   503
    assert(throws_exception(), "Should be called otherwise");
20284
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 19966
diff changeset
   504
    assert(_exception_name != NULL, "exception_name should be set");
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   505
    streamIndentor si(str, indent * 2);
20284
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 19966
diff changeset
   506
    str->indent().print_cr("%s: %s", _exception_name->as_C_string(), _exception_message->as_C_string());
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   507
  }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   508
#endif // ndef PRODUCT
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   509
};
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   510
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   511
Symbol* MethodFamily::generate_no_defaults_message(TRAPS) const {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   512
  return SymbolTable::new_symbol("No qualifying defaults found", CHECK_NULL);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   513
}
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   514
22232
26acfad336c0 8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents: 21913
diff changeset
   515
Symbol* MethodFamily::generate_method_message(Symbol *klass_name, Method* method, TRAPS) const {
26acfad336c0 8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents: 21913
diff changeset
   516
  stringStream ss;
26acfad336c0 8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents: 21913
diff changeset
   517
  ss.print("Method ");
26acfad336c0 8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents: 21913
diff changeset
   518
  Symbol* name = method->name();
26acfad336c0 8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents: 21913
diff changeset
   519
  Symbol* signature = method->signature();
26acfad336c0 8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents: 21913
diff changeset
   520
  ss.write((const char*)klass_name->bytes(), klass_name->utf8_length());
26acfad336c0 8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents: 21913
diff changeset
   521
  ss.print(".");
26acfad336c0 8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents: 21913
diff changeset
   522
  ss.write((const char*)name->bytes(), name->utf8_length());
26acfad336c0 8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents: 21913
diff changeset
   523
  ss.write((const char*)signature->bytes(), signature->utf8_length());
26acfad336c0 8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents: 21913
diff changeset
   524
  ss.print(" is abstract");
26acfad336c0 8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents: 21913
diff changeset
   525
  return SymbolTable::new_symbol(ss.base(), (int)ss.size(), CHECK_NULL);
26acfad336c0 8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents: 21913
diff changeset
   526
}
26acfad336c0 8027804: JCK resolveMethod test fails expecting AbstractMethodError
hseigel
parents: 21913
diff changeset
   527
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   528
Symbol* MethodFamily::generate_conflicts_message(GrowableArray<Method*>* methods, TRAPS) const {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   529
  stringStream ss;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   530
  ss.print("Conflicting default methods:");
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   531
  for (int i = 0; i < methods->length(); ++i) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   532
    Method* method = methods->at(i);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   533
    Symbol* klass = method->klass_name();
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   534
    Symbol* name = method->name();
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   535
    ss.print(" ");
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   536
    ss.write((const char*)klass->bytes(), klass->utf8_length());
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   537
    ss.print(".");
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   538
    ss.write((const char*)name->bytes(), name->utf8_length());
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   539
  }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   540
  return SymbolTable::new_symbol(ss.base(), (int)ss.size(), CHECK_NULL);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   541
}
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   542
18695
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   543
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   544
class StateRestorer;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   545
18695
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   546
// StatefulMethodFamily is a wrapper around a MethodFamily that maintains the
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   547
// qualification state during hierarchy visitation, and applies that state
18695
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   548
// when adding members to the MethodFamily
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   549
class StatefulMethodFamily : public ResourceObj {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   550
  friend class StateRestorer;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   551
 private:
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   552
  QualifiedState _qualification_state;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   553
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   554
  void set_qualification_state(QualifiedState state) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   555
    _qualification_state = state;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   556
  }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   557
18695
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   558
 protected:
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   559
  MethodFamily* _method_family;
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   560
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   561
 public:
18695
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   562
  StatefulMethodFamily() {
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   563
   _method_family = new MethodFamily();
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   564
   _qualification_state = QUALIFIED;
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   565
  }
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   566
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   567
  StatefulMethodFamily(MethodFamily* mf) {
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   568
   _method_family = mf;
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   569
   _qualification_state = QUALIFIED;
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   570
  }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   571
18695
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   572
  void set_target_if_empty(Method* m) { _method_family->set_target_if_empty(m); }
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   573
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   574
  MethodFamily* get_method_family() { return _method_family; }
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   575
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   576
  StateRestorer* record_method_and_dq_further(Method* mo);
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   577
};
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   578
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   579
class StateRestorer : public PseudoScopeMark {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   580
 private:
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   581
  StatefulMethodFamily* _method;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   582
  QualifiedState _state_to_restore;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   583
 public:
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   584
  StateRestorer(StatefulMethodFamily* dm, QualifiedState state)
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   585
      : _method(dm), _state_to_restore(state) {}
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   586
  ~StateRestorer() { destroy(); }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   587
  void restore_state() { _method->set_qualification_state(_state_to_restore); }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   588
  virtual void destroy() { restore_state(); }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   589
};
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   590
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   591
StateRestorer* StatefulMethodFamily::record_method_and_dq_further(Method* mo) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   592
  StateRestorer* mark = new StateRestorer(this, _qualification_state);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   593
  if (_qualification_state == QUALIFIED) {
18695
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   594
    _method_family->record_qualified_method(mo);
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   595
  } else {
18695
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   596
    _method_family->record_disqualified_method(mo);
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   597
  }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   598
  // Everything found "above"??? this method in the hierarchy walk is set to
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   599
  // disqualified
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   600
  set_qualification_state(DISQUALIFIED);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   601
  return mark;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   602
}
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   603
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   604
// Represents a location corresponding to a vtable slot for methods that
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   605
// neither the class nor any of it's ancestors provide an implementaion.
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   606
// Default methods may be present to fill this slot.
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   607
class EmptyVtableSlot : public ResourceObj {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   608
 private:
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   609
  Symbol* _name;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   610
  Symbol* _signature;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   611
  int _size_of_parameters;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   612
  MethodFamily* _binding;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   613
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   614
 public:
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   615
  EmptyVtableSlot(Method* method)
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   616
      : _name(method->name()), _signature(method->signature()),
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   617
        _size_of_parameters(method->size_of_parameters()), _binding(NULL) {}
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   618
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   619
  Symbol* name() const { return _name; }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   620
  Symbol* signature() const { return _signature; }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   621
  int size_of_parameters() const { return _size_of_parameters; }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   622
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   623
  void bind_family(MethodFamily* lm) { _binding = lm; }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   624
  bool is_bound() { return _binding != NULL; }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   625
  MethodFamily* get_binding() { return _binding; }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   626
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   627
#ifndef PRODUCT
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   628
  void print_on(outputStream* str) const {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   629
    print_slot(str, name(), signature());
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   630
  }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   631
#endif // ndef PRODUCT
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   632
};
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   633
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   634
static bool already_in_vtable_slots(GrowableArray<EmptyVtableSlot*>* slots, Method* m) {
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   635
  bool found = false;
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   636
  for (int j = 0; j < slots->length(); ++j) {
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   637
    if (slots->at(j)->name() == m->name() &&
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   638
        slots->at(j)->signature() == m->signature() ) {
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   639
      found = true;
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   640
      break;
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   641
    }
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   642
  }
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   643
  return found;
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   644
}
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   645
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   646
static GrowableArray<EmptyVtableSlot*>* find_empty_vtable_slots(
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   647
    InstanceKlass* klass, GrowableArray<Method*>* mirandas, TRAPS) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   648
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   649
  assert(klass != NULL, "Must be valid class");
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   650
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   651
  GrowableArray<EmptyVtableSlot*>* slots = new GrowableArray<EmptyVtableSlot*>();
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   652
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   653
  // All miranda methods are obvious candidates
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   654
  for (int i = 0; i < mirandas->length(); ++i) {
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   655
    Method* m = mirandas->at(i);
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   656
    if (!already_in_vtable_slots(slots, m)) {
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   657
      slots->append(new EmptyVtableSlot(m));
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   658
    }
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   659
  }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   660
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   661
  // Also any overpasses in our superclasses, that we haven't implemented.
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   662
  // (can't use the vtable because it is not guaranteed to be initialized yet)
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   663
  InstanceKlass* super = klass->java_super();
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   664
  while (super != NULL) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   665
    for (int i = 0; i < super->methods()->length(); ++i) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   666
      Method* m = super->methods()->at(i);
21913
0e2fd7282ac6 8028438: static superclass method masks default methods
acorn
parents: 21556
diff changeset
   667
      if (m->is_overpass() || m->is_static()) {
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   668
        // m is a method that would have been a miranda if not for the
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   669
        // default method processing that occurred on behalf of our superclass,
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   670
        // so it's a method we want to re-examine in this new context.  That is,
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   671
        // unless we have a real implementation of it in the current class.
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   672
        Method* impl = klass->lookup_method(m->name(), m->signature());
21913
0e2fd7282ac6 8028438: static superclass method masks default methods
acorn
parents: 21556
diff changeset
   673
        if (impl == NULL || impl->is_overpass() || impl->is_static()) {
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   674
          if (!already_in_vtable_slots(slots, m)) {
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   675
            slots->append(new EmptyVtableSlot(m));
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   676
          }
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   677
        }
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   678
      }
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   679
    }
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   680
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   681
    // also any default methods in our superclasses
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   682
    if (super->default_methods() != NULL) {
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   683
      for (int i = 0; i < super->default_methods()->length(); ++i) {
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   684
        Method* m = super->default_methods()->at(i);
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   685
        // m is a method that would have been a miranda if not for the
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   686
        // default method processing that occurred on behalf of our superclass,
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   687
        // so it's a method we want to re-examine in this new context.  That is,
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   688
        // unless we have a real implementation of it in the current class.
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   689
        Method* impl = klass->lookup_method(m->name(), m->signature());
21913
0e2fd7282ac6 8028438: static superclass method masks default methods
acorn
parents: 21556
diff changeset
   690
        if (impl == NULL || impl->is_overpass() || impl->is_static()) {
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   691
          if (!already_in_vtable_slots(slots, m)) {
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   692
            slots->append(new EmptyVtableSlot(m));
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   693
          }
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   694
        }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   695
      }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   696
    }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   697
    super = super->java_super();
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   698
  }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   699
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   700
#ifndef PRODUCT
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   701
  if (TraceDefaultMethods) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   702
    tty->print_cr("Slots that need filling:");
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   703
    streamIndentor si(tty);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   704
    for (int i = 0; i < slots->length(); ++i) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   705
      tty->indent();
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   706
      slots->at(i)->print_on(tty);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   707
      tty->print_cr("");
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   708
    }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   709
  }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   710
#endif // ndef PRODUCT
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   711
  return slots;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   712
}
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   713
18695
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   714
// Iterates over the superinterface type hierarchy looking for all methods
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   715
// with a specific erased signature.
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   716
class FindMethodsByErasedSig : public HierarchyVisitor<FindMethodsByErasedSig> {
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   717
 private:
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   718
  // Context data
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   719
  Symbol* _method_name;
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   720
  Symbol* _method_signature;
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   721
  StatefulMethodFamily*  _family;
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   722
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   723
 public:
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   724
  FindMethodsByErasedSig(Symbol* name, Symbol* signature) :
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   725
      _method_name(name), _method_signature(signature),
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   726
      _family(NULL) {}
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   727
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   728
  void get_discovered_family(MethodFamily** family) {
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   729
      if (_family != NULL) {
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   730
        *family = _family->get_method_family();
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   731
      } else {
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   732
        *family = NULL;
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   733
      }
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   734
  }
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   735
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   736
  void* new_node_data(InstanceKlass* cls) { return new PseudoScope(); }
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   737
  void free_node_data(void* node_data) {
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   738
    PseudoScope::cast(node_data)->destroy();
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   739
  }
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   740
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   741
  // Find all methods on this hierarchy that match this
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   742
  // method's erased (name, signature)
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   743
  bool visit() {
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   744
    PseudoScope* scope = PseudoScope::cast(current_data());
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   745
    InstanceKlass* iklass = current_class();
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   746
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   747
    Method* m = iklass->find_method(_method_name, _method_signature);
20284
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 19966
diff changeset
   748
    // private interface methods are not candidates for default methods
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 19966
diff changeset
   749
    // invokespecial to private interface methods doesn't use default method logic
21556
e75cd34a59e0 8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents: 21516
diff changeset
   750
    // The overpasses are your supertypes' errors, we do not include them
20284
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 19966
diff changeset
   751
    // future: take access controls into account for superclass methods
21556
e75cd34a59e0 8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents: 21516
diff changeset
   752
    if (m != NULL && !m->is_static() && !m->is_overpass() &&
e75cd34a59e0 8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents: 21516
diff changeset
   753
         (!iklass->is_interface() || m->is_public())) {
18695
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   754
      if (_family == NULL) {
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   755
        _family = new StatefulMethodFamily();
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   756
      }
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   757
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   758
      if (iklass->is_interface()) {
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   759
        StateRestorer* restorer = _family->record_method_and_dq_further(m);
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   760
        scope->add_mark(restorer);
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   761
      } else {
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   762
        // This is the rule that methods in classes "win" (bad word) over
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   763
        // methods in interfaces. This works because of single inheritance
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   764
        _family->set_target_if_empty(m);
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   765
      }
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   766
    }
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   767
    return true;
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   768
  }
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   769
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   770
};
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   771
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   772
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   773
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   774
static void create_defaults_and_exceptions(
18695
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   775
    GrowableArray<EmptyVtableSlot*>* slots, InstanceKlass* klass, TRAPS);
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   776
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   777
static void generate_erased_defaults(
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   778
     InstanceKlass* klass, GrowableArray<EmptyVtableSlot*>* empty_slots,
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   779
     EmptyVtableSlot* slot, TRAPS) {
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   780
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   781
  // sets up a set of methods with the same exact erased signature
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   782
  FindMethodsByErasedSig visitor(slot->name(), slot->signature());
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   783
  visitor.run(klass);
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   784
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   785
  MethodFamily* family;
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   786
  visitor.get_discovered_family(&family);
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   787
  if (family != NULL) {
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   788
    family->determine_target(klass, CHECK);
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   789
    slot->bind_family(family);
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   790
  }
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   791
}
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   792
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   793
static void merge_in_new_methods(InstanceKlass* klass,
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   794
    GrowableArray<Method*>* new_methods, TRAPS);
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   795
static void create_default_methods( InstanceKlass* klass,
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   796
    GrowableArray<Method*>* new_methods, TRAPS);
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   797
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   798
// This is the guts of the default methods implementation.  This is called just
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   799
// after the classfile has been parsed if some ancestor has default methods.
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   800
//
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   801
// First if finds any name/signature slots that need any implementation (either
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   802
// because they are miranda or a superclass's implementation is an overpass
19681
1b35da7b1d85 8012294: remove generic handling for default methods
acorn
parents: 18695
diff changeset
   803
// itself).  For each slot, iterate over the hierarchy, to see if they contain a
1b35da7b1d85 8012294: remove generic handling for default methods
acorn
parents: 18695
diff changeset
   804
// signature that matches the slot we are looking at.
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   805
//
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   806
// For each slot filled, we generate an overpass method that either calls the
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   807
// unique default method candidate using invokespecial, or throws an exception
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   808
// (in the case of no default method candidates, or more than one valid
19681
1b35da7b1d85 8012294: remove generic handling for default methods
acorn
parents: 18695
diff changeset
   809
// candidate).  These methods are then added to the class's method list.
1b35da7b1d85 8012294: remove generic handling for default methods
acorn
parents: 18695
diff changeset
   810
// The JVM does not create bridges nor handle generic signatures here.
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   811
void DefaultMethods::generate_default_methods(
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   812
    InstanceKlass* klass, GrowableArray<Method*>* mirandas, TRAPS) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   813
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   814
  // This resource mark is the bound for all memory allocation that takes
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   815
  // place during default method processing.  After this goes out of scope,
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   816
  // all (Resource) objects' memory will be reclaimed.  Be careful if adding an
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   817
  // embedded resource mark under here as that memory can't be used outside
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   818
  // whatever scope it's in.
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   819
  ResourceMark rm(THREAD);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   820
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   821
  // Keep entire hierarchy alive for the duration of the computation
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   822
  KeepAliveRegistrar keepAlive(THREAD);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   823
  KeepAliveVisitor loadKeepAlive(&keepAlive);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   824
  loadKeepAlive.run(klass);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   825
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   826
#ifndef PRODUCT
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   827
  if (TraceDefaultMethods) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   828
    ResourceMark rm;  // be careful with these!
21556
e75cd34a59e0 8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents: 21516
diff changeset
   829
    tty->print_cr("%s %s requires default method processing",
e75cd34a59e0 8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents: 21516
diff changeset
   830
        klass->is_interface() ? "Interface" : "Class",
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   831
        klass->name()->as_klass_external_name());
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   832
    PrintHierarchy printer;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   833
    printer.run(klass);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   834
  }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   835
#endif // ndef PRODUCT
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   836
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   837
  GrowableArray<EmptyVtableSlot*>* empty_slots =
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   838
      find_empty_vtable_slots(klass, mirandas, CHECK);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   839
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   840
  for (int i = 0; i < empty_slots->length(); ++i) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   841
    EmptyVtableSlot* slot = empty_slots->at(i);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   842
#ifndef PRODUCT
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   843
    if (TraceDefaultMethods) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   844
      streamIndentor si(tty, 2);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   845
      tty->indent().print("Looking for default methods for slot ");
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   846
      slot->print_on(tty);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   847
      tty->print_cr("");
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   848
    }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   849
#endif // ndef PRODUCT
18695
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   850
19681
1b35da7b1d85 8012294: remove generic handling for default methods
acorn
parents: 18695
diff changeset
   851
    generate_erased_defaults(klass, empty_slots, slot, CHECK);
18695
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   852
 }
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   853
#ifndef PRODUCT
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   854
  if (TraceDefaultMethods) {
21556
e75cd34a59e0 8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents: 21516
diff changeset
   855
    tty->print_cr("Creating defaults and overpasses...");
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   856
  }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   857
#endif // ndef PRODUCT
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   858
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   859
  create_defaults_and_exceptions(empty_slots, klass, CHECK);
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   860
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   861
#ifndef PRODUCT
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   862
  if (TraceDefaultMethods) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   863
    tty->print_cr("Default method processing complete");
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   864
  }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   865
#endif // ndef PRODUCT
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   866
}
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   867
20284
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 19966
diff changeset
   868
static int assemble_method_error(
595a25ab9474 8011311: Private interface methods. Default conflicts:ICCE. no erased_super_default.
acorn
parents: 19966
diff changeset
   869
    BytecodeConstantPool* cp, BytecodeBuffer* buffer, Symbol* errorName, Symbol* message, TRAPS) {
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   870
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   871
  Symbol* init = vmSymbols::object_initializer_name();
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   872
  Symbol* sig = vmSymbols::string_void_signature();
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   873
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   874
  BytecodeAssembler assem(buffer, cp);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   875
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   876
  assem._new(errorName);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   877
  assem.dup();
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   878
  assem.load_string(message);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   879
  assem.invokespecial(errorName, init, sig);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   880
  assem.athrow();
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   881
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   882
  return 3; // max stack size: [ exception, exception, string ]
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   883
}
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   884
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   885
static Method* new_method(
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   886
    BytecodeConstantPool* cp, BytecodeBuffer* bytecodes, Symbol* name,
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   887
    Symbol* sig, AccessFlags flags, int max_stack, int params,
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   888
    ConstMethod::MethodType mt, TRAPS) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   889
18695
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   890
  address code_start = 0;
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   891
  int code_length = 0;
15601
df8faef6efaf 8007320: NPG: move method annotations
coleenp
parents: 15219
diff changeset
   892
  InlineTableSizes sizes;
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   893
18695
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   894
  if (bytecodes != NULL && bytecodes->length() > 0) {
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   895
    code_start = static_cast<address>(bytecodes->adr_at(0));
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   896
    code_length = bytecodes->length();
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   897
  }
be902722fe0a 8013635: VM should no longer create bridges for generic signatures.
acorn
parents: 17859
diff changeset
   898
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   899
  Method* m = Method::allocate(cp->pool_holder()->class_loader_data(),
15601
df8faef6efaf 8007320: NPG: move method annotations
coleenp
parents: 15219
diff changeset
   900
                               code_length, flags, &sizes,
15102
0a86564e5f61 8004728: Add hotspot support for parameter reflection
coleenp
parents: 14586
diff changeset
   901
                               mt, CHECK_NULL);
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   902
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   903
  m->set_constants(NULL); // This will get filled in later
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   904
  m->set_name_index(cp->utf8(name));
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   905
  m->set_signature_index(cp->utf8(sig));
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   906
#ifdef CC_INTERP
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   907
  ResultTypeFinder rtf(sig);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   908
  m->set_result_index(rtf.type());
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   909
#endif
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   910
  m->set_size_of_parameters(params);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   911
  m->set_max_stack(max_stack);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   912
  m->set_max_locals(params);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   913
  m->constMethod()->set_stackmap_data(NULL);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   914
  m->set_code(code_start);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   915
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   916
  return m;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   917
}
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   918
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   919
static void switchover_constant_pool(BytecodeConstantPool* bpool,
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   920
    InstanceKlass* klass, GrowableArray<Method*>* new_methods, TRAPS) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   921
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   922
  if (new_methods->length() > 0) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   923
    ConstantPool* cp = bpool->create_constant_pool(CHECK);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   924
    if (cp != klass->constants()) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   925
      klass->class_loader_data()->add_to_deallocate_list(klass->constants());
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   926
      klass->set_constants(cp);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   927
      cp->set_pool_holder(klass);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   928
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   929
      for (int i = 0; i < new_methods->length(); ++i) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   930
        new_methods->at(i)->set_constants(cp);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   931
      }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   932
      for (int i = 0; i < klass->methods()->length(); ++i) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   933
        Method* mo = klass->methods()->at(i);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   934
        mo->set_constants(cp);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   935
      }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   936
    }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   937
  }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   938
}
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   939
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   940
// Create default_methods list for the current class.
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   941
// With the VM only processing erased signatures, the VM only
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   942
// creates an overpass in a conflict case or a case with no candidates.
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   943
// This allows virtual methods to override the overpass, but ensures
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   944
// that a local method search will find the exception rather than an abstract
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   945
// or default method that is not a valid candidate.
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   946
static void create_defaults_and_exceptions(
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   947
    GrowableArray<EmptyVtableSlot*>* slots,
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   948
    InstanceKlass* klass, TRAPS) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   949
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   950
  GrowableArray<Method*> overpasses;
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   951
  GrowableArray<Method*> defaults;
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   952
  BytecodeConstantPool bpool(klass->constants());
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   953
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   954
  for (int i = 0; i < slots->length(); ++i) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   955
    EmptyVtableSlot* slot = slots->at(i);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   956
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   957
    if (slot->is_bound()) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   958
      MethodFamily* method = slot->get_binding();
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   959
      BytecodeBuffer buffer;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   960
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   961
#ifndef PRODUCT
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   962
      if (TraceDefaultMethods) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   963
        tty->print("for slot: ");
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   964
        slot->print_on(tty);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   965
        tty->print_cr("");
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   966
        if (method->has_target()) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   967
          method->print_selected(tty, 1);
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   968
        } else if (method->throws_exception()) {
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   969
          method->print_exception(tty, 1);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   970
        }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   971
      }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   972
#endif // ndef PRODUCT
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   973
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   974
      if (method->has_target()) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   975
        Method* selected = method->get_selected_target();
19966
64732b96b5f5 8024647: Default method resolution with private superclass method
acorn
parents: 19690
diff changeset
   976
        if (selected->method_holder()->is_interface()) {
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   977
          defaults.push(selected);
19966
64732b96b5f5 8024647: Default method resolution with private superclass method
acorn
parents: 19690
diff changeset
   978
        }
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   979
      } else if (method->throws_exception()) {
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   980
        int max_stack = assemble_method_error(&bpool, &buffer,
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   981
           method->get_exception_name(), method->get_exception_message(), CHECK);
19966
64732b96b5f5 8024647: Default method resolution with private superclass method
acorn
parents: 19690
diff changeset
   982
        AccessFlags flags = accessFlags_from(
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   983
          JVM_ACC_PUBLIC | JVM_ACC_SYNTHETIC | JVM_ACC_BRIDGE);
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   984
         Method* m = new_method(&bpool, &buffer, slot->name(), slot->signature(),
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   985
          flags, max_stack, slot->size_of_parameters(),
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   986
          ConstMethod::OVERPASS, CHECK);
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   987
        // We push to the methods list:
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   988
        // overpass methods which are exception throwing methods
19966
64732b96b5f5 8024647: Default method resolution with private superclass method
acorn
parents: 19690
diff changeset
   989
        if (m != NULL) {
64732b96b5f5 8024647: Default method resolution with private superclass method
acorn
parents: 19690
diff changeset
   990
          overpasses.push(m);
64732b96b5f5 8024647: Default method resolution with private superclass method
acorn
parents: 19690
diff changeset
   991
        }
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   992
      }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   993
    }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   994
  }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   995
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   996
#ifndef PRODUCT
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   997
  if (TraceDefaultMethods) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   998
    tty->print_cr("Created %d overpass methods", overpasses.length());
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
   999
    tty->print_cr("Created %d default  methods", defaults.length());
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1000
  }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1001
#endif // ndef PRODUCT
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1002
20391
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
  1003
  if (overpasses.length() > 0) {
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
  1004
    switchover_constant_pool(&bpool, klass, &overpasses, CHECK);
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
  1005
    merge_in_new_methods(klass, &overpasses, CHECK);
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
  1006
  }
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
  1007
  if (defaults.length() > 0) {
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
  1008
    create_default_methods(klass, &defaults, CHECK);
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
  1009
  }
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
  1010
}
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
  1011
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
  1012
static void create_default_methods( InstanceKlass* klass,
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
  1013
    GrowableArray<Method*>* new_methods, TRAPS) {
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
  1014
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
  1015
  int new_size = new_methods->length();
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
  1016
  Array<Method*>* total_default_methods = MetadataFactory::new_array<Method*>(
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
  1017
      klass->class_loader_data(), new_size, NULL, CHECK);
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
  1018
  for (int index = 0; index < new_size; index++ ) {
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
  1019
    total_default_methods->at_put(index, new_methods->at(index));
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
  1020
  }
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
  1021
  Method::sort_methods(total_default_methods, false, false);
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
  1022
7b146c5ebb18 8009130: Lambda: Fix access controls, loader constraints.
acorn
parents: 20300
diff changeset
  1023
  klass->set_default_methods(total_default_methods);
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1024
}
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1025
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1026
static void sort_methods(GrowableArray<Method*>* methods) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1027
  // Note that this must sort using the same key as is used for sorting
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1028
  // methods in InstanceKlass.
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1029
  bool sorted = true;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1030
  for (int i = methods->length() - 1; i > 0; --i) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1031
    for (int j = 0; j < i; ++j) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1032
      Method* m1 = methods->at(j);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1033
      Method* m2 = methods->at(j + 1);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1034
      if ((uintptr_t)m1->name() > (uintptr_t)m2->name()) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1035
        methods->at_put(j, m2);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1036
        methods->at_put(j + 1, m1);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1037
        sorted = false;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1038
      }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1039
    }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1040
    if (sorted) break;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1041
    sorted = true;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1042
  }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1043
#ifdef ASSERT
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1044
  uintptr_t prev = 0;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1045
  for (int i = 0; i < methods->length(); ++i) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1046
    Method* mh = methods->at(i);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1047
    uintptr_t nv = (uintptr_t)mh->name();
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1048
    assert(nv >= prev, "Incorrect overpass method ordering");
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1049
    prev = nv;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1050
  }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1051
#endif
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1052
}
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1053
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1054
static void merge_in_new_methods(InstanceKlass* klass,
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1055
    GrowableArray<Method*>* new_methods, TRAPS) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1056
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1057
  enum { ANNOTATIONS, PARAMETERS, DEFAULTS, NUM_ARRAYS };
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1058
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1059
  Array<Method*>* original_methods = klass->methods();
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1060
  Array<int>* original_ordering = klass->method_ordering();
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1061
  Array<int>* merged_ordering = Universe::the_empty_int_array();
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1062
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1063
  int new_size = klass->methods()->length() + new_methods->length();
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1064
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1065
  Array<Method*>* merged_methods = MetadataFactory::new_array<Method*>(
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1066
      klass->class_loader_data(), new_size, NULL, CHECK);
15601
df8faef6efaf 8007320: NPG: move method annotations
coleenp
parents: 15219
diff changeset
  1067
22233
f0028de67b30 8030633: nsk/jvmti/RedefineClasses/StressRedefine failed invalid method ordering length on Solaris
coleenp
parents: 22232
diff changeset
  1068
  // original_ordering might be empty if this class has no methods of its own
f0028de67b30 8030633: nsk/jvmti/RedefineClasses/StressRedefine failed invalid method ordering length on Solaris
coleenp
parents: 22232
diff changeset
  1069
  if (JvmtiExport::can_maintain_original_method_order() || DumpSharedSpaces) {
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1070
    merged_ordering = MetadataFactory::new_array<int>(
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1071
        klass->class_loader_data(), new_size, CHECK);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1072
  }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1073
  int method_order_index = klass->methods()->length();
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1074
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1075
  sort_methods(new_methods);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1076
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1077
  // Perform grand merge of existing methods and new methods
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1078
  int orig_idx = 0;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1079
  int new_idx = 0;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1080
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1081
  for (int i = 0; i < new_size; ++i) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1082
    Method* orig_method = NULL;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1083
    Method* new_method = NULL;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1084
    if (orig_idx < original_methods->length()) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1085
      orig_method = original_methods->at(orig_idx);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1086
    }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1087
    if (new_idx < new_methods->length()) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1088
      new_method = new_methods->at(new_idx);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1089
    }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1090
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1091
    if (orig_method != NULL &&
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1092
        (new_method == NULL || orig_method->name() < new_method->name())) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1093
      merged_methods->at_put(i, orig_method);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1094
      original_methods->at_put(orig_idx, NULL);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1095
      if (merged_ordering->length() > 0) {
22233
f0028de67b30 8030633: nsk/jvmti/RedefineClasses/StressRedefine failed invalid method ordering length on Solaris
coleenp
parents: 22232
diff changeset
  1096
        assert(original_ordering != NULL && original_ordering->length() > 0,
f0028de67b30 8030633: nsk/jvmti/RedefineClasses/StressRedefine failed invalid method ordering length on Solaris
coleenp
parents: 22232
diff changeset
  1097
               "should have original order information for this method");
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1098
        merged_ordering->at_put(i, original_ordering->at(orig_idx));
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1099
      }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1100
      ++orig_idx;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1101
    } else {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1102
      merged_methods->at_put(i, new_method);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1103
      if (merged_ordering->length() > 0) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1104
        merged_ordering->at_put(i, method_order_index++);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1105
      }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1106
      ++new_idx;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1107
    }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1108
    // update idnum for new location
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1109
    merged_methods->at(i)->set_method_idnum(i);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1110
  }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1111
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1112
  // Verify correct order
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1113
#ifdef ASSERT
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1114
  uintptr_t prev = 0;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1115
  for (int i = 0; i < merged_methods->length(); ++i) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1116
    Method* mo = merged_methods->at(i);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1117
    uintptr_t nv = (uintptr_t)mo->name();
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1118
    assert(nv >= prev, "Incorrect method ordering");
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1119
    prev = nv;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1120
  }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1121
#endif
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1122
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1123
  // Replace klass methods with new merged lists
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1124
  klass->set_methods(merged_methods);
17859
cda7f55ca4dc 8015436: compiler/ciReplay/TestSA.sh fails with assert() index is out of bounds
sspitsyn
parents: 16379
diff changeset
  1125
  klass->set_initial_method_idnum(new_size);
22233
f0028de67b30 8030633: nsk/jvmti/RedefineClasses/StressRedefine failed invalid method ordering length on Solaris
coleenp
parents: 22232
diff changeset
  1126
  klass->set_method_ordering(merged_ordering);
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1127
22233
f0028de67b30 8030633: nsk/jvmti/RedefineClasses/StressRedefine failed invalid method ordering length on Solaris
coleenp
parents: 22232
diff changeset
  1128
  // Free metadata
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1129
  ClassLoaderData* cld = klass->class_loader_data();
22233
f0028de67b30 8030633: nsk/jvmti/RedefineClasses/StressRedefine failed invalid method ordering length on Solaris
coleenp
parents: 22232
diff changeset
  1130
  if (original_methods->length() > 0) {
21556
e75cd34a59e0 8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents: 21516
diff changeset
  1131
    MetadataFactory::free_array(cld, original_methods);
e75cd34a59e0 8027229: ICCE expected for >=2 maximally specific default methods.
acorn
parents: 21516
diff changeset
  1132
  }
22233
f0028de67b30 8030633: nsk/jvmti/RedefineClasses/StressRedefine failed invalid method ordering length on Solaris
coleenp
parents: 22232
diff changeset
  1133
  if (original_ordering != NULL && original_ordering->length() > 0) {
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1134
    MetadataFactory::free_array(cld, original_ordering);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1135
  }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
  1136
}