1 /*
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
3 * Copyright 2012, 2013 SAP AG. All rights reserved.
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 only, as
8 * published by the Free Software Foundation.
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 *
130 // There are no relocations available when the code gets relocated
131 // because of CodeBuffer expansion.
132 if (code->relocation_size() == 0)
133 return NULL;
134
135 address bl_destination = Assembler::bxx_destination(call_addr);
136 if (code->content_contains(bl_destination) &&
137 is_NativeCallTrampolineStub_at(bl_destination))
138 return bl_destination;
139
140 // If the codeBlob is not a nmethod, this is because we get here from the
141 // CodeBlob constructor, which is called within the nmethod constructor.
142 return trampoline_stub_Relocation::get_trampoline_for(call_addr, (nmethod*)code);
143 }
144
145 #ifdef ASSERT
146 void NativeCall::verify() {
147 address addr = addr_at(0);
148
149 if (!NativeCall::is_call_at(addr)) {
150 tty->print_cr("not a NativeCall at " PTR_FORMAT, addr);
151 // TODO: PPC port: Disassembler::decode(addr - 20, addr + 20, tty);
152 fatal(err_msg("not a NativeCall at " PTR_FORMAT, addr));
153 }
154 }
155 #endif // ASSERT
156
157 #ifdef ASSERT
158 void NativeFarCall::verify() {
159 address addr = addr_at(0);
160
161 NativeInstruction::verify();
162 if (!NativeFarCall::is_far_call_at(addr)) {
163 tty->print_cr("not a NativeFarCall at " PTR_FORMAT, addr);
164 // TODO: PPC port: Disassembler::decode(addr, 20, 20, tty);
165 fatal(err_msg("not a NativeFarCall at " PTR_FORMAT, addr));
166 }
167 }
168 #endif // ASSERT
169
170 address NativeMovConstReg::next_instruction_address() const {
171 #ifdef ASSERT
172 CodeBlob* nm = CodeCache::find_blob(instruction_address());
173 assert(!MacroAssembler::is_set_narrow_oop(addr_at(0), nm->content_begin()), "Should not patch narrow oop here");
174 #endif
175
176 if (MacroAssembler::is_load_const_from_method_toc_at(addr_at(0))) {
177 return addr_at(load_const_from_method_toc_instruction_size);
178 } else {
179 return addr_at(load_const_instruction_size);
180 }
181 }
182
183 intptr_t NativeMovConstReg::data() const {
184 address addr = addr_at(0);
185
289 if (MacroAssembler::get_narrow_oop(addr, cb->content_begin()) == (long)data) return;
290 const int invalidated_range =
291 MacroAssembler::patch_set_narrow_oop(addr, cb->content_begin(), (long)data);
292 const address start = invalidated_range < 0 ? addr + invalidated_range : addr;
293 // FIXME:
294 const int range = invalidated_range < 0 ? 4 - invalidated_range : 8;
295 ICache::ppc64_flush_icache_bytes(start, range);
296 }
297
298 // Do not use an assertion here. Let clients decide whether they only
299 // want this when assertions are enabled.
300 #ifdef ASSERT
301 void NativeMovConstReg::verify() {
302 address addr = addr_at(0);
303 if (! MacroAssembler::is_load_const_at(addr) &&
304 ! MacroAssembler::is_load_const_from_method_toc_at(addr)) {
305 CodeBlob* cb = CodeCache::find_blob_unsafe(addr); // find_nmethod() asserts if nmethod is zombie.
306 if (! (cb != NULL && MacroAssembler::is_calculate_address_from_global_toc_at(addr, cb->content_begin())) &&
307 ! (cb != NULL && MacroAssembler::is_set_narrow_oop(addr, cb->content_begin())) &&
308 ! MacroAssembler::is_bl(*((int*) addr))) {
309 tty->print_cr("not a NativeMovConstReg at " PTR_FORMAT, addr);
310 // TODO: PPC port: Disassembler::decode(addr, 20, 20, tty);
311 fatal(err_msg("not a NativeMovConstReg at " PTR_FORMAT, addr));
312 }
313 }
314 }
315 #endif // ASSERT
316
317 void NativeJump::patch_verified_entry(address entry, address verified_entry, address dest) {
318 ResourceMark rm;
319 int code_size = 1 * BytesPerInstWord;
320 CodeBuffer cb(verified_entry, code_size + 1);
321 MacroAssembler* a = new MacroAssembler(&cb);
322 #ifdef COMPILER2
323 assert(dest == SharedRuntime::get_handle_wrong_method_stub(), "expected fixed destination of patch");
324 #endif
325 // Patch this nmethod atomically. Always use illtrap/trap in debug build.
326 if (DEBUG_ONLY(false &&) a->is_within_range_of_b(dest, a->pc())) {
327 a->b(dest);
328 } else {
329 // The signal handler will continue at dest=OptoRuntime::handle_wrong_method_stub().
330 if (TrapBasedNotEntrantChecks) {
331 // We use a special trap for marking a method as not_entrant or zombie.
332 a->trap_zombie_not_entrant();
333 } else {
334 // We use an illtrap for marking a method as not_entrant or zombie.
335 a->illtrap();
336 }
337 }
338 ICache::ppc64_flush_icache_bytes(verified_entry, code_size);
339 }
340
341 #ifdef ASSERT
342 void NativeJump::verify() {
343 address addr = addr_at(0);
344
345 NativeInstruction::verify();
346 if (!NativeJump::is_jump_at(addr)) {
347 tty->print_cr("not a NativeJump at " PTR_FORMAT, addr);
348 // TODO: PPC port: Disassembler::decode(addr, 20, 20, tty);
349 fatal(err_msg("not a NativeJump at " PTR_FORMAT, addr));
350 }
351 }
352 #endif // ASSERT
353
354 //-------------------------------------------------------------------
355
356 // Call trampoline stubs.
357 //
358 // Layout and instructions of a call trampoline stub:
359 // 0: load the TOC (part 1)
360 // 4: load the TOC (part 2)
361 // 8: load the call target from the constant pool (part 1)
362 // [12: load the call target from the constant pool (part 2, optional)]
363 // ..: branch via CTR
364 //
365
366 address NativeCallTrampolineStub::encoded_destination_addr() const {
367 address instruction_addr = addr_at(2 * BytesPerInstWord);
368 assert(MacroAssembler::is_ld_largeoffset(instruction_addr),
369 "must be a ld with large offset (from the constant pool)");
|
1 /*
2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
3 * Copyright 2012, 2014 SAP AG. All rights reserved.
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 only, as
8 * published by the Free Software Foundation.
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 *
130 // There are no relocations available when the code gets relocated
131 // because of CodeBuffer expansion.
132 if (code->relocation_size() == 0)
133 return NULL;
134
135 address bl_destination = Assembler::bxx_destination(call_addr);
136 if (code->content_contains(bl_destination) &&
137 is_NativeCallTrampolineStub_at(bl_destination))
138 return bl_destination;
139
140 // If the codeBlob is not a nmethod, this is because we get here from the
141 // CodeBlob constructor, which is called within the nmethod constructor.
142 return trampoline_stub_Relocation::get_trampoline_for(call_addr, (nmethod*)code);
143 }
144
145 #ifdef ASSERT
146 void NativeCall::verify() {
147 address addr = addr_at(0);
148
149 if (!NativeCall::is_call_at(addr)) {
150 tty->print_cr("not a NativeCall at " PTR_FORMAT, p2i(addr));
151 // TODO: PPC port: Disassembler::decode(addr - 20, addr + 20, tty);
152 fatal(err_msg("not a NativeCall at " PTR_FORMAT, p2i(addr)));
153 }
154 }
155 #endif // ASSERT
156
157 #ifdef ASSERT
158 void NativeFarCall::verify() {
159 address addr = addr_at(0);
160
161 NativeInstruction::verify();
162 if (!NativeFarCall::is_far_call_at(addr)) {
163 tty->print_cr("not a NativeFarCall at " PTR_FORMAT, p2i(addr));
164 // TODO: PPC port: Disassembler::decode(addr, 20, 20, tty);
165 fatal(err_msg("not a NativeFarCall at " PTR_FORMAT, p2i(addr)));
166 }
167 }
168 #endif // ASSERT
169
170 address NativeMovConstReg::next_instruction_address() const {
171 #ifdef ASSERT
172 CodeBlob* nm = CodeCache::find_blob(instruction_address());
173 assert(!MacroAssembler::is_set_narrow_oop(addr_at(0), nm->content_begin()), "Should not patch narrow oop here");
174 #endif
175
176 if (MacroAssembler::is_load_const_from_method_toc_at(addr_at(0))) {
177 return addr_at(load_const_from_method_toc_instruction_size);
178 } else {
179 return addr_at(load_const_instruction_size);
180 }
181 }
182
183 intptr_t NativeMovConstReg::data() const {
184 address addr = addr_at(0);
185
289 if (MacroAssembler::get_narrow_oop(addr, cb->content_begin()) == (long)data) return;
290 const int invalidated_range =
291 MacroAssembler::patch_set_narrow_oop(addr, cb->content_begin(), (long)data);
292 const address start = invalidated_range < 0 ? addr + invalidated_range : addr;
293 // FIXME:
294 const int range = invalidated_range < 0 ? 4 - invalidated_range : 8;
295 ICache::ppc64_flush_icache_bytes(start, range);
296 }
297
298 // Do not use an assertion here. Let clients decide whether they only
299 // want this when assertions are enabled.
300 #ifdef ASSERT
301 void NativeMovConstReg::verify() {
302 address addr = addr_at(0);
303 if (! MacroAssembler::is_load_const_at(addr) &&
304 ! MacroAssembler::is_load_const_from_method_toc_at(addr)) {
305 CodeBlob* cb = CodeCache::find_blob_unsafe(addr); // find_nmethod() asserts if nmethod is zombie.
306 if (! (cb != NULL && MacroAssembler::is_calculate_address_from_global_toc_at(addr, cb->content_begin())) &&
307 ! (cb != NULL && MacroAssembler::is_set_narrow_oop(addr, cb->content_begin())) &&
308 ! MacroAssembler::is_bl(*((int*) addr))) {
309 tty->print_cr("not a NativeMovConstReg at " PTR_FORMAT, p2i(addr));
310 // TODO: PPC port: Disassembler::decode(addr, 20, 20, tty);
311 fatal(err_msg("not a NativeMovConstReg at " PTR_FORMAT, p2i(addr)));
312 }
313 }
314 }
315 #endif // ASSERT
316
317 void NativeJump::patch_verified_entry(address entry, address verified_entry, address dest) {
318 ResourceMark rm;
319 int code_size = 1 * BytesPerInstWord;
320 CodeBuffer cb(verified_entry, code_size + 1);
321 MacroAssembler* a = new MacroAssembler(&cb);
322 #ifdef COMPILER2
323 assert(dest == SharedRuntime::get_handle_wrong_method_stub(), "expected fixed destination of patch");
324 #endif
325 // Patch this nmethod atomically. Always use illtrap/trap in debug build.
326 if (DEBUG_ONLY(false &&) a->is_within_range_of_b(dest, a->pc())) {
327 a->b(dest);
328 } else {
329 // The signal handler will continue at dest=OptoRuntime::handle_wrong_method_stub().
330 if (TrapBasedNotEntrantChecks) {
331 // We use a special trap for marking a method as not_entrant or zombie.
332 a->trap_zombie_not_entrant();
333 } else {
334 // We use an illtrap for marking a method as not_entrant or zombie.
335 a->illtrap();
336 }
337 }
338 ICache::ppc64_flush_icache_bytes(verified_entry, code_size);
339 }
340
341 #ifdef ASSERT
342 void NativeJump::verify() {
343 address addr = addr_at(0);
344
345 NativeInstruction::verify();
346 if (!NativeJump::is_jump_at(addr)) {
347 tty->print_cr("not a NativeJump at " PTR_FORMAT, p2i(addr));
348 // TODO: PPC port: Disassembler::decode(addr, 20, 20, tty);
349 fatal(err_msg("not a NativeJump at " PTR_FORMAT, p2i(addr)));
350 }
351 }
352 #endif // ASSERT
353
354 //-------------------------------------------------------------------
355
356 // Call trampoline stubs.
357 //
358 // Layout and instructions of a call trampoline stub:
359 // 0: load the TOC (part 1)
360 // 4: load the TOC (part 2)
361 // 8: load the call target from the constant pool (part 1)
362 // [12: load the call target from the constant pool (part 2, optional)]
363 // ..: branch via CTR
364 //
365
366 address NativeCallTrampolineStub::encoded_destination_addr() const {
367 address instruction_addr = addr_at(2 * BytesPerInstWord);
368 assert(MacroAssembler::is_ld_largeoffset(instruction_addr),
369 "must be a ld with large offset (from the constant pool)");
|