src/share/vm/classfile/genericSignatures.cpp

changeset 6240
9b4ce069642e
parent 6239
2a907fd129cb
parent 5653
9cd0183fe325
child 6241
6fa574bfd32a
     1.1 --- a/src/share/vm/classfile/genericSignatures.cpp	Fri Sep 06 09:55:38 2013 +0100
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,1279 +0,0 @@
     1.4 -/*
     1.5 - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
     1.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 - *
     1.8 - * This code is free software; you can redistribute it and/or modify it
     1.9 - * under the terms of the GNU General Public License version 2 only, as
    1.10 - * published by the Free Software Foundation.
    1.11 - *
    1.12 - * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 - * version 2 for more details (a copy is included in the LICENSE file that
    1.16 - * accompanied this code).
    1.17 - *
    1.18 - * You should have received a copy of the GNU General Public License version
    1.19 - * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 - *
    1.22 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 - * or visit www.oracle.com if you need additional information or have any
    1.24 - * questions.
    1.25 - *
    1.26 - */
    1.27 -
    1.28 -#include "precompiled.hpp"
    1.29 -
    1.30 -#include "classfile/genericSignatures.hpp"
    1.31 -#include "classfile/symbolTable.hpp"
    1.32 -#include "classfile/systemDictionary.hpp"
    1.33 -#include "memory/resourceArea.hpp"
    1.34 -
    1.35 -namespace generic {
    1.36 -
    1.37 -// Helper class for parsing the generic signature Symbol in klass and methods
    1.38 -class DescriptorStream : public ResourceObj {
    1.39 - private:
    1.40 -  Symbol* _symbol;
    1.41 -  int _offset;
    1.42 -  int _mark;
    1.43 -  const char* _parse_error;
    1.44 -
    1.45 -  void set_parse_error(const char* error) {
    1.46 -    assert(error != NULL, "Can't set NULL error string");
    1.47 -    _parse_error = error;
    1.48 -  }
    1.49 -
    1.50 - public:
    1.51 -  DescriptorStream(Symbol* sym)
    1.52 -      : _symbol(sym), _offset(0), _mark(-1), _parse_error(NULL) {}
    1.53 -
    1.54 -  const char* parse_error() const {
    1.55 -    return _parse_error;
    1.56 -  }
    1.57 -
    1.58 -  bool at_end() { return _offset >= _symbol->utf8_length(); }
    1.59 -
    1.60 -  char peek() {
    1.61 -    if (at_end()) {
    1.62 -      set_parse_error("Peeking past end of signature");
    1.63 -      return '\0';
    1.64 -    } else {
    1.65 -      return _symbol->byte_at(_offset);
    1.66 -    }
    1.67 -  }
    1.68 -
    1.69 -  char read() {
    1.70 -    if (at_end()) {
    1.71 -      set_parse_error("Reading past end of signature");
    1.72 -      return '\0';
    1.73 -    } else {
    1.74 -      return _symbol->byte_at(_offset++);
    1.75 -    }
    1.76 -  }
    1.77 -
    1.78 -  void read(char expected) {
    1.79 -    char c = read();
    1.80 -    assert_char(c, expected, 0);
    1.81 -  }
    1.82 -
    1.83 -  void assert_char(char c, char expected, int pos = -1) {
    1.84 -    if (c != expected) {
    1.85 -      const char* fmt = "Parse error at %d: expected %c but got %c";
    1.86 -      size_t len = strlen(fmt) + 5;
    1.87 -      char* buffer = NEW_RESOURCE_ARRAY(char, len);
    1.88 -      jio_snprintf(buffer, len, fmt, _offset + pos, expected, c);
    1.89 -      set_parse_error(buffer);
    1.90 -    }
    1.91 -  }
    1.92 -
    1.93 -  void push(char c) {
    1.94 -    assert(c == _symbol->byte_at(_offset - 1), "Pushing back wrong value");
    1.95 -    --_offset;
    1.96 -  }
    1.97 -
    1.98 -  void expect_end() {
    1.99 -    if (!at_end()) {
   1.100 -      set_parse_error("Unexpected data trailing signature");
   1.101 -    }
   1.102 -  }
   1.103 -
   1.104 -  bool has_mark() { return _mark != -1; }
   1.105 -
   1.106 -  void set_mark() {
   1.107 -    _mark = _offset;
   1.108 -  }
   1.109 -
   1.110 -  Identifier* identifier_from_mark() {
   1.111 -    assert(has_mark(), "Mark should be set");
   1.112 -    if (!has_mark()) {
   1.113 -      set_parse_error("Expected mark to be set");
   1.114 -      return NULL;
   1.115 -    } else {
   1.116 -      Identifier* id = new Identifier(_symbol, _mark, _offset - 1);
   1.117 -      _mark = -1;
   1.118 -      return id;
   1.119 -    }
   1.120 -  }
   1.121 -};
   1.122 -
   1.123 -
   1.124 -#define CHECK_FOR_PARSE_ERROR()         \
   1.125 -  if (STREAM->parse_error() != NULL) {   \
   1.126 -    if (VerifyGenericSignatures) {      \
   1.127 -      fatal(STREAM->parse_error());      \
   1.128 -    }                                   \
   1.129 -    return NULL;                        \
   1.130 -  } (void)0
   1.131 -
   1.132 -#define READ() STREAM->read(); CHECK_FOR_PARSE_ERROR()
   1.133 -#define PEEK() STREAM->peek(); CHECK_FOR_PARSE_ERROR()
   1.134 -#define PUSH(c) STREAM->push(c)
   1.135 -#define EXPECT(c) STREAM->read(c); CHECK_FOR_PARSE_ERROR()
   1.136 -#define EXPECTED(c, ch) STREAM->assert_char(c, ch); CHECK_FOR_PARSE_ERROR()
   1.137 -#define EXPECT_END() STREAM->expect_end(); CHECK_FOR_PARSE_ERROR()
   1.138 -
   1.139 -#define CHECK_STREAM STREAM); CHECK_FOR_PARSE_ERROR(); ((void)0
   1.140 -
   1.141 -#ifndef PRODUCT
   1.142 -void Identifier::print_on(outputStream* str) const {
   1.143 -  for (int i = _begin; i < _end; ++i) {
   1.144 -    str->print("%c", (char)_sym->byte_at(i));
   1.145 -  }
   1.146 -}
   1.147 -#endif // ndef PRODUCT
   1.148 -
   1.149 -bool Identifier::equals(Identifier* other) {
   1.150 -  if (_sym == other->_sym && _begin == other->_begin && _end == other->_end) {
   1.151 -    return true;
   1.152 -  } else if (_end - _begin != other->_end - other->_begin) {
   1.153 -    return false;
   1.154 -  } else {
   1.155 -    size_t len = _end - _begin;
   1.156 -    char* addr = ((char*)_sym->bytes()) + _begin;
   1.157 -    char* oaddr = ((char*)other->_sym->bytes()) + other->_begin;
   1.158 -    return strncmp(addr, oaddr, len) == 0;
   1.159 -  }
   1.160 -}
   1.161 -
   1.162 -bool Identifier::equals(Symbol* sym) {
   1.163 -  Identifier id(sym, 0, sym->utf8_length());
   1.164 -  return equals(&id);
   1.165 -}
   1.166 -
   1.167 -/**
   1.168 - * A formal type parameter may be found in the the enclosing class, but it could
   1.169 - * also come from an enclosing method or outer class, in the case of inner-outer
   1.170 - * classes or anonymous classes.  For example:
   1.171 - *
   1.172 - * class Outer<T,V> {
   1.173 - *   class Inner<W> {
   1.174 - *     void m(T t, V v, W w);
   1.175 - *   }
   1.176 - * }
   1.177 - *
   1.178 - * In this case, the type variables in m()'s signature are not all found in the
   1.179 - * immediate enclosing class (Inner).  class Inner has only type parameter W,
   1.180 - * but it's outer_class field will reference Outer's descriptor which contains
   1.181 - * T & V (no outer_method in this case).
   1.182 - *
   1.183 - * If you have an anonymous class, it has both an enclosing method *and* an
   1.184 - * enclosing class where type parameters can be declared:
   1.185 - *
   1.186 - * class MOuter<T> {
   1.187 - *   <V> void bar(V v) {
   1.188 - *     Runnable r = new Runnable() {
   1.189 - *       public void run() {}
   1.190 - *       public void foo(T t, V v) { ... }
   1.191 - *     };
   1.192 - *   }
   1.193 - * }
   1.194 - *
   1.195 - * In this case, foo will be a member of some class, Runnable$1, which has no
   1.196 - * formal parameters itself, but has an outer_method (bar()) which provides
   1.197 - * type parameter V, and an outer class MOuter with type parameter T.
   1.198 - *
   1.199 - * It is also possible that the outer class is itself an inner class to some
   1.200 - * other class (or an anonymous class with an enclosing method), so we need to
   1.201 - * follow the outer_class/outer_method chain to it's end when looking for a
   1.202 - * type parameter.
   1.203 - */
   1.204 -TypeParameter* Descriptor::find_type_parameter(Identifier* id, int* depth) {
   1.205 -
   1.206 -  int current_depth = 0;
   1.207 -
   1.208 -  MethodDescriptor* outer_method = as_method_signature();
   1.209 -  ClassDescriptor* outer_class = as_class_signature();
   1.210 -
   1.211 -  if (outer_class == NULL) { // 'this' is a method signature; use the holder
   1.212 -    outer_class = outer_method->outer_class();
   1.213 -  }
   1.214 -
   1.215 -  while (outer_method != NULL || outer_class != NULL) {
   1.216 -    if (outer_method != NULL) {
   1.217 -      for (int i = 0; i < outer_method->type_parameters().length(); ++i) {
   1.218 -        TypeParameter* p = outer_method->type_parameters().at(i);
   1.219 -        if (p->identifier()->equals(id)) {
   1.220 -          *depth = -1; // indicates this this is a method parameter
   1.221 -          return p;
   1.222 -        }
   1.223 -      }
   1.224 -    }
   1.225 -    if (outer_class != NULL) {
   1.226 -      for (int i = 0; i < outer_class->type_parameters().length(); ++i) {
   1.227 -        TypeParameter* p = outer_class->type_parameters().at(i);
   1.228 -        if (p->identifier()->equals(id)) {
   1.229 -          *depth = current_depth;
   1.230 -          return p;
   1.231 -        }
   1.232 -      }
   1.233 -      outer_method = outer_class->outer_method();
   1.234 -      outer_class = outer_class->outer_class();
   1.235 -      ++current_depth;
   1.236 -    }
   1.237 -  }
   1.238 -
   1.239 -  if (VerifyGenericSignatures) {
   1.240 -    fatal("Could not resolve identifier");
   1.241 -  }
   1.242 -
   1.243 -  return NULL;
   1.244 -}
   1.245 -
   1.246 -ClassDescriptor* ClassDescriptor::parse_generic_signature(Klass* klass, TRAPS) {
   1.247 -  return parse_generic_signature(klass, NULL, CHECK_NULL);
   1.248 -}
   1.249 -
   1.250 -ClassDescriptor* ClassDescriptor::parse_generic_signature(
   1.251 -      Klass* klass, Symbol* original_name, TRAPS) {
   1.252 -
   1.253 -  InstanceKlass* ik = InstanceKlass::cast(klass);
   1.254 -  Symbol* sym = ik->generic_signature();
   1.255 -
   1.256 -  ClassDescriptor* spec;
   1.257 -
   1.258 -  if (sym == NULL || (spec = ClassDescriptor::parse_generic_signature(sym)) == NULL) {
   1.259 -    spec = ClassDescriptor::placeholder(ik);
   1.260 -  }
   1.261 -
   1.262 -  u2 outer_index = get_outer_class_index(ik, CHECK_NULL);
   1.263 -  if (outer_index != 0) {
   1.264 -    if (original_name == NULL) {
   1.265 -      original_name = ik->name();
   1.266 -    }
   1.267 -    Handle class_loader = Handle(THREAD, ik->class_loader());
   1.268 -    Handle protection_domain = Handle(THREAD, ik->protection_domain());
   1.269 -
   1.270 -    Symbol* outer_name = ik->constants()->klass_name_at(outer_index);
   1.271 -    Klass* outer = SystemDictionary::find(
   1.272 -        outer_name, class_loader, protection_domain, CHECK_NULL);
   1.273 -    if (outer == NULL && !THREAD->is_Compiler_thread()) {
   1.274 -      if (outer_name == ik->super()->name()) {
   1.275 -        outer = SystemDictionary::resolve_super_or_fail(original_name, outer_name,
   1.276 -                                                        class_loader, protection_domain,
   1.277 -                                                        false, CHECK_NULL);
   1.278 -      }
   1.279 -      else {
   1.280 -        outer = SystemDictionary::resolve_or_fail(outer_name, class_loader,
   1.281 -                                                  protection_domain, false, CHECK_NULL);
   1.282 -      }
   1.283 -    }
   1.284 -
   1.285 -    InstanceKlass* outer_ik;
   1.286 -    ClassDescriptor* outer_spec = NULL;
   1.287 -    if (outer == NULL) {
   1.288 -      outer_spec = ClassDescriptor::placeholder(ik);
   1.289 -      assert(false, "Outer class not loaded and not loadable from here");
   1.290 -    } else {
   1.291 -      outer_ik = InstanceKlass::cast(outer);
   1.292 -      outer_spec = parse_generic_signature(outer, original_name, CHECK_NULL);
   1.293 -    }
   1.294 -    spec->set_outer_class(outer_spec);
   1.295 -
   1.296 -    u2 encl_method_idx = ik->enclosing_method_method_index();
   1.297 -    if (encl_method_idx != 0 && outer_ik != NULL) {
   1.298 -      ConstantPool* cp = ik->constants();
   1.299 -      u2 name_index = cp->name_ref_index_at(encl_method_idx);
   1.300 -      u2 sig_index = cp->signature_ref_index_at(encl_method_idx);
   1.301 -      Symbol* name = cp->symbol_at(name_index);
   1.302 -      Symbol* sig = cp->symbol_at(sig_index);
   1.303 -      Method* m = outer_ik->find_method(name, sig);
   1.304 -      if (m != NULL) {
   1.305 -        Symbol* gsig = m->generic_signature();
   1.306 -        if (gsig != NULL) {
   1.307 -          MethodDescriptor* gms = MethodDescriptor::parse_generic_signature(gsig, outer_spec);
   1.308 -          spec->set_outer_method(gms);
   1.309 -        }
   1.310 -      } else if (VerifyGenericSignatures) {
   1.311 -        ResourceMark rm;
   1.312 -        stringStream ss;
   1.313 -        ss.print("Could not find method %s %s in class %s",
   1.314 -          name->as_C_string(), sig->as_C_string(), outer_name->as_C_string());
   1.315 -        fatal(ss.as_string());
   1.316 -      }
   1.317 -    }
   1.318 -  }
   1.319 -
   1.320 -  spec->bind_variables_to_parameters();
   1.321 -  return spec;
   1.322 -}
   1.323 -
   1.324 -ClassDescriptor* ClassDescriptor::placeholder(InstanceKlass* klass) {
   1.325 -  GrowableArray<TypeParameter*> formals;
   1.326 -  GrowableArray<ClassType*> interfaces;
   1.327 -  ClassType* super_type = NULL;
   1.328 -
   1.329 -  Klass* super_klass = klass->super();
   1.330 -  if (super_klass != NULL) {
   1.331 -    InstanceKlass* super = InstanceKlass::cast(super_klass);
   1.332 -    super_type = ClassType::from_symbol(super->name());
   1.333 -  }
   1.334 -
   1.335 -  for (int i = 0; i < klass->local_interfaces()->length(); ++i) {
   1.336 -    InstanceKlass* iface = InstanceKlass::cast(klass->local_interfaces()->at(i));
   1.337 -    interfaces.append(ClassType::from_symbol(iface->name()));
   1.338 -  }
   1.339 -  return new ClassDescriptor(formals, super_type, interfaces);
   1.340 -}
   1.341 -
   1.342 -ClassDescriptor* ClassDescriptor::parse_generic_signature(Symbol* sym) {
   1.343 -
   1.344 -  DescriptorStream ds(sym);
   1.345 -  DescriptorStream* STREAM = &ds;
   1.346 -
   1.347 -  GrowableArray<TypeParameter*> parameters(8);
   1.348 -  char c = READ();
   1.349 -  if (c == '<') {
   1.350 -    c = READ();
   1.351 -    while (c != '>') {
   1.352 -      PUSH(c);
   1.353 -      TypeParameter* ftp = TypeParameter::parse_generic_signature(CHECK_STREAM);
   1.354 -      parameters.append(ftp);
   1.355 -      c = READ();
   1.356 -    }
   1.357 -  } else {
   1.358 -    PUSH(c);
   1.359 -  }
   1.360 -
   1.361 -  EXPECT('L');
   1.362 -  ClassType* super = ClassType::parse_generic_signature(CHECK_STREAM);
   1.363 -
   1.364 -  GrowableArray<ClassType*> signatures(2);
   1.365 -  while (!STREAM->at_end()) {
   1.366 -    EXPECT('L');
   1.367 -    ClassType* iface = ClassType::parse_generic_signature(CHECK_STREAM);
   1.368 -    signatures.append(iface);
   1.369 -  }
   1.370 -
   1.371 -  EXPECT_END();
   1.372 -
   1.373 -  return new ClassDescriptor(parameters, super, signatures);
   1.374 -}
   1.375 -
   1.376 -#ifndef PRODUCT
   1.377 -void ClassDescriptor::print_on(outputStream* str) const {
   1.378 -  str->indent().print_cr("ClassDescriptor {");
   1.379 -  {
   1.380 -    streamIndentor si(str);
   1.381 -    if (_type_parameters.length() > 0) {
   1.382 -      str->indent().print_cr("Formals {");
   1.383 -      {
   1.384 -        streamIndentor si(str);
   1.385 -        for (int i = 0; i < _type_parameters.length(); ++i) {
   1.386 -          _type_parameters.at(i)->print_on(str);
   1.387 -        }
   1.388 -      }
   1.389 -      str->indent().print_cr("}");
   1.390 -    }
   1.391 -    if (_super != NULL) {
   1.392 -      str->indent().print_cr("Superclass: ");
   1.393 -      {
   1.394 -        streamIndentor si(str);
   1.395 -        _super->print_on(str);
   1.396 -      }
   1.397 -    }
   1.398 -    if (_interfaces.length() > 0) {
   1.399 -      str->indent().print_cr("SuperInterfaces: {");
   1.400 -      {
   1.401 -        streamIndentor si(str);
   1.402 -        for (int i = 0; i < _interfaces.length(); ++i) {
   1.403 -          _interfaces.at(i)->print_on(str);
   1.404 -        }
   1.405 -      }
   1.406 -      str->indent().print_cr("}");
   1.407 -    }
   1.408 -    if (_outer_method != NULL) {
   1.409 -      str->indent().print_cr("Outer Method: {");
   1.410 -      {
   1.411 -        streamIndentor si(str);
   1.412 -        _outer_method->print_on(str);
   1.413 -      }
   1.414 -      str->indent().print_cr("}");
   1.415 -    }
   1.416 -    if (_outer_class != NULL) {
   1.417 -      str->indent().print_cr("Outer Class: {");
   1.418 -      {
   1.419 -        streamIndentor si(str);
   1.420 -        _outer_class->print_on(str);
   1.421 -      }
   1.422 -      str->indent().print_cr("}");
   1.423 -    }
   1.424 -  }
   1.425 -  str->indent().print_cr("}");
   1.426 -}
   1.427 -#endif // ndef PRODUCT
   1.428 -
   1.429 -ClassType* ClassDescriptor::interface_desc(Symbol* sym) {
   1.430 -  for (int i = 0; i < _interfaces.length(); ++i) {
   1.431 -    if (_interfaces.at(i)->identifier()->equals(sym)) {
   1.432 -      return _interfaces.at(i);
   1.433 -    }
   1.434 -  }
   1.435 -  if (VerifyGenericSignatures) {
   1.436 -    fatal("Did not find expected interface");
   1.437 -  }
   1.438 -  return NULL;
   1.439 -}
   1.440 -
   1.441 -void ClassDescriptor::bind_variables_to_parameters() {
   1.442 -  if (_outer_class != NULL) {
   1.443 -    _outer_class->bind_variables_to_parameters();
   1.444 -  }
   1.445 -  if (_outer_method != NULL) {
   1.446 -    _outer_method->bind_variables_to_parameters();
   1.447 -  }
   1.448 -  for (int i = 0; i < _type_parameters.length(); ++i) {
   1.449 -    _type_parameters.at(i)->bind_variables_to_parameters(this, i);
   1.450 -  }
   1.451 -  if (_super != NULL) {
   1.452 -    _super->bind_variables_to_parameters(this);
   1.453 -  }
   1.454 -  for (int i = 0; i < _interfaces.length(); ++i) {
   1.455 -    _interfaces.at(i)->bind_variables_to_parameters(this);
   1.456 -  }
   1.457 -}
   1.458 -
   1.459 -ClassDescriptor* ClassDescriptor::canonicalize(Context* ctx) {
   1.460 -
   1.461 -  GrowableArray<TypeParameter*> type_params(_type_parameters.length());
   1.462 -  for (int i = 0; i < _type_parameters.length(); ++i) {
   1.463 -    type_params.append(_type_parameters.at(i)->canonicalize(ctx, 0));
   1.464 -  }
   1.465 -
   1.466 -  ClassDescriptor* outer = _outer_class == NULL ? NULL :
   1.467 -      _outer_class->canonicalize(ctx);
   1.468 -
   1.469 -  ClassType* super = _super == NULL ? NULL : _super->canonicalize(ctx, 0);
   1.470 -
   1.471 -  GrowableArray<ClassType*> interfaces(_interfaces.length());
   1.472 -  for (int i = 0; i < _interfaces.length(); ++i) {
   1.473 -    interfaces.append(_interfaces.at(i)->canonicalize(ctx, 0));
   1.474 -  }
   1.475 -
   1.476 -  MethodDescriptor* md = _outer_method == NULL ? NULL :
   1.477 -      _outer_method->canonicalize(ctx);
   1.478 -
   1.479 -  return new ClassDescriptor(type_params, super, interfaces, outer, md);
   1.480 -}
   1.481 -
   1.482 -u2 ClassDescriptor::get_outer_class_index(InstanceKlass* klass, TRAPS) {
   1.483 -  int inner_index = InstanceKlass::inner_class_inner_class_info_offset;
   1.484 -  int outer_index = InstanceKlass::inner_class_outer_class_info_offset;
   1.485 -  int name_offset = InstanceKlass::inner_class_inner_name_offset;
   1.486 -  int next_offset = InstanceKlass::inner_class_next_offset;
   1.487 -
   1.488 -  if (klass->inner_classes() == NULL || klass->inner_classes()->length() == 0) {
   1.489 -    // No inner class info => no declaring class
   1.490 -    return 0;
   1.491 -  }
   1.492 -
   1.493 -  Array<u2>* i_icls = klass->inner_classes();
   1.494 -  ConstantPool* i_cp = klass->constants();
   1.495 -  int i_length = i_icls->length();
   1.496 -
   1.497 -  // Find inner_klass attribute
   1.498 -  for (int i = 0; i + next_offset < i_length; i += next_offset) {
   1.499 -    u2 ioff = i_icls->at(i + inner_index);
   1.500 -    u2 ooff = i_icls->at(i + outer_index);
   1.501 -    u2 noff = i_icls->at(i + name_offset);
   1.502 -    if (ioff != 0) {
   1.503 -      // Check to see if the name matches the class we're looking for
   1.504 -      // before attempting to find the class.
   1.505 -      if (i_cp->klass_name_at_matches(klass, ioff) && ooff != 0) {
   1.506 -        return ooff;
   1.507 -      }
   1.508 -    }
   1.509 -  }
   1.510 -
   1.511 -  // It may be anonymous; try for that.
   1.512 -  u2 encl_method_class_idx = klass->enclosing_method_class_index();
   1.513 -  if (encl_method_class_idx != 0) {
   1.514 -    return encl_method_class_idx;
   1.515 -  }
   1.516 -
   1.517 -  return 0;
   1.518 -}
   1.519 -
   1.520 -MethodDescriptor* MethodDescriptor::parse_generic_signature(Method* m, ClassDescriptor* outer) {
   1.521 -  Symbol* generic_sig = m->generic_signature();
   1.522 -  MethodDescriptor* md = NULL;
   1.523 -  if (generic_sig == NULL || (md = parse_generic_signature(generic_sig, outer)) == NULL) {
   1.524 -    md = parse_generic_signature(m->signature(), outer);
   1.525 -  }
   1.526 -  assert(md != NULL, "Could not parse method signature");
   1.527 -  md->bind_variables_to_parameters();
   1.528 -  return md;
   1.529 -}
   1.530 -
   1.531 -MethodDescriptor* MethodDescriptor::parse_generic_signature(Symbol* sym, ClassDescriptor* outer) {
   1.532 -
   1.533 -  DescriptorStream ds(sym);
   1.534 -  DescriptorStream* STREAM = &ds;
   1.535 -
   1.536 -  GrowableArray<TypeParameter*> params(8);
   1.537 -  char c = READ();
   1.538 -  if (c == '<') {
   1.539 -    c = READ();
   1.540 -    while (c != '>') {
   1.541 -      PUSH(c);
   1.542 -      TypeParameter* ftp = TypeParameter::parse_generic_signature(CHECK_STREAM);
   1.543 -      params.append(ftp);
   1.544 -      c = READ();
   1.545 -    }
   1.546 -  } else {
   1.547 -    PUSH(c);
   1.548 -  }
   1.549 -
   1.550 -  EXPECT('(');
   1.551 -
   1.552 -  GrowableArray<Type*> parameters(8);
   1.553 -  c = READ();
   1.554 -  while (c != ')') {
   1.555 -    PUSH(c);
   1.556 -    Type* arg = Type::parse_generic_signature(CHECK_STREAM);
   1.557 -    parameters.append(arg);
   1.558 -    c = READ();
   1.559 -  }
   1.560 -
   1.561 -  Type* rt = Type::parse_generic_signature(CHECK_STREAM);
   1.562 -
   1.563 -  GrowableArray<Type*> throws;
   1.564 -  while (!STREAM->at_end()) {
   1.565 -    EXPECT('^');
   1.566 -    Type* spec = Type::parse_generic_signature(CHECK_STREAM);
   1.567 -    throws.append(spec);
   1.568 -  }
   1.569 -
   1.570 -  return new MethodDescriptor(params, outer, parameters, rt, throws);
   1.571 -}
   1.572 -
   1.573 -void MethodDescriptor::bind_variables_to_parameters() {
   1.574 -  for (int i = 0; i < _type_parameters.length(); ++i) {
   1.575 -    _type_parameters.at(i)->bind_variables_to_parameters(this, i);
   1.576 -  }
   1.577 -  for (int i = 0; i < _parameters.length(); ++i) {
   1.578 -    _parameters.at(i)->bind_variables_to_parameters(this);
   1.579 -  }
   1.580 -  _return_type->bind_variables_to_parameters(this);
   1.581 -  for (int i = 0; i < _throws.length(); ++i) {
   1.582 -    _throws.at(i)->bind_variables_to_parameters(this);
   1.583 -  }
   1.584 -}
   1.585 -
   1.586 -bool MethodDescriptor::covariant_match(MethodDescriptor* other, Context* ctx) {
   1.587 -
   1.588 -  if (_parameters.length() == other->_parameters.length()) {
   1.589 -    for (int i = 0; i < _parameters.length(); ++i) {
   1.590 -      if (!_parameters.at(i)->covariant_match(other->_parameters.at(i), ctx)) {
   1.591 -        return false;
   1.592 -      }
   1.593 -    }
   1.594 -
   1.595 -    if (_return_type->as_primitive() != NULL) {
   1.596 -      return _return_type->covariant_match(other->_return_type, ctx);
   1.597 -    } else {
   1.598 -      // return type is a reference
   1.599 -      return other->_return_type->as_class() != NULL ||
   1.600 -             other->_return_type->as_variable() != NULL ||
   1.601 -             other->_return_type->as_array() != NULL;
   1.602 -    }
   1.603 -  } else {
   1.604 -    return false;
   1.605 -  }
   1.606 -}
   1.607 -
   1.608 -MethodDescriptor* MethodDescriptor::canonicalize(Context* ctx) {
   1.609 -
   1.610 -  GrowableArray<TypeParameter*> type_params(_type_parameters.length());
   1.611 -  for (int i = 0; i < _type_parameters.length(); ++i) {
   1.612 -    type_params.append(_type_parameters.at(i)->canonicalize(ctx, 0));
   1.613 -  }
   1.614 -
   1.615 -  ClassDescriptor* outer = _outer_class == NULL ? NULL :
   1.616 -      _outer_class->canonicalize(ctx);
   1.617 -
   1.618 -  GrowableArray<Type*> params(_parameters.length());
   1.619 -  for (int i = 0; i < _parameters.length(); ++i) {
   1.620 -    params.append(_parameters.at(i)->canonicalize(ctx, 0));
   1.621 -  }
   1.622 -
   1.623 -  Type* rt = _return_type->canonicalize(ctx, 0);
   1.624 -
   1.625 -  GrowableArray<Type*> throws(_throws.length());
   1.626 -  for (int i = 0; i < _throws.length(); ++i) {
   1.627 -    throws.append(_throws.at(i)->canonicalize(ctx, 0));
   1.628 -  }
   1.629 -
   1.630 -  return new MethodDescriptor(type_params, outer, params, rt, throws);
   1.631 -}
   1.632 -
   1.633 -#ifndef PRODUCT
   1.634 -TempNewSymbol MethodDescriptor::reify_signature(Context* ctx, TRAPS) {
   1.635 -  stringStream ss(256);
   1.636 -
   1.637 -  ss.print("(");
   1.638 -  for (int i = 0; i < _parameters.length(); ++i) {
   1.639 -    _parameters.at(i)->reify_signature(&ss, ctx);
   1.640 -  }
   1.641 -  ss.print(")");
   1.642 -  _return_type->reify_signature(&ss, ctx);
   1.643 -  return SymbolTable::new_symbol(ss.base(), (int)ss.size(), THREAD);
   1.644 -}
   1.645 -
   1.646 -void MethodDescriptor::print_on(outputStream* str) const {
   1.647 -  str->indent().print_cr("MethodDescriptor {");
   1.648 -  {
   1.649 -    streamIndentor si(str);
   1.650 -    if (_type_parameters.length() > 0) {
   1.651 -      str->indent().print_cr("Formals: {");
   1.652 -      {
   1.653 -        streamIndentor si(str);
   1.654 -        for (int i = 0; i < _type_parameters.length(); ++i) {
   1.655 -          _type_parameters.at(i)->print_on(str);
   1.656 -        }
   1.657 -      }
   1.658 -      str->indent().print_cr("}");
   1.659 -    }
   1.660 -    str->indent().print_cr("Parameters: {");
   1.661 -    {
   1.662 -      streamIndentor si(str);
   1.663 -      for (int i = 0; i < _parameters.length(); ++i) {
   1.664 -        _parameters.at(i)->print_on(str);
   1.665 -      }
   1.666 -    }
   1.667 -    str->indent().print_cr("}");
   1.668 -    str->indent().print_cr("Return Type: ");
   1.669 -    {
   1.670 -      streamIndentor si(str);
   1.671 -      _return_type->print_on(str);
   1.672 -    }
   1.673 -
   1.674 -    if (_throws.length() > 0) {
   1.675 -      str->indent().print_cr("Throws: {");
   1.676 -      {
   1.677 -        streamIndentor si(str);
   1.678 -        for (int i = 0; i < _throws.length(); ++i) {
   1.679 -          _throws.at(i)->print_on(str);
   1.680 -        }
   1.681 -      }
   1.682 -      str->indent().print_cr("}");
   1.683 -    }
   1.684 -  }
   1.685 -  str->indent().print_cr("}");
   1.686 -}
   1.687 -#endif // ndef PRODUCT
   1.688 -
   1.689 -TypeParameter* TypeParameter::parse_generic_signature(DescriptorStream* STREAM) {
   1.690 -  STREAM->set_mark();
   1.691 -  char c = READ();
   1.692 -  while (c != ':') {
   1.693 -    c = READ();
   1.694 -  }
   1.695 -
   1.696 -  Identifier* id = STREAM->identifier_from_mark();
   1.697 -
   1.698 -  ClassType* class_bound = NULL;
   1.699 -  GrowableArray<ClassType*> interface_bounds(8);
   1.700 -
   1.701 -  c = READ();
   1.702 -  if (c != '>') {
   1.703 -    if (c != ':') {
   1.704 -      EXPECTED(c, 'L');
   1.705 -      class_bound = ClassType::parse_generic_signature(CHECK_STREAM);
   1.706 -      c = READ();
   1.707 -    }
   1.708 -
   1.709 -    while (c == ':') {
   1.710 -      EXPECT('L');
   1.711 -      ClassType* fts = ClassType::parse_generic_signature(CHECK_STREAM);
   1.712 -      interface_bounds.append(fts);
   1.713 -      c = READ();
   1.714 -    }
   1.715 -  }
   1.716 -  PUSH(c);
   1.717 -
   1.718 -  return new TypeParameter(id, class_bound, interface_bounds);
   1.719 -}
   1.720 -
   1.721 -void TypeParameter::bind_variables_to_parameters(Descriptor* sig, int position) {
   1.722 -  if (_class_bound != NULL) {
   1.723 -    _class_bound->bind_variables_to_parameters(sig);
   1.724 -  }
   1.725 -  for (int i = 0; i < _interface_bounds.length(); ++i) {
   1.726 -    _interface_bounds.at(i)->bind_variables_to_parameters(sig);
   1.727 -  }
   1.728 -  _position = position;
   1.729 -}
   1.730 -
   1.731 -Type* TypeParameter::resolve(
   1.732 -    Context* ctx, int inner_depth, int ctx_depth) {
   1.733 -
   1.734 -  if (inner_depth == -1) {
   1.735 -    // This indicates that the parameter is a method type parameter, which
   1.736 -    // isn't resolveable using the class hierarchy context
   1.737 -    return bound();
   1.738 -  }
   1.739 -
   1.740 -  ClassType* provider = ctx->at_depth(ctx_depth);
   1.741 -  if (provider != NULL) {
   1.742 -    for (int i = 0; i < inner_depth && provider != NULL; ++i) {
   1.743 -      provider = provider->outer_class();
   1.744 -    }
   1.745 -    if (provider != NULL) {
   1.746 -      TypeArgument* arg = provider->type_argument_at(_position);
   1.747 -      if (arg != NULL) {
   1.748 -        Type* value = arg->lower_bound();
   1.749 -        return value->canonicalize(ctx, ctx_depth + 1);
   1.750 -      }
   1.751 -    }
   1.752 -  }
   1.753 -
   1.754 -  return bound();
   1.755 -}
   1.756 -
   1.757 -TypeParameter* TypeParameter::canonicalize(Context* ctx, int ctx_depth) {
   1.758 -  ClassType* bound = _class_bound == NULL ? NULL :
   1.759 -     _class_bound->canonicalize(ctx, ctx_depth);
   1.760 -
   1.761 -  GrowableArray<ClassType*> ifaces(_interface_bounds.length());
   1.762 -  for (int i = 0; i < _interface_bounds.length(); ++i) {
   1.763 -    ifaces.append(_interface_bounds.at(i)->canonicalize(ctx, ctx_depth));
   1.764 -  }
   1.765 -
   1.766 -  TypeParameter* ret = new TypeParameter(_identifier, bound, ifaces);
   1.767 -  ret->_position = _position;
   1.768 -  return ret;
   1.769 -}
   1.770 -
   1.771 -ClassType* TypeParameter::bound() {
   1.772 -  if (_class_bound != NULL) {
   1.773 -    return _class_bound;
   1.774 -  }
   1.775 -
   1.776 -  if (_interface_bounds.length() == 1) {
   1.777 -    return _interface_bounds.at(0);
   1.778 -  }
   1.779 -
   1.780 -  return ClassType::java_lang_Object(); // TODO: investigate this case
   1.781 -}
   1.782 -
   1.783 -#ifndef PRODUCT
   1.784 -void TypeParameter::print_on(outputStream* str) const {
   1.785 -  str->indent().print_cr("Formal: {");
   1.786 -  {
   1.787 -    streamIndentor si(str);
   1.788 -
   1.789 -    str->indent().print("Identifier: ");
   1.790 -    _identifier->print_on(str);
   1.791 -    str->print_cr("");
   1.792 -    if (_class_bound != NULL) {
   1.793 -      str->indent().print_cr("Class Bound: ");
   1.794 -      streamIndentor si(str);
   1.795 -      _class_bound->print_on(str);
   1.796 -    }
   1.797 -    if (_interface_bounds.length() > 0) {
   1.798 -      str->indent().print_cr("Interface Bounds: {");
   1.799 -      {
   1.800 -        streamIndentor si(str);
   1.801 -        for (int i = 0; i < _interface_bounds.length(); ++i) {
   1.802 -          _interface_bounds.at(i)->print_on(str);
   1.803 -        }
   1.804 -      }
   1.805 -      str->indent().print_cr("}");
   1.806 -    }
   1.807 -    str->indent().print_cr("Ordinal Position: %d", _position);
   1.808 -  }
   1.809 -  str->indent().print_cr("}");
   1.810 -}
   1.811 -#endif // ndef PRODUCT
   1.812 -
   1.813 -Type* Type::parse_generic_signature(DescriptorStream* STREAM) {
   1.814 -  char c = READ();
   1.815 -  switch (c) {
   1.816 -    case 'L':
   1.817 -      return ClassType::parse_generic_signature(CHECK_STREAM);
   1.818 -    case 'T':
   1.819 -      return TypeVariable::parse_generic_signature(CHECK_STREAM);
   1.820 -    case '[':
   1.821 -      return ArrayType::parse_generic_signature(CHECK_STREAM);
   1.822 -    default:
   1.823 -      return new PrimitiveType(c);
   1.824 -  }
   1.825 -}
   1.826 -
   1.827 -Identifier* ClassType::parse_generic_signature_simple(GrowableArray<TypeArgument*>* args,
   1.828 -    bool* has_inner, DescriptorStream* STREAM) {
   1.829 -  STREAM->set_mark();
   1.830 -
   1.831 -  char c = READ();
   1.832 -  while (c != ';' && c != '.' && c != '<') { c = READ(); }
   1.833 -  Identifier* id = STREAM->identifier_from_mark();
   1.834 -
   1.835 -  if (c == '<') {
   1.836 -    c = READ();
   1.837 -    while (c != '>') {
   1.838 -      PUSH(c);
   1.839 -      TypeArgument* arg = TypeArgument::parse_generic_signature(CHECK_STREAM);
   1.840 -      args->append(arg);
   1.841 -      c = READ();
   1.842 -    }
   1.843 -    c = READ();
   1.844 -  }
   1.845 -
   1.846 -  *has_inner = (c == '.');
   1.847 -  if (!(*has_inner)) {
   1.848 -    EXPECTED(c, ';');
   1.849 -  }
   1.850 -
   1.851 -  return id;
   1.852 -}
   1.853 -
   1.854 -ClassType* ClassType::parse_generic_signature(DescriptorStream* STREAM) {
   1.855 -  return parse_generic_signature(NULL, CHECK_STREAM);
   1.856 -}
   1.857 -
   1.858 -ClassType* ClassType::parse_generic_signature(ClassType* outer, DescriptorStream* STREAM) {
   1.859 -  GrowableArray<TypeArgument*> args;
   1.860 -  ClassType* gct = NULL;
   1.861 -  bool has_inner = false;
   1.862 -
   1.863 -  Identifier* id = parse_generic_signature_simple(&args, &has_inner, STREAM);
   1.864 -  if (id != NULL) {
   1.865 -    gct = new ClassType(id, args, outer);
   1.866 -
   1.867 -    if (has_inner) {
   1.868 -      gct = parse_generic_signature(gct, CHECK_STREAM);
   1.869 -    }
   1.870 -  }
   1.871 -  return gct;
   1.872 -}
   1.873 -
   1.874 -ClassType* ClassType::from_symbol(Symbol* sym) {
   1.875 -  assert(sym != NULL, "Must not be null");
   1.876 -  GrowableArray<TypeArgument*> args;
   1.877 -  Identifier* id = new Identifier(sym, 0, sym->utf8_length());
   1.878 -  return new ClassType(id, args, NULL);
   1.879 -}
   1.880 -
   1.881 -ClassType* ClassType::java_lang_Object() {
   1.882 -  return from_symbol(vmSymbols::java_lang_Object());
   1.883 -}
   1.884 -
   1.885 -void ClassType::bind_variables_to_parameters(Descriptor* sig) {
   1.886 -  for (int i = 0; i < _type_arguments.length(); ++i) {
   1.887 -    _type_arguments.at(i)->bind_variables_to_parameters(sig);
   1.888 -  }
   1.889 -  if (_outer_class != NULL) {
   1.890 -    _outer_class->bind_variables_to_parameters(sig);
   1.891 -  }
   1.892 -}
   1.893 -
   1.894 -TypeArgument* ClassType::type_argument_at(int i) {
   1.895 -  if (i >= 0 && i < _type_arguments.length()) {
   1.896 -    return _type_arguments.at(i);
   1.897 -  } else {
   1.898 -    return NULL;
   1.899 -  }
   1.900 -}
   1.901 -
   1.902 -#ifndef PRODUCT
   1.903 -void ClassType::reify_signature(stringStream* ss, Context* ctx) {
   1.904 -  ss->print("L");
   1.905 -  _identifier->print_on(ss);
   1.906 -  ss->print(";");
   1.907 -}
   1.908 -
   1.909 -void ClassType::print_on(outputStream* str) const {
   1.910 -  str->indent().print_cr("Class {");
   1.911 -  {
   1.912 -    streamIndentor si(str);
   1.913 -    str->indent().print("Name: ");
   1.914 -    _identifier->print_on(str);
   1.915 -    str->print_cr("");
   1.916 -    if (_type_arguments.length() != 0) {
   1.917 -      str->indent().print_cr("Type Arguments: {");
   1.918 -      {
   1.919 -        streamIndentor si(str);
   1.920 -        for (int j = 0; j < _type_arguments.length(); ++j) {
   1.921 -          _type_arguments.at(j)->print_on(str);
   1.922 -        }
   1.923 -      }
   1.924 -      str->indent().print_cr("}");
   1.925 -    }
   1.926 -    if (_outer_class != NULL) {
   1.927 -      str->indent().print_cr("Outer Class: ");
   1.928 -      streamIndentor sir(str);
   1.929 -      _outer_class->print_on(str);
   1.930 -    }
   1.931 -  }
   1.932 -  str->indent().print_cr("}");
   1.933 -}
   1.934 -#endif // ndef PRODUCT
   1.935 -
   1.936 -bool ClassType::covariant_match(Type* other, Context* ctx) {
   1.937 -
   1.938 -  if (other == this) {
   1.939 -    return true;
   1.940 -  }
   1.941 -
   1.942 -  TypeVariable* variable = other->as_variable();
   1.943 -  if (variable != NULL) {
   1.944 -    other = variable->resolve(ctx, 0);
   1.945 -  }
   1.946 -
   1.947 -  ClassType* outer = outer_class();
   1.948 -  ClassType* other_class = other->as_class();
   1.949 -
   1.950 -  if (other_class == NULL ||
   1.951 -      (outer == NULL) != (other_class->outer_class() == NULL)) {
   1.952 -    return false;
   1.953 -  }
   1.954 -
   1.955 -  if (!_identifier->equals(other_class->_identifier)) {
   1.956 -    return false;
   1.957 -  }
   1.958 -
   1.959 -  if (outer != NULL && !outer->covariant_match(other_class->outer_class(), ctx)) {
   1.960 -    return false;
   1.961 -  }
   1.962 -
   1.963 -  return true;
   1.964 -}
   1.965 -
   1.966 -ClassType* ClassType::canonicalize(Context* ctx, int ctx_depth) {
   1.967 -
   1.968 -  GrowableArray<TypeArgument*> args(_type_arguments.length());
   1.969 -  for (int i = 0; i < _type_arguments.length(); ++i) {
   1.970 -    args.append(_type_arguments.at(i)->canonicalize(ctx, ctx_depth));
   1.971 -  }
   1.972 -
   1.973 -  ClassType* outer = _outer_class == NULL ? NULL :
   1.974 -      _outer_class->canonicalize(ctx, ctx_depth);
   1.975 -
   1.976 -  return new ClassType(_identifier, args, outer);
   1.977 -}
   1.978 -
   1.979 -TypeVariable* TypeVariable::parse_generic_signature(DescriptorStream* STREAM) {
   1.980 -  STREAM->set_mark();
   1.981 -  char c = READ();
   1.982 -  while (c != ';') {
   1.983 -    c = READ();
   1.984 -  }
   1.985 -  Identifier* id = STREAM->identifier_from_mark();
   1.986 -
   1.987 -  return new TypeVariable(id);
   1.988 -}
   1.989 -
   1.990 -void TypeVariable::bind_variables_to_parameters(Descriptor* sig) {
   1.991 -  _parameter = sig->find_type_parameter(_id, &_inner_depth);
   1.992 -  if (VerifyGenericSignatures && _parameter == NULL) {
   1.993 -    fatal("Could not find formal parameter");
   1.994 -  }
   1.995 -}
   1.996 -
   1.997 -Type* TypeVariable::resolve(Context* ctx, int ctx_depth) {
   1.998 -  if (parameter() != NULL) {
   1.999 -    return parameter()->resolve(ctx, inner_depth(), ctx_depth);
  1.1000 -  } else {
  1.1001 -    if (VerifyGenericSignatures) {
  1.1002 -      fatal("Type variable matches no parameter");
  1.1003 -    }
  1.1004 -    return NULL;
  1.1005 -  }
  1.1006 -}
  1.1007 -
  1.1008 -bool TypeVariable::covariant_match(Type* other, Context* ctx) {
  1.1009 -
  1.1010 -  if (other == this) {
  1.1011 -    return true;
  1.1012 -  }
  1.1013 -
  1.1014 -  Context my_context(NULL); // empty, results in erasure
  1.1015 -  Type* my_type = resolve(&my_context, 0);
  1.1016 -  if (my_type == NULL) {
  1.1017 -    return false;
  1.1018 -  }
  1.1019 -
  1.1020 -  return my_type->covariant_match(other, ctx);
  1.1021 -}
  1.1022 -
  1.1023 -Type* TypeVariable::canonicalize(Context* ctx, int ctx_depth) {
  1.1024 -  return resolve(ctx, ctx_depth);
  1.1025 -}
  1.1026 -
  1.1027 -#ifndef PRODUCT
  1.1028 -void TypeVariable::reify_signature(stringStream* ss, Context* ctx) {
  1.1029 -  Type* type = resolve(ctx, 0);
  1.1030 -  if (type != NULL) {
  1.1031 -    type->reify_signature(ss, ctx);
  1.1032 -  }
  1.1033 -}
  1.1034 -
  1.1035 -void TypeVariable::print_on(outputStream* str) const {
  1.1036 -  str->indent().print_cr("Type Variable {");
  1.1037 -  {
  1.1038 -    streamIndentor si(str);
  1.1039 -    str->indent().print("Name: ");
  1.1040 -    _id->print_on(str);
  1.1041 -    str->print_cr("");
  1.1042 -    str->indent().print_cr("Inner depth: %d", _inner_depth);
  1.1043 -  }
  1.1044 -  str->indent().print_cr("}");
  1.1045 -}
  1.1046 -#endif // ndef PRODUCT
  1.1047 -
  1.1048 -ArrayType* ArrayType::parse_generic_signature(DescriptorStream* STREAM) {
  1.1049 -  Type* base = Type::parse_generic_signature(CHECK_STREAM);
  1.1050 -  return new ArrayType(base);
  1.1051 -}
  1.1052 -
  1.1053 -void ArrayType::bind_variables_to_parameters(Descriptor* sig) {
  1.1054 -  assert(_base != NULL, "Invalid base");
  1.1055 -  _base->bind_variables_to_parameters(sig);
  1.1056 -}
  1.1057 -
  1.1058 -bool ArrayType::covariant_match(Type* other, Context* ctx) {
  1.1059 -  assert(_base != NULL, "Invalid base");
  1.1060 -
  1.1061 -  if (other == this) {
  1.1062 -    return true;
  1.1063 -  }
  1.1064 -
  1.1065 -  ArrayType* other_array = other->as_array();
  1.1066 -  return (other_array != NULL && _base->covariant_match(other_array->_base, ctx));
  1.1067 -}
  1.1068 -
  1.1069 -ArrayType* ArrayType::canonicalize(Context* ctx, int ctx_depth) {
  1.1070 -  assert(_base != NULL, "Invalid base");
  1.1071 -  return new ArrayType(_base->canonicalize(ctx, ctx_depth));
  1.1072 -}
  1.1073 -
  1.1074 -#ifndef PRODUCT
  1.1075 -void ArrayType::reify_signature(stringStream* ss, Context* ctx) {
  1.1076 -  assert(_base != NULL, "Invalid base");
  1.1077 -  ss->print("[");
  1.1078 -  _base->reify_signature(ss, ctx);
  1.1079 -}
  1.1080 -
  1.1081 -void ArrayType::print_on(outputStream* str) const {
  1.1082 -  str->indent().print_cr("Array {");
  1.1083 -  {
  1.1084 -    streamIndentor si(str);
  1.1085 -    _base->print_on(str);
  1.1086 -  }
  1.1087 -  str->indent().print_cr("}");
  1.1088 -}
  1.1089 -#endif // ndef PRODUCT
  1.1090 -
  1.1091 -bool PrimitiveType::covariant_match(Type* other, Context* ctx) {
  1.1092 -
  1.1093 -  PrimitiveType* other_prim = other->as_primitive();
  1.1094 -  return (other_prim != NULL && _type == other_prim->_type);
  1.1095 -}
  1.1096 -
  1.1097 -PrimitiveType* PrimitiveType::canonicalize(Context* ctx, int ctxd) {
  1.1098 -  return this;
  1.1099 -}
  1.1100 -
  1.1101 -#ifndef PRODUCT
  1.1102 -void PrimitiveType::reify_signature(stringStream* ss, Context* ctx) {
  1.1103 -  ss->print("%c", _type);
  1.1104 -}
  1.1105 -
  1.1106 -void PrimitiveType::print_on(outputStream* str) const {
  1.1107 -  str->indent().print_cr("Primitive: '%c'", _type);
  1.1108 -}
  1.1109 -#endif // ndef PRODUCT
  1.1110 -
  1.1111 -void PrimitiveType::bind_variables_to_parameters(Descriptor* sig) {
  1.1112 -}
  1.1113 -
  1.1114 -TypeArgument* TypeArgument::parse_generic_signature(DescriptorStream* STREAM) {
  1.1115 -  char c = READ();
  1.1116 -  Type* type = NULL;
  1.1117 -
  1.1118 -  switch (c) {
  1.1119 -    case '*':
  1.1120 -      return new TypeArgument(ClassType::java_lang_Object(), NULL);
  1.1121 -      break;
  1.1122 -    default:
  1.1123 -      PUSH(c);
  1.1124 -      // fall-through
  1.1125 -    case '+':
  1.1126 -    case '-':
  1.1127 -      type = Type::parse_generic_signature(CHECK_STREAM);
  1.1128 -      if (c == '+') {
  1.1129 -        return new TypeArgument(type, NULL);
  1.1130 -      } else if (c == '-') {
  1.1131 -        return new TypeArgument(ClassType::java_lang_Object(), type);
  1.1132 -      } else {
  1.1133 -        return new TypeArgument(type, type);
  1.1134 -      }
  1.1135 -  }
  1.1136 -}
  1.1137 -
  1.1138 -void TypeArgument::bind_variables_to_parameters(Descriptor* sig) {
  1.1139 -  assert(_lower_bound != NULL, "Invalid lower bound");
  1.1140 -  _lower_bound->bind_variables_to_parameters(sig);
  1.1141 -  if (_upper_bound != NULL && _upper_bound != _lower_bound) {
  1.1142 -    _upper_bound->bind_variables_to_parameters(sig);
  1.1143 -  }
  1.1144 -}
  1.1145 -
  1.1146 -bool TypeArgument::covariant_match(TypeArgument* other, Context* ctx) {
  1.1147 -  assert(_lower_bound != NULL, "Invalid lower bound");
  1.1148 -
  1.1149 -  if (other == this) {
  1.1150 -    return true;
  1.1151 -  }
  1.1152 -
  1.1153 -  if (!_lower_bound->covariant_match(other->lower_bound(), ctx)) {
  1.1154 -    return false;
  1.1155 -  }
  1.1156 -  return true;
  1.1157 -}
  1.1158 -
  1.1159 -TypeArgument* TypeArgument::canonicalize(Context* ctx, int ctx_depth) {
  1.1160 -  assert(_lower_bound != NULL, "Invalid lower bound");
  1.1161 -  Type* lower = _lower_bound->canonicalize(ctx, ctx_depth);
  1.1162 -  Type* upper = NULL;
  1.1163 -
  1.1164 -  if (_upper_bound == _lower_bound) {
  1.1165 -    upper = lower;
  1.1166 -  } else if (_upper_bound != NULL) {
  1.1167 -    upper = _upper_bound->canonicalize(ctx, ctx_depth);
  1.1168 -  }
  1.1169 -
  1.1170 -  return new TypeArgument(lower, upper);
  1.1171 -}
  1.1172 -
  1.1173 -#ifndef PRODUCT
  1.1174 -void TypeArgument::print_on(outputStream* str) const {
  1.1175 -  str->indent().print_cr("TypeArgument {");
  1.1176 -  {
  1.1177 -    streamIndentor si(str);
  1.1178 -    if (_lower_bound != NULL) {
  1.1179 -      str->indent().print("Lower bound: ");
  1.1180 -      _lower_bound->print_on(str);
  1.1181 -    }
  1.1182 -    if (_upper_bound != NULL) {
  1.1183 -      str->indent().print("Upper bound: ");
  1.1184 -      _upper_bound->print_on(str);
  1.1185 -    }
  1.1186 -  }
  1.1187 -  str->indent().print_cr("}");
  1.1188 -}
  1.1189 -#endif // ndef PRODUCT
  1.1190 -
  1.1191 -void Context::Mark::destroy() {
  1.1192 -  if (is_active()) {
  1.1193 -    _context->reset_to_mark(_marked_size);
  1.1194 -  }
  1.1195 -  deactivate();
  1.1196 -}
  1.1197 -
  1.1198 -void Context::apply_type_arguments(
  1.1199 -    InstanceKlass* current, InstanceKlass* super, TRAPS) {
  1.1200 -  assert(_cache != NULL, "Cannot use an empty context");
  1.1201 -  ClassType* spec = NULL;
  1.1202 -  if (current != NULL) {
  1.1203 -    ClassDescriptor* descriptor = _cache->descriptor_for(current, CHECK);
  1.1204 -    if (super == current->super()) {
  1.1205 -      spec = descriptor->super();
  1.1206 -    } else {
  1.1207 -      spec = descriptor->interface_desc(super->name());
  1.1208 -    }
  1.1209 -    if (spec != NULL) {
  1.1210 -      _type_arguments.push(spec);
  1.1211 -    }
  1.1212 -  }
  1.1213 -}
  1.1214 -
  1.1215 -void Context::reset_to_mark(int size) {
  1.1216 -  _type_arguments.trunc_to(size);
  1.1217 -}
  1.1218 -
  1.1219 -ClassType* Context::at_depth(int i) const {
  1.1220 -  if (i < _type_arguments.length()) {
  1.1221 -    return _type_arguments.at(_type_arguments.length() - 1 - i);
  1.1222 -  }
  1.1223 -  return NULL;
  1.1224 -}
  1.1225 -
  1.1226 -#ifndef PRODUCT
  1.1227 -void Context::print_on(outputStream* str) const {
  1.1228 -  str->indent().print_cr("Context {");
  1.1229 -  for (int i = 0; i < _type_arguments.length(); ++i) {
  1.1230 -    streamIndentor si(str);
  1.1231 -    str->indent().print("leval %d: ", i);
  1.1232 -    ClassType* ct = at_depth(i);
  1.1233 -    if (ct == NULL) {
  1.1234 -      str->print_cr("<empty>");
  1.1235 -      continue;
  1.1236 -    } else {
  1.1237 -      str->print_cr("{");
  1.1238 -    }
  1.1239 -
  1.1240 -    for (int j = 0; j < ct->type_arguments_length(); ++j) {
  1.1241 -      streamIndentor si(str);
  1.1242 -      TypeArgument* ta = ct->type_argument_at(j);
  1.1243 -      Type* bound = ta->lower_bound();
  1.1244 -      bound->print_on(str);
  1.1245 -    }
  1.1246 -    str->indent().print_cr("}");
  1.1247 -  }
  1.1248 -  str->indent().print_cr("}");
  1.1249 -}
  1.1250 -#endif // ndef PRODUCT
  1.1251 -
  1.1252 -ClassDescriptor* DescriptorCache::descriptor_for(InstanceKlass* ik, TRAPS) {
  1.1253 -
  1.1254 -  ClassDescriptor** existing = _class_descriptors.get(ik);
  1.1255 -  if (existing == NULL) {
  1.1256 -    ClassDescriptor* cd = ClassDescriptor::parse_generic_signature(ik, CHECK_NULL);
  1.1257 -    _class_descriptors.put(ik, cd);
  1.1258 -    return cd;
  1.1259 -  } else {
  1.1260 -    return *existing;
  1.1261 -  }
  1.1262 -}
  1.1263 -
  1.1264 -MethodDescriptor* DescriptorCache::descriptor_for(
  1.1265 -    Method* mh, ClassDescriptor* cd, TRAPS) {
  1.1266 -  assert(mh != NULL && cd != NULL, "Should not be NULL");
  1.1267 -  MethodDescriptor** existing = _method_descriptors.get(mh);
  1.1268 -  if (existing == NULL) {
  1.1269 -    MethodDescriptor* md = MethodDescriptor::parse_generic_signature(mh, cd);
  1.1270 -    _method_descriptors.put(mh, md);
  1.1271 -    return md;
  1.1272 -  } else {
  1.1273 -    return *existing;
  1.1274 -  }
  1.1275 -}
  1.1276 -MethodDescriptor* DescriptorCache::descriptor_for(Method* mh, TRAPS) {
  1.1277 -  ClassDescriptor* cd = descriptor_for(
  1.1278 -      InstanceKlass::cast(mh->method_holder()), CHECK_NULL);
  1.1279 -  return descriptor_for(mh, cd, THREAD);
  1.1280 -}
  1.1281 -
  1.1282 -} // namespace generic

mercurial