src/share/vm/ci/ciSignature.cpp

changeset 0
f90c822e73f8
child 6876
710a3c8b516e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/ci/ciSignature.cpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,152 @@
     1.4 +/*
     1.5 + * Copyright (c) 1999, 2014, 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 +#include "ci/ciMethodType.hpp"
    1.30 +#include "ci/ciSignature.hpp"
    1.31 +#include "ci/ciUtilities.hpp"
    1.32 +#include "memory/allocation.inline.hpp"
    1.33 +#include "oops/oop.inline.hpp"
    1.34 +#include "runtime/signature.hpp"
    1.35 +
    1.36 +// ciSignature
    1.37 +//
    1.38 +// This class represents the signature of a method.
    1.39 +
    1.40 +// ------------------------------------------------------------------
    1.41 +// ciSignature::ciSignature
    1.42 +ciSignature::ciSignature(ciKlass* accessing_klass, constantPoolHandle cpool, ciSymbol* symbol) {
    1.43 +  ASSERT_IN_VM;
    1.44 +  EXCEPTION_CONTEXT;
    1.45 +  _accessing_klass = accessing_klass;
    1.46 +  _symbol = symbol;
    1.47 +
    1.48 +  ciEnv* env = CURRENT_ENV;
    1.49 +  Arena* arena = env->arena();
    1.50 +  _types = new (arena) GrowableArray<ciType*>(arena, 8, 0, NULL);
    1.51 +
    1.52 +  int size = 0;
    1.53 +  int count = 0;
    1.54 +  ResourceMark rm(THREAD);
    1.55 +  Symbol* sh = symbol->get_symbol();
    1.56 +  SignatureStream ss(sh);
    1.57 +  for (; ; ss.next()) {
    1.58 +    // Process one element of the signature
    1.59 +    ciType* type;
    1.60 +    if (!ss.is_object()) {
    1.61 +      type = ciType::make(ss.type());
    1.62 +    } else {
    1.63 +      Symbol* name = ss.as_symbol(THREAD);
    1.64 +      if (HAS_PENDING_EXCEPTION) {
    1.65 +        type = ss.is_array() ? (ciType*)ciEnv::unloaded_ciobjarrayklass()
    1.66 +          : (ciType*)ciEnv::unloaded_ciinstance_klass();
    1.67 +        env->record_out_of_memory_failure();
    1.68 +        CLEAR_PENDING_EXCEPTION;
    1.69 +      } else {
    1.70 +        ciSymbol* klass_name = env->get_symbol(name);
    1.71 +        type = env->get_klass_by_name_impl(_accessing_klass, cpool, klass_name, false);
    1.72 +      }
    1.73 +    }
    1.74 +    _types->append(type);
    1.75 +    if (ss.at_return_type()) {
    1.76 +      // Done processing the return type; do not add it into the count.
    1.77 +      break;
    1.78 +    }
    1.79 +    size += type->size();
    1.80 +    count++;
    1.81 +  }
    1.82 +  _size = size;
    1.83 +  _count = count;
    1.84 +}
    1.85 +
    1.86 +// ------------------------------------------------------------------
    1.87 +// ciSignature::ciSignature
    1.88 +ciSignature::ciSignature(ciKlass* accessing_klass, ciSymbol* symbol, ciMethodType* method_type) :
    1.89 +  _symbol(symbol),
    1.90 +  _accessing_klass(accessing_klass),
    1.91 +  _size( method_type->ptype_slot_count()),
    1.92 +  _count(method_type->ptype_count())
    1.93 +{
    1.94 +  ASSERT_IN_VM;
    1.95 +  EXCEPTION_CONTEXT;
    1.96 +  Arena* arena = CURRENT_ENV->arena();
    1.97 +  _types = new (arena) GrowableArray<ciType*>(arena, _count + 1, 0, NULL);
    1.98 +  for (int i = 0; i < _count; i++) {
    1.99 +    _types->append(method_type->ptype_at(i));
   1.100 +  }
   1.101 +  _types->append(method_type->rtype());
   1.102 +}
   1.103 +
   1.104 +// ------------------------------------------------------------------
   1.105 +// ciSignature::return_type
   1.106 +//
   1.107 +// What is the return type of this signature?
   1.108 +ciType* ciSignature::return_type() const {
   1.109 +  return _types->at(_count);
   1.110 +}
   1.111 +
   1.112 +// ------------------------------------------------------------------
   1.113 +// ciSignature::type_at
   1.114 +//
   1.115 +// What is the type of the index'th element of this
   1.116 +// signature?
   1.117 +ciType* ciSignature::type_at(int index) const {
   1.118 +  assert(index < _count, "out of bounds");
   1.119 +  // The first _klasses element holds the return klass.
   1.120 +  return _types->at(index);
   1.121 +}
   1.122 +
   1.123 +// ------------------------------------------------------------------
   1.124 +// ciSignature::equals
   1.125 +//
   1.126 +// Compare this signature to another one.  Signatures with different
   1.127 +// accessing classes but with signature-types resolved to the same
   1.128 +// types are defined to be equal.
   1.129 +bool ciSignature::equals(ciSignature* that) {
   1.130 +  // Compare signature
   1.131 +  if (!this->as_symbol()->equals(that->as_symbol()))  return false;
   1.132 +  // Compare all types of the arguments
   1.133 +  for (int i = 0; i < _count; i++) {
   1.134 +    if (this->type_at(i) != that->type_at(i))         return false;
   1.135 +  }
   1.136 +  // Compare the return type
   1.137 +  if (this->return_type() != that->return_type())     return false;
   1.138 +  return true;
   1.139 +}
   1.140 +
   1.141 +// ------------------------------------------------------------------
   1.142 +// ciSignature::print_signature
   1.143 +void ciSignature::print_signature() {
   1.144 +  _symbol->print_symbol();
   1.145 +}
   1.146 +
   1.147 +// ------------------------------------------------------------------
   1.148 +// ciSignature::print
   1.149 +void ciSignature::print() {
   1.150 +  tty->print("<ciSignature symbol=");
   1.151 +  print_signature();
   1.152 + tty->print(" accessing_klass=");
   1.153 +  _accessing_klass->print();
   1.154 +  tty->print(" address=" INTPTR_FORMAT ">", p2i((address)this));
   1.155 +}

mercurial