compiledIC_sparc.cpp revision 4565:a6e09d6dd8e5
1/*
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25#include "precompiled.hpp"
26#include "asm/macroAssembler.inline.hpp"
27#include "code/compiledIC.hpp"
28#include "code/icBuffer.hpp"
29#include "code/nmethod.hpp"
30#include "memory/resourceArea.hpp"
31#include "runtime/mutexLocker.hpp"
32#include "runtime/safepoint.hpp"
33#ifdef COMPILER2
34#include "opto/matcher.hpp"
35#endif
36
37// Release the CompiledICHolder* associated with this call site is there is one.
38void CompiledIC::cleanup_call_site(virtual_call_Relocation* call_site) {
39  // This call site might have become stale so inspect it carefully.
40  NativeCall* call = nativeCall_at(call_site->addr());
41  if (is_icholder_entry(call->destination())) {
42    NativeMovConstReg* value = nativeMovConstReg_at(call_site->cached_value());
43    InlineCacheBuffer::queue_for_release((CompiledICHolder*)value->data());
44  }
45}
46
47bool CompiledIC::is_icholder_call_site(virtual_call_Relocation* call_site) {
48  // This call site might have become stale so inspect it carefully.
49  NativeCall* call = nativeCall_at(call_site->addr());
50  return is_icholder_entry(call->destination());
51}
52
53//-----------------------------------------------------------------------------
54// High-level access to an inline cache. Guaranteed to be MT-safe.
55
56CompiledIC::CompiledIC(nmethod* nm, NativeCall* call)
57  : _ic_call(call)
58{
59  address ic_call = call->instruction_address();
60
61  assert(ic_call != NULL, "ic_call address must be set");
62  assert(nm != NULL, "must pass nmethod");
63  assert(nm->contains(ic_call), "must be in nmethod");
64
65  // Search for the ic_call at the given address.
66  RelocIterator iter(nm, ic_call, ic_call+1);
67  bool ret = iter.next();
68  assert(ret == true, "relocInfo must exist at this address");
69  assert(iter.addr() == ic_call, "must find ic_call");
70  if (iter.type() == relocInfo::virtual_call_type) {
71    virtual_call_Relocation* r = iter.virtual_call_reloc();
72    _is_optimized = false;
73    _value = nativeMovConstReg_at(r->cached_value());
74  } else {
75    assert(iter.type() == relocInfo::opt_virtual_call_type, "must be a virtual call");
76    _is_optimized = true;
77    _value = NULL;
78  }
79}
80
81// ----------------------------------------------------------------------------
82
83#define __ _masm.
84void CompiledStaticCall::emit_to_interp_stub(CodeBuffer &cbuf) {
85#ifdef COMPILER2
86  // Stub is fixed up when the corresponding call is converted from calling
87  // compiled code to calling interpreted code.
88  // set (empty), G5
89  // jmp -1
90
91  address mark = cbuf.insts_mark();  // Get mark within main instrs section.
92
93  MacroAssembler _masm(&cbuf);
94
95  address base =
96  __ start_a_stub(to_interp_stub_size()*2);
97  if (base == NULL) return;  // CodeBuffer::expand failed.
98
99  // Static stub relocation stores the instruction address of the call.
100  __ relocate(static_stub_Relocation::spec(mark));
101
102  __ set_metadata(NULL, as_Register(Matcher::inline_cache_reg_encode()));
103
104  __ set_inst_mark();
105  AddressLiteral addrlit(-1);
106  __ JUMP(addrlit, G3, 0);
107
108  __ delayed()->nop();
109
110  // Update current stubs pointer and restore code_end.
111  __ end_a_stub();
112#else
113  ShouldNotReachHere();
114#endif
115}
116#undef __
117
118int CompiledStaticCall::to_interp_stub_size() {
119  // This doesn't need to be accurate but it must be larger or equal to
120  // the real size of the stub.
121  return (NativeMovConstReg::instruction_size +  // sethi/setlo;
122          NativeJump::instruction_size + // sethi; jmp; nop
123          (TraceJumps ? 20 * BytesPerInstWord : 0) );
124}
125
126// Relocation entries for call stub, compiled java to interpreter.
127int CompiledStaticCall::reloc_to_interp_stub() {
128  return 10;  // 4 in emit_java_to_interp + 1 in Java_Static_Call
129}
130
131void CompiledStaticCall::set_to_interpreted(methodHandle callee, address entry) {
132  address stub = find_stub();
133  guarantee(stub != NULL, "stub not found");
134
135  if (TraceICs) {
136    ResourceMark rm;
137    tty->print_cr("CompiledStaticCall@" INTPTR_FORMAT ": set_to_interpreted %s",
138                  instruction_address(),
139                  callee->name_and_sig_as_C_string());
140  }
141
142  // Creation also verifies the object.
143  NativeMovConstReg* method_holder = nativeMovConstReg_at(stub);
144  NativeJump*        jump          = nativeJump_at(method_holder->next_instruction_address());
145
146  assert(method_holder->data() == 0 || method_holder->data() == (intptr_t)callee(),
147         "a) MT-unsafe modification of inline cache");
148  assert(jump->jump_destination() == (address)-1 || jump->jump_destination() == entry,
149         "b) MT-unsafe modification of inline cache");
150
151  // Update stub.
152  method_holder->set_data((intptr_t)callee());
153  jump->set_jump_destination(entry);
154
155  // Update jump to call.
156  set_destination_mt_safe(stub);
157}
158
159void CompiledStaticCall::set_stub_to_clean(static_stub_Relocation* static_stub) {
160  assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), "mt unsafe call");
161  // Reset stub.
162  address stub = static_stub->addr();
163  assert(stub != NULL, "stub not found");
164  // Creation also verifies the object.
165  NativeMovConstReg* method_holder = nativeMovConstReg_at(stub);
166  NativeJump*        jump          = nativeJump_at(method_holder->next_instruction_address());
167  method_holder->set_data(0);
168  jump->set_jump_destination((address)-1);
169}
170
171//-----------------------------------------------------------------------------
172// Non-product mode code
173#ifndef PRODUCT
174
175void CompiledStaticCall::verify() {
176  // Verify call.
177  NativeCall::verify();
178  if (os::is_MP()) {
179    verify_alignment();
180  }
181
182  // Verify stub.
183  address stub = find_stub();
184  assert(stub != NULL, "no stub found for static call");
185  // Creation also verifies the object.
186  NativeMovConstReg* method_holder = nativeMovConstReg_at(stub);
187  NativeJump*        jump          = nativeJump_at(method_holder->next_instruction_address());
188
189  // Verify state.
190  assert(is_clean() || is_call_to_compiled() || is_call_to_interpreted(), "sanity check");
191}
192
193#endif // !PRODUCT
194