ciSignature.cpp revision 2062:3582bf76420e
11573Srgrimes/*
21573Srgrimes * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
31573Srgrimes * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
41573Srgrimes *
51573Srgrimes * This code is free software; you can redistribute it and/or modify it
61573Srgrimes * under the terms of the GNU General Public License version 2 only, as
71573Srgrimes * published by the Free Software Foundation.
81573Srgrimes *
91573Srgrimes * This code is distributed in the hope that it will be useful, but WITHOUT
101573Srgrimes * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
111573Srgrimes * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
121573Srgrimes * version 2 for more details (a copy is included in the LICENSE file that
131573Srgrimes * accompanied this code).
141573Srgrimes *
151573Srgrimes * You should have received a copy of the GNU General Public License version
16249808Semaste * 2 along with this work; if not, write to the Free Software Foundation,
171573Srgrimes * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
181573Srgrimes *
191573Srgrimes * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
201573Srgrimes * or visit www.oracle.com if you need additional information or have any
211573Srgrimes * questions.
221573Srgrimes *
231573Srgrimes */
241573Srgrimes
251573Srgrimes#include "precompiled.hpp"
261573Srgrimes#include "ci/ciSignature.hpp"
271573Srgrimes#include "ci/ciUtilities.hpp"
281573Srgrimes#include "memory/allocation.inline.hpp"
291573Srgrimes#include "oops/oop.inline.hpp"
301573Srgrimes#include "runtime/signature.hpp"
311573Srgrimes
321573Srgrimes// ciSignature
331573Srgrimes//
341573Srgrimes// This class represents the signature of a method.
351573Srgrimes
3692986Sobrien// ------------------------------------------------------------------
3792986Sobrien// ciSignature::ciSignature
381573SrgrimesciSignature::ciSignature(ciKlass* accessing_klass, ciSymbol* symbol) {
3971579Sdeischen  ASSERT_IN_VM;
401573Srgrimes  EXCEPTION_CONTEXT;
411573Srgrimes  _accessing_klass = accessing_klass;
4271579Sdeischen  _symbol = symbol;
431573Srgrimes
4435129Sjb  ciEnv* env = CURRENT_ENV;
451573Srgrimes  Arena* arena = env->arena();
461573Srgrimes  _types = new (arena) GrowableArray<ciType*>(arena, 8, 0, NULL);
471573Srgrimes
481573Srgrimes  int size = 0;
491573Srgrimes  int count = 0;
5013545Sjulian  ResourceMark rm(THREAD);
51103012Stjr  Symbol* sh = symbol->get_symbol();
521573Srgrimes  SignatureStream ss(sh);
5392889Sobrien  for (; ; ss.next()) {
541573Srgrimes    // Process one element of the signature
551573Srgrimes    ciType* type;
561573Srgrimes    if (!ss.is_object()) {
571573Srgrimes      type = ciType::make(ss.type());
581573Srgrimes    } else {
591573Srgrimes      Symbol* name = ss.as_symbol(THREAD);
601573Srgrimes      if (HAS_PENDING_EXCEPTION) {
611573Srgrimes        type = ss.is_array() ? (ciType*)ciEnv::unloaded_ciobjarrayklass()
621573Srgrimes          : (ciType*)ciEnv::unloaded_ciinstance_klass();
631573Srgrimes        env->record_out_of_memory_failure();
641573Srgrimes        CLEAR_PENDING_EXCEPTION;
651573Srgrimes      } else {
66320942Skib        ciSymbol* klass_name = env->get_symbol(name);
671573Srgrimes        type = env->get_klass_by_name_impl(_accessing_klass, klass_name, false);
681573Srgrimes      }
691573Srgrimes    }
701573Srgrimes    _types->append(type);
711573Srgrimes    if (ss.at_return_type()) {
721573Srgrimes      // Done processing the return type; do not add it into the count.
731573Srgrimes      break;
741573Srgrimes    }
751573Srgrimes    size += type->size();
761573Srgrimes    count++;
771573Srgrimes  }
781573Srgrimes  _size = size;
791573Srgrimes  _count = count;
801573Srgrimes}
8182839Sache
821573Srgrimes// ------------------------------------------------------------------
831573Srgrimes// ciSignature::return_ciType
841573Srgrimes//
851573Srgrimes// What is the return type of this signature?
861573SrgrimesciType* ciSignature::return_type() const {
871573Srgrimes  return _types->at(_count);
881573Srgrimes}
891573Srgrimes
901573Srgrimes// ------------------------------------------------------------------
911573Srgrimes// ciSignature::ciType_at
921573Srgrimes//
931573Srgrimes// What is the type of the index'th element of this
941573Srgrimes// signature?
951573SrgrimesciType* ciSignature::type_at(int index) const {
961573Srgrimes  assert(index < _count, "out of bounds");
971573Srgrimes  // The first _klasses element holds the return klass.
981573Srgrimes  return _types->at(index);
991573Srgrimes}
1001573Srgrimes
1011573Srgrimes// ------------------------------------------------------------------
1021573Srgrimes// ciSignature::print_signature
1031573Srgrimesvoid ciSignature::print_signature() {
1041573Srgrimes  _symbol->print_symbol();
1051573Srgrimes}
1061573Srgrimes
1071573Srgrimes// ------------------------------------------------------------------
1081573Srgrimes// ciSignature::print
1091573Srgrimesvoid ciSignature::print() {
1101573Srgrimes  tty->print("<ciSignature symbol=");
1111573Srgrimes  print_signature();
1121573Srgrimes tty->print(" accessing_klass=");
1131573Srgrimes  _accessing_klass->print();
1141573Srgrimes  tty->print(" address=0x%x>", (address)this);
1151573Srgrimes}
1161573Srgrimes