ciSignature.cpp revision 1472:c18cbe5936b8
1285SN/A/*
2462SN/A * Copyright (c) 1999, 2007, Oracle and/or its affiliates. All rights reserved.
3285SN/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4285SN/A *
5285SN/A * This code is free software; you can redistribute it and/or modify it
6285SN/A * under the terms of the GNU General Public License version 2 only, as
7285SN/A * published by the Free Software Foundation.
8285SN/A *
9285SN/A * This code is distributed in the hope that it will be useful, but WITHOUT
10285SN/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11285SN/A * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12285SN/A * version 2 for more details (a copy is included in the LICENSE file that
13285SN/A * accompanied this code).
14285SN/A *
15285SN/A * You should have received a copy of the GNU General Public License version
16285SN/A * 2 along with this work; if not, write to the Free Software Foundation,
17285SN/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18285SN/A *
19285SN/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20285SN/A * or visit www.oracle.com if you need additional information or have any
21285SN/A * questions.
22285SN/A *
23285SN/A */
24285SN/A
25285SN/A#include "incls/_precompiled.incl"
26285SN/A#include "incls/_ciSignature.cpp.incl"
27285SN/A
28285SN/A// ciSignature
29285SN/A//
30285SN/A// This class represents the signature of a method.
31285SN/A
32285SN/A// ------------------------------------------------------------------
33285SN/A// ciSignature::ciSignature
34285SN/AciSignature::ciSignature(ciKlass* accessing_klass, ciSymbol* symbol) {
35285SN/A  ASSERT_IN_VM;
36285SN/A  EXCEPTION_CONTEXT;
37285SN/A  _accessing_klass = accessing_klass;
38285SN/A  _symbol = symbol;
39285SN/A
40285SN/A  ciEnv* env = CURRENT_ENV;
41285SN/A  Arena* arena = env->arena();
42285SN/A  _types = new (arena) GrowableArray<ciType*>(arena, 8, 0, NULL);
43285SN/A
44285SN/A  int size = 0;
45285SN/A  int count = 0;
46285SN/A  symbolHandle sh (THREAD, symbol->get_symbolOop());
47285SN/A  SignatureStream ss(sh);
48285SN/A  for (; ; ss.next()) {
49285SN/A    // Process one element of the signature
50285SN/A    ciType* type;
51285SN/A    if (!ss.is_object()) {
52285SN/A      type = ciType::make(ss.type());
53285SN/A    } else {
54285SN/A      symbolOop name = ss.as_symbol(THREAD);
55285SN/A      if (HAS_PENDING_EXCEPTION) {
56285SN/A        type = ss.is_array() ? (ciType*)ciEnv::unloaded_ciobjarrayklass()
57285SN/A          : (ciType*)ciEnv::unloaded_ciinstance_klass();
58285SN/A        env->record_out_of_memory_failure();
59285SN/A        CLEAR_PENDING_EXCEPTION;
60285SN/A      } else {
61285SN/A        ciSymbol* klass_name = env->get_object(name)->as_symbol();
62285SN/A        type = env->get_klass_by_name_impl(_accessing_klass, klass_name, false);
63285SN/A      }
64285SN/A    }
65285SN/A    _types->append(type);
66285SN/A    if (ss.at_return_type()) {
67285SN/A      // Done processing the return type; do not add it into the count.
68285SN/A      break;
69285SN/A    }
70285SN/A    size += type->size();
71285SN/A    count++;
72285SN/A  }
73285SN/A  _size = size;
74285SN/A  _count = count;
75285SN/A}
76285SN/A
77285SN/A// ------------------------------------------------------------------
78285SN/A// ciSignature::return_ciType
79285SN/A//
80285SN/A// What is the return type of this signature?
81285SN/AciType* ciSignature::return_type() const {
82285SN/A  return _types->at(_count);
83285SN/A}
84285SN/A
85285SN/A// ------------------------------------------------------------------
86285SN/A// ciSignature::ciType_at
87285SN/A//
88285SN/A// What is the type of the index'th element of this
89285SN/A// signature?
90285SN/AciType* ciSignature::type_at(int index) const {
91285SN/A  assert(index < _count, "out of bounds");
92285SN/A  // The first _klasses element holds the return klass.
93285SN/A  return _types->at(index);
94285SN/A}
95285SN/A
96285SN/A// ------------------------------------------------------------------
97285SN/A// ciSignature::print_signature
98285SN/Avoid ciSignature::print_signature() {
99285SN/A  _symbol->print_symbol();
100285SN/A}
101285SN/A
102285SN/A// ------------------------------------------------------------------
103285SN/A// ciSignature::print
104285SN/Avoid ciSignature::print() {
105285SN/A  tty->print("<ciSignature symbol=");
106285SN/A  print_signature();
107285SN/A tty->print(" accessing_klass=");
108285SN/A  _accessing_klass->print();
109285SN/A  tty->print(" address=0x%x>", (address)this);
110285SN/A}
111285SN/A