hotspot/src/share/vm/classfile/genericSignatures.hpp
author ccheung
Thu, 13 Jun 2013 22:02:40 -0700
changeset 18073 f02460441ddc
parent 14385 959bbcc16725
permissions -rw-r--r--
8014431: cleanup warnings indicated by the -Wunused-value compiler option on linux Reviewed-by: dholmes, coleenp Contributed-by: jeremymanson@google.com, calvin.cheung@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
     1
/*
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
     2
 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
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
#ifndef SHARE_VM_CLASSFILE_GENERICSIGNATURES_HPP
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    26
#define SHARE_VM_CLASSFILE_GENERICSIGNATURES_HPP
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    27
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 "runtime/signature.hpp"
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    31
#include "utilities/growableArray.hpp"
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    32
#include "utilities/resourceHash.hpp"
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    33
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    34
class stringStream;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    35
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    36
namespace generic {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    37
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    38
class Identifier;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    39
class ClassDescriptor;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    40
class MethodDescriptor;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    41
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    42
class TypeParameter; // a formal type parameter declared in generic signatures
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    43
class TypeArgument;  // The "type value" passed to fill parameters in supertypes
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    44
class TypeVariable;  // A usage of a type parameter as a value
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    45
/**
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    46
 * Example:
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    47
 *
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    48
 * <T, V> class Foo extends Bar<String> { int m(V v) {} }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    49
 * ^^^^^^                       ^^^^^^          ^^
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    50
 * type parameters            type argument    type variable
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    51
 *
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    52
 * Note that a type variable could be passed as an argument too:
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    53
 * <T, V> class Foo extends Bar<T> { int m(V v) {} }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    54
 *                             ^^^
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    55
 *                             type argument's value is a type variable
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    56
 */
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    57
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    58
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    59
class Type;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    60
class ClassType;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    61
class ArrayType;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    62
class PrimitiveType;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    63
class Context;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    64
class DescriptorCache;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    65
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    66
class DescriptorStream;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    67
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    68
class Identifier : public ResourceObj {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    69
 private:
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    70
  Symbol* _sym;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    71
  int _begin;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    72
  int _end;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    73
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    74
 public:
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    75
  Identifier(Symbol* sym, int begin, int end) :
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    76
    _sym(sym), _begin(begin), _end(end) {}
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    77
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    78
  bool equals(Identifier* other);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    79
  bool equals(Symbol* sym);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    80
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    81
#ifndef PRODUCT
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    82
  void print_on(outputStream* str) const;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    83
#endif // ndef PRODUCT
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    84
};
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    85
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    86
class Descriptor : public ResourceObj {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    87
 protected:
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    88
  GrowableArray<TypeParameter*> _type_parameters;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    89
  ClassDescriptor* _outer_class;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    90
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    91
  Descriptor(GrowableArray<TypeParameter*>& params,
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    92
    ClassDescriptor* outer)
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    93
    : _type_parameters(params), _outer_class(outer) {}
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    94
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    95
 public:
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    96
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    97
  ClassDescriptor* outer_class() { return _outer_class; }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    98
  void set_outer_class(ClassDescriptor* sig) { _outer_class = sig; }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
    99
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   100
  virtual ClassDescriptor* as_class_signature() { return NULL; }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   101
  virtual MethodDescriptor* as_method_signature() { return NULL; }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   102
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   103
  bool is_class_signature() { return as_class_signature() != NULL; }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   104
  bool is_method_signature() { return as_method_signature() != NULL; }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   105
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   106
  GrowableArray<TypeParameter*>& type_parameters() {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   107
    return _type_parameters;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   108
  }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   109
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   110
  TypeParameter* find_type_parameter(Identifier* id, int* param_depth);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   111
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   112
  virtual void bind_variables_to_parameters() = 0;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   113
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   114
#ifndef PRODUCT
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   115
  virtual void print_on(outputStream* str) const = 0;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   116
#endif
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   117
};
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   118
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   119
class ClassDescriptor : public Descriptor {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   120
 private:
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   121
  ClassType* _super;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   122
  GrowableArray<ClassType*> _interfaces;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   123
  MethodDescriptor* _outer_method;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   124
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   125
  ClassDescriptor(GrowableArray<TypeParameter*>& ftp, ClassType* scs,
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   126
      GrowableArray<ClassType*>& sis, ClassDescriptor* outer_class = NULL,
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   127
      MethodDescriptor* outer_method = NULL)
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   128
        : Descriptor(ftp, outer_class), _super(scs), _interfaces(sis),
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   129
          _outer_method(outer_method) {}
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   130
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   131
  static u2 get_outer_class_index(InstanceKlass* k, TRAPS);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   132
  static ClassDescriptor* parse_generic_signature(Klass* k, Symbol* original_name, TRAPS);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   133
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   134
 public:
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   135
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   136
  virtual ClassDescriptor* as_class_signature() { return this; }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   137
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   138
  MethodDescriptor* outer_method() { return _outer_method; }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   139
  void set_outer_method(MethodDescriptor* m) { _outer_method = m; }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   140
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   141
  ClassType* super() { return _super; }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   142
  ClassType* interface_desc(Symbol* sym);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   143
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   144
  static ClassDescriptor* parse_generic_signature(Klass* k, TRAPS);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   145
  static ClassDescriptor* parse_generic_signature(Symbol* sym);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   146
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   147
  // For use in superclass chains in positions where this is no generic info
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   148
  static ClassDescriptor* placeholder(InstanceKlass* klass);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   149
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   150
#ifndef PRODUCT
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   151
  void print_on(outputStream* str) const;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   152
#endif
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   153
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   154
  ClassDescriptor* canonicalize(Context* ctx);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   155
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   156
  // Linking sets the position index in any contained TypeVariable type
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   157
  // to correspond to the location of that identifier in the formal type
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   158
  // parameters.
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   159
  void bind_variables_to_parameters();
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   160
};
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   161
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   162
class MethodDescriptor : public Descriptor {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   163
 private:
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   164
  GrowableArray<Type*> _parameters;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   165
  Type* _return_type;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   166
  GrowableArray<Type*> _throws;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   167
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   168
  MethodDescriptor(GrowableArray<TypeParameter*>& ftp, ClassDescriptor* outer,
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   169
      GrowableArray<Type*>& sigs, Type* rt, GrowableArray<Type*>& throws)
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   170
      : Descriptor(ftp, outer), _parameters(sigs), _return_type(rt),
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   171
        _throws(throws) {}
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   172
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   173
 public:
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   174
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   175
  static MethodDescriptor* parse_generic_signature(Method* m, ClassDescriptor* outer);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   176
  static MethodDescriptor* parse_generic_signature(Symbol* sym, ClassDescriptor* outer);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   177
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   178
  MethodDescriptor* as_method_signature() { return this; }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   179
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   180
  // Performs generic analysis on the method parameters to determine
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   181
  // if both methods refer to the same argument types.
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   182
  bool covariant_match(MethodDescriptor* other, Context* ctx);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   183
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   184
  // Returns a new method descriptor with all generic variables
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   185
  // removed and replaced with whatever is indicated using the Context.
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   186
  MethodDescriptor* canonicalize(Context* ctx);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   187
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   188
  void bind_variables_to_parameters();
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   189
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   190
#ifndef PRODUCT
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   191
  TempNewSymbol reify_signature(Context* ctx, TRAPS);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   192
  void print_on(outputStream* str) const;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   193
#endif
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   194
};
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   195
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   196
class TypeParameter : public ResourceObj {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   197
 private:
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   198
  Identifier* _identifier;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   199
  ClassType* _class_bound;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   200
  GrowableArray<ClassType*> _interface_bounds;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   201
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   202
  // The position is the ordinal location of the parameter within the
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   203
  // formal parameter list (excluding outer classes).  It is only set for
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   204
  // formal type parameters that are associated with a class -- method
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   205
  // type parameters are left as -1.  When resolving a generic variable to
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   206
  // find the actual type, this index is used to access the generic type
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   207
  // argument in the provided context object.
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   208
  int _position; // Assigned during variable linking
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   209
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   210
  TypeParameter(Identifier* id, ClassType* class_bound,
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   211
    GrowableArray<ClassType*>& interface_bounds) :
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   212
      _identifier(id), _class_bound(class_bound),
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   213
      _interface_bounds(interface_bounds), _position(-1) {}
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   214
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   215
 public:
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   216
  static TypeParameter* parse_generic_signature(DescriptorStream* str);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   217
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   218
  ClassType* bound();
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   219
  int position() { return _position; }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   220
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   221
  void bind_variables_to_parameters(Descriptor* sig, int position);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   222
  Identifier* identifier() { return _identifier; }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   223
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   224
  Type* resolve(Context* ctx, int inner_depth, int ctx_depth);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   225
  TypeParameter* canonicalize(Context* ctx, int ctx_depth);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   226
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   227
#ifndef PRODUCT
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   228
  void print_on(outputStream* str) const;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   229
#endif
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   230
};
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   231
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   232
class Type : public ResourceObj {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   233
 public:
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   234
  static Type* parse_generic_signature(DescriptorStream* str);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   235
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   236
  virtual ClassType* as_class() { return NULL; }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   237
  virtual TypeVariable* as_variable() { return NULL; }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   238
  virtual ArrayType* as_array() { return NULL; }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   239
  virtual PrimitiveType* as_primitive() { return NULL; }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   240
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   241
  virtual bool covariant_match(Type* gt, Context* ctx) = 0;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   242
  virtual Type* canonicalize(Context* ctx, int ctx_depth) = 0;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   243
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   244
  virtual void bind_variables_to_parameters(Descriptor* sig) = 0;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   245
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   246
#ifndef PRODUCT
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   247
  virtual void reify_signature(stringStream* ss, Context* ctx) = 0;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   248
  virtual void print_on(outputStream* str) const = 0;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   249
#endif
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   250
};
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   251
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   252
class ClassType : public Type {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   253
  friend class ClassDescriptor;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   254
 protected:
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   255
  Identifier* _identifier;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   256
  GrowableArray<TypeArgument*> _type_arguments;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   257
  ClassType* _outer_class;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   258
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   259
  ClassType(Identifier* identifier,
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   260
      GrowableArray<TypeArgument*>& args,
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   261
      ClassType* outer)
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   262
      : _identifier(identifier), _type_arguments(args), _outer_class(outer) {}
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   263
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   264
  // Returns true if there are inner classes to read
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   265
  static Identifier* parse_generic_signature_simple(
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   266
      GrowableArray<TypeArgument*>* args,
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   267
      bool* has_inner, DescriptorStream* str);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   268
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   269
  static ClassType* parse_generic_signature(ClassType* outer,
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   270
      DescriptorStream* str);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   271
  static ClassType* from_symbol(Symbol* sym);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   272
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   273
 public:
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   274
  ClassType* as_class() { return this; }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   275
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   276
  static ClassType* parse_generic_signature(DescriptorStream* str);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   277
  static ClassType* java_lang_Object();
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   278
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   279
  Identifier* identifier() { return _identifier; }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   280
  int type_arguments_length() { return _type_arguments.length(); }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   281
  TypeArgument* type_argument_at(int i);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   282
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   283
  virtual ClassType* outer_class() { return _outer_class; }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   284
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   285
  bool covariant_match(Type* gt, Context* ctx);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   286
  ClassType* canonicalize(Context* ctx, int context_depth);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   287
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   288
  void bind_variables_to_parameters(Descriptor* sig);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   289
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   290
#ifndef PRODUCT
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   291
  void reify_signature(stringStream* ss, Context* ctx);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   292
  void print_on(outputStream* str) const;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   293
#endif
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   294
};
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   295
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   296
class TypeVariable : public Type {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   297
 private:
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   298
  Identifier* _id;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   299
  TypeParameter* _parameter; // assigned during linking
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   300
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   301
  // how many steps "out" from inner classes, -1 if method
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   302
  int _inner_depth;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   303
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   304
  TypeVariable(Identifier* id)
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   305
      : _id(id), _parameter(NULL), _inner_depth(0) {}
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   306
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   307
 public:
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   308
  TypeVariable* as_variable() { return this; }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   309
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   310
  static TypeVariable* parse_generic_signature(DescriptorStream* str);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   311
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   312
  Identifier* identifier() { return _id; }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   313
  TypeParameter* parameter() { return _parameter; }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   314
  int inner_depth() { return _inner_depth; }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   315
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   316
  void bind_variables_to_parameters(Descriptor* sig);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   317
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   318
  Type* resolve(Context* ctx, int ctx_depth);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   319
  bool covariant_match(Type* gt, Context* ctx);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   320
  Type* canonicalize(Context* ctx, int ctx_depth);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   321
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   322
#ifndef PRODUCT
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   323
  void reify_signature(stringStream* ss, Context* ctx);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   324
  void print_on(outputStream* str) const;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   325
#endif
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   326
};
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   327
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   328
class ArrayType : public Type {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   329
 private:
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   330
  Type* _base;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   331
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   332
  ArrayType(Type* base) : _base(base) {}
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   333
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   334
 public:
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   335
  ArrayType* as_array() { return this; }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   336
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   337
  static ArrayType* parse_generic_signature(DescriptorStream* str);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   338
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   339
  bool covariant_match(Type* gt, Context* ctx);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   340
  ArrayType* canonicalize(Context* ctx, int ctx_depth);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   341
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   342
  void bind_variables_to_parameters(Descriptor* sig);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   343
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   344
#ifndef PRODUCT
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   345
  void reify_signature(stringStream* ss, Context* ctx);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   346
  void print_on(outputStream* str) const;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   347
#endif
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   348
};
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   349
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   350
class PrimitiveType : public Type {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   351
  friend class Type;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   352
 private:
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   353
  char _type; // includes V for void
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   354
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   355
  PrimitiveType(char& type) : _type(type) {}
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   356
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   357
 public:
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   358
  PrimitiveType* as_primitive() { return this; }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   359
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   360
  bool covariant_match(Type* gt, Context* ctx);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   361
  PrimitiveType* canonicalize(Context* ctx, int ctx_depth);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   362
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   363
  void bind_variables_to_parameters(Descriptor* sig);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   364
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   365
#ifndef PRODUCT
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   366
  void reify_signature(stringStream* ss, Context* ctx);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   367
  void print_on(outputStream* str) const;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   368
#endif
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   369
};
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   370
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   371
class TypeArgument : public ResourceObj {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   372
 private:
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   373
  Type* _lower_bound;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   374
  Type* _upper_bound; // may be null or == _lower_bound
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   375
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   376
  TypeArgument(Type* lower_bound, Type* upper_bound)
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   377
      : _lower_bound(lower_bound), _upper_bound(upper_bound) {}
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   378
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   379
 public:
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   380
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   381
  static TypeArgument* parse_generic_signature(DescriptorStream* str);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   382
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   383
  Type* lower_bound() { return _lower_bound; }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   384
  Type* upper_bound() { return _upper_bound; }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   385
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   386
  void bind_variables_to_parameters(Descriptor* sig);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   387
  TypeArgument* canonicalize(Context* ctx, int ctx_depth);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   388
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   389
  bool covariant_match(TypeArgument* a, Context* ctx);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   390
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   391
#ifndef PRODUCT
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   392
  void print_on(outputStream* str) const;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   393
#endif
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   394
};
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   395
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   396
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   397
class Context : public ResourceObj {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   398
 private:
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   399
  DescriptorCache* _cache;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   400
  GrowableArray<ClassType*> _type_arguments;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   401
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   402
  void reset_to_mark(int size);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   403
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   404
 public:
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   405
  // When this object goes out of scope or 'destroy' is
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   406
  // called, then the application of the type to the
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   407
  // context is wound-back (unless it's been deactivated).
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   408
  class Mark : public StackObj {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   409
   private:
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   410
    mutable Context* _context;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   411
    int _marked_size;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   412
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   413
    bool is_active() const { return _context != NULL; }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   414
    void deactivate() const { _context = NULL; }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   415
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   416
   public:
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   417
    Mark() : _context(NULL), _marked_size(0) {}
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   418
    Mark(Context* ctx, int sz) : _context(ctx), _marked_size(sz) {}
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   419
    Mark(const Mark& m) : _context(m._context), _marked_size(m._marked_size) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   420
      m.deactivate(); // Ownership is transferred
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   421
    }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   422
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   423
    Mark& operator=(const Mark& cm) {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   424
      destroy();
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   425
      _context = cm._context;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   426
      _marked_size = cm._marked_size;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   427
      cm.deactivate();
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   428
      return *this;
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
    void destroy();
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   432
    ~Mark() { destroy(); }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   433
  };
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   434
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   435
  Context(DescriptorCache* cache) : _cache(cache) {}
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   436
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   437
  Mark mark() { return Mark(this, _type_arguments.length()); }
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   438
  void apply_type_arguments(InstanceKlass* current, InstanceKlass* super,TRAPS);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   439
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   440
  ClassType* at_depth(int i) const;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   441
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   442
#ifndef PRODUCT
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   443
  void print_on(outputStream* str) const;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   444
#endif
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   445
};
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   446
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   447
/**
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   448
 * Contains a cache of descriptors for classes and methods so they can be
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   449
 * looked-up instead of reparsing each time they are needed.
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   450
 */
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   451
class DescriptorCache : public ResourceObj {
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   452
 private:
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   453
  ResourceHashtable<InstanceKlass*, ClassDescriptor*> _class_descriptors;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   454
  ResourceHashtable<Method*, MethodDescriptor*> _method_descriptors;
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   455
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   456
 public:
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   457
  ClassDescriptor* descriptor_for(InstanceKlass* ikh, TRAPS);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   458
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   459
  MethodDescriptor* descriptor_for(Method* mh, ClassDescriptor* cd, TRAPS);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   460
  // Class descriptor derived from method holder
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   461
  MethodDescriptor* descriptor_for(Method* mh, TRAPS);
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   462
};
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   463
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   464
} // namespace generic
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   465
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   466
#endif // SHARE_VM_CLASSFILE_GENERICSIGNATURES_HPP
959bbcc16725 7200776: Implement default methods in interfaces
kamg
parents:
diff changeset
   467