src/hotspot/share/ci/ciSignature.cpp
author coleenp
Fri, 16 Mar 2018 09:12:13 -0400
changeset 49449 ef5d5d343e2a
parent 47216 71c04702a3d5
child 54847 59ea39bb2809
permissions -rw-r--r--
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files Summary: interfaceSupport.hpp is an inline file so moved to interfaceSupport.inline.hpp and stopped including it in .hpp files Reviewed-by: stefank, rehn, kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
37248
11a660dbbb8e 8132524: Missing includes to resourceArea.hpp
jprovino
parents: 33593
diff changeset
     2
 * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#include "precompiled.hpp"
13929
8da0dc50a6e4 7200949: JSR 292: rubybench/bench/time/bench_base64.rb fails with jruby.jar not on boot class path
twisti
parents: 10734
diff changeset
    26
#include "ci/ciMethodType.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#include "ci/ciSignature.hpp"
49449
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 47216
diff changeset
    28
#include "ci/ciUtilities.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "memory/allocation.inline.hpp"
37248
11a660dbbb8e 8132524: Missing includes to resourceArea.hpp
jprovino
parents: 33593
diff changeset
    30
#include "memory/resourceArea.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "oops/oop.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
#include "runtime/signature.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
// ciSignature
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
// This class represents the signature of a method.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
// ciSignature::ciSignature
33593
60764a78fa5c 8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents: 24424
diff changeset
    40
ciSignature::ciSignature(ciKlass* accessing_klass, const constantPoolHandle& cpool, ciSymbol* symbol) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  ASSERT_IN_VM;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  EXCEPTION_CONTEXT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  _accessing_klass = accessing_klass;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  _symbol = symbol;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  ciEnv* env = CURRENT_ENV;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  Arena* arena = env->arena();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  _types = new (arena) GrowableArray<ciType*>(arena, 8, 0, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  int size = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  int count = 0;
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    52
  ResourceMark rm(THREAD);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    53
  Symbol* sh = symbol->get_symbol();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  SignatureStream ss(sh);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  for (; ; ss.next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
    // Process one element of the signature
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
    ciType* type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    if (!ss.is_object()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
      type = ciType::make(ss.type());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
    } else {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    61
      Symbol* name = ss.as_symbol(THREAD);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
      if (HAS_PENDING_EXCEPTION) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
        type = ss.is_array() ? (ciType*)ciEnv::unloaded_ciobjarrayklass()
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
          : (ciType*)ciEnv::unloaded_ciinstance_klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
        env->record_out_of_memory_failure();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
        CLEAR_PENDING_EXCEPTION;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
      } else {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    68
        ciSymbol* klass_name = env->get_symbol(name);
10008
d84de97ad847 7056328: JSR 292 invocation sometimes fails in adapters for types not on boot class path
jrose
parents: 8921
diff changeset
    69
        type = env->get_klass_by_name_impl(_accessing_klass, cpool, klass_name, false);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
    _types->append(type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    if (ss.at_return_type()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
      // Done processing the return type; do not add it into the count.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    size += type->size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
    count++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  _size = size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  _count = count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
// ------------------------------------------------------------------
13929
8da0dc50a6e4 7200949: JSR 292: rubybench/bench/time/bench_base64.rb fails with jruby.jar not on boot class path
twisti
parents: 10734
diff changeset
    85
// ciSignature::ciSignature
8da0dc50a6e4 7200949: JSR 292: rubybench/bench/time/bench_base64.rb fails with jruby.jar not on boot class path
twisti
parents: 10734
diff changeset
    86
ciSignature::ciSignature(ciKlass* accessing_klass, ciSymbol* symbol, ciMethodType* method_type) :
8da0dc50a6e4 7200949: JSR 292: rubybench/bench/time/bench_base64.rb fails with jruby.jar not on boot class path
twisti
parents: 10734
diff changeset
    87
  _symbol(symbol),
8da0dc50a6e4 7200949: JSR 292: rubybench/bench/time/bench_base64.rb fails with jruby.jar not on boot class path
twisti
parents: 10734
diff changeset
    88
  _accessing_klass(accessing_klass),
8da0dc50a6e4 7200949: JSR 292: rubybench/bench/time/bench_base64.rb fails with jruby.jar not on boot class path
twisti
parents: 10734
diff changeset
    89
  _size( method_type->ptype_slot_count()),
8da0dc50a6e4 7200949: JSR 292: rubybench/bench/time/bench_base64.rb fails with jruby.jar not on boot class path
twisti
parents: 10734
diff changeset
    90
  _count(method_type->ptype_count())
8da0dc50a6e4 7200949: JSR 292: rubybench/bench/time/bench_base64.rb fails with jruby.jar not on boot class path
twisti
parents: 10734
diff changeset
    91
{
8da0dc50a6e4 7200949: JSR 292: rubybench/bench/time/bench_base64.rb fails with jruby.jar not on boot class path
twisti
parents: 10734
diff changeset
    92
  ASSERT_IN_VM;
8da0dc50a6e4 7200949: JSR 292: rubybench/bench/time/bench_base64.rb fails with jruby.jar not on boot class path
twisti
parents: 10734
diff changeset
    93
  EXCEPTION_CONTEXT;
8da0dc50a6e4 7200949: JSR 292: rubybench/bench/time/bench_base64.rb fails with jruby.jar not on boot class path
twisti
parents: 10734
diff changeset
    94
  Arena* arena = CURRENT_ENV->arena();
8da0dc50a6e4 7200949: JSR 292: rubybench/bench/time/bench_base64.rb fails with jruby.jar not on boot class path
twisti
parents: 10734
diff changeset
    95
  _types = new (arena) GrowableArray<ciType*>(arena, _count + 1, 0, NULL);
8da0dc50a6e4 7200949: JSR 292: rubybench/bench/time/bench_base64.rb fails with jruby.jar not on boot class path
twisti
parents: 10734
diff changeset
    96
  for (int i = 0; i < _count; i++) {
8da0dc50a6e4 7200949: JSR 292: rubybench/bench/time/bench_base64.rb fails with jruby.jar not on boot class path
twisti
parents: 10734
diff changeset
    97
    _types->append(method_type->ptype_at(i));
8da0dc50a6e4 7200949: JSR 292: rubybench/bench/time/bench_base64.rb fails with jruby.jar not on boot class path
twisti
parents: 10734
diff changeset
    98
  }
8da0dc50a6e4 7200949: JSR 292: rubybench/bench/time/bench_base64.rb fails with jruby.jar not on boot class path
twisti
parents: 10734
diff changeset
    99
  _types->append(method_type->rtype());
8da0dc50a6e4 7200949: JSR 292: rubybench/bench/time/bench_base64.rb fails with jruby.jar not on boot class path
twisti
parents: 10734
diff changeset
   100
}
8da0dc50a6e4 7200949: JSR 292: rubybench/bench/time/bench_base64.rb fails with jruby.jar not on boot class path
twisti
parents: 10734
diff changeset
   101
8da0dc50a6e4 7200949: JSR 292: rubybench/bench/time/bench_base64.rb fails with jruby.jar not on boot class path
twisti
parents: 10734
diff changeset
   102
// ------------------------------------------------------------------
10734
065435337883 7092712: JSR 292: unloaded invokedynamic call sites can lead to a crash with signature types not on BCP
twisti
parents: 10008
diff changeset
   103
// ciSignature::return_type
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
// What is the return type of this signature?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
ciType* ciSignature::return_type() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  return _types->at(_count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
// ------------------------------------------------------------------
10734
065435337883 7092712: JSR 292: unloaded invokedynamic call sites can lead to a crash with signature types not on BCP
twisti
parents: 10008
diff changeset
   111
// ciSignature::type_at
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
// What is the type of the index'th element of this
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
// signature?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
ciType* ciSignature::type_at(int index) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  assert(index < _count, "out of bounds");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  // The first _klasses element holds the return klass.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  return _types->at(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
// ------------------------------------------------------------------
10734
065435337883 7092712: JSR 292: unloaded invokedynamic call sites can lead to a crash with signature types not on BCP
twisti
parents: 10008
diff changeset
   122
// ciSignature::equals
065435337883 7092712: JSR 292: unloaded invokedynamic call sites can lead to a crash with signature types not on BCP
twisti
parents: 10008
diff changeset
   123
//
065435337883 7092712: JSR 292: unloaded invokedynamic call sites can lead to a crash with signature types not on BCP
twisti
parents: 10008
diff changeset
   124
// Compare this signature to another one.  Signatures with different
065435337883 7092712: JSR 292: unloaded invokedynamic call sites can lead to a crash with signature types not on BCP
twisti
parents: 10008
diff changeset
   125
// accessing classes but with signature-types resolved to the same
065435337883 7092712: JSR 292: unloaded invokedynamic call sites can lead to a crash with signature types not on BCP
twisti
parents: 10008
diff changeset
   126
// types are defined to be equal.
065435337883 7092712: JSR 292: unloaded invokedynamic call sites can lead to a crash with signature types not on BCP
twisti
parents: 10008
diff changeset
   127
bool ciSignature::equals(ciSignature* that) {
065435337883 7092712: JSR 292: unloaded invokedynamic call sites can lead to a crash with signature types not on BCP
twisti
parents: 10008
diff changeset
   128
  // Compare signature
065435337883 7092712: JSR 292: unloaded invokedynamic call sites can lead to a crash with signature types not on BCP
twisti
parents: 10008
diff changeset
   129
  if (!this->as_symbol()->equals(that->as_symbol()))  return false;
065435337883 7092712: JSR 292: unloaded invokedynamic call sites can lead to a crash with signature types not on BCP
twisti
parents: 10008
diff changeset
   130
  // Compare all types of the arguments
065435337883 7092712: JSR 292: unloaded invokedynamic call sites can lead to a crash with signature types not on BCP
twisti
parents: 10008
diff changeset
   131
  for (int i = 0; i < _count; i++) {
065435337883 7092712: JSR 292: unloaded invokedynamic call sites can lead to a crash with signature types not on BCP
twisti
parents: 10008
diff changeset
   132
    if (this->type_at(i) != that->type_at(i))         return false;
065435337883 7092712: JSR 292: unloaded invokedynamic call sites can lead to a crash with signature types not on BCP
twisti
parents: 10008
diff changeset
   133
  }
065435337883 7092712: JSR 292: unloaded invokedynamic call sites can lead to a crash with signature types not on BCP
twisti
parents: 10008
diff changeset
   134
  // Compare the return type
065435337883 7092712: JSR 292: unloaded invokedynamic call sites can lead to a crash with signature types not on BCP
twisti
parents: 10008
diff changeset
   135
  if (this->return_type() != that->return_type())     return false;
065435337883 7092712: JSR 292: unloaded invokedynamic call sites can lead to a crash with signature types not on BCP
twisti
parents: 10008
diff changeset
   136
  return true;
065435337883 7092712: JSR 292: unloaded invokedynamic call sites can lead to a crash with signature types not on BCP
twisti
parents: 10008
diff changeset
   137
}
065435337883 7092712: JSR 292: unloaded invokedynamic call sites can lead to a crash with signature types not on BCP
twisti
parents: 10008
diff changeset
   138
065435337883 7092712: JSR 292: unloaded invokedynamic call sites can lead to a crash with signature types not on BCP
twisti
parents: 10008
diff changeset
   139
// ------------------------------------------------------------------
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
// ciSignature::print_signature
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
void ciSignature::print_signature() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  _symbol->print_symbol();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
// ciSignature::print
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
void ciSignature::print() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  tty->print("<ciSignature symbol=");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  print_signature();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
 tty->print(" accessing_klass=");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  _accessing_klass->print();
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 13929
diff changeset
   152
  tty->print(" address=" INTPTR_FORMAT ">", p2i((address)this));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
}