1 /* 2 * Copyright (c) 2016, 2017, 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 #include "precompiled.hpp" 25 26 #include "aot/compiledIC_aot.hpp" 27 #include "code/codeCache.hpp" 28 #include "memory/resourceArea.hpp" 29 30 void CompiledDirectStaticCall::set_to_far(const methodHandle& callee, address entry) { 31 address stub = find_stub(true /* is_far */); 32 guarantee(stub != NULL, "stub not found"); 33 34 if (TraceICs) { 35 ResourceMark rm; 36 tty->print_cr("CompiledDirectStaticCall@" INTPTR_FORMAT ": set_to_far %s", 37 p2i(instruction_address()), 38 callee->name_and_sig_as_C_string()); 39 } 40 41 // Creation also verifies the object. 42 // mov rax,imm_aot_addr 43 // jmp rax 44 NativeMovConstReg* destination_holder = nativeMovConstReg_at(stub); 45 46 #ifdef ASSERT 47 // read the value once 48 intptr_t data = destination_holder->data(); 49 assert(data == 0 || data == (intptr_t)entry, 50 "MT-unsafe modification of inline cache"); 51 #endif 52 53 // Update stub. 54 destination_holder->set_data((intptr_t)entry); 55 56 // Update jump to call. 57 set_destination_mt_safe(stub); 58 } 59 60 void CompiledPltStaticCall::set_to_interpreted(const methodHandle& callee, address entry) { 61 address stub = find_stub(); 62 guarantee(stub != NULL, "stub not found"); 63 if (TraceICs) { 64 ResourceMark rm; 65 tty->print_cr("CompiledPltStaticCall@" INTPTR_FORMAT ": set_to_interpreted %s", 66 p2i(instruction_address()), 67 callee->name_and_sig_as_C_string()); 68 } 69 70 // Creation also verifies the object. 71 NativeLoadGot* method_loader = nativeLoadGot_at(stub); 72 NativeGotJump* jump = nativeGotJump_at(method_loader->next_instruction_address()); 73 74 intptr_t data = method_loader->data(); 75 address destination = jump->destination(); 76 assert(data == 0 || data == (intptr_t)callee(), 77 "a) MT-unsafe modification of inline cache"); 78 assert(destination == (address)-1 || destination == entry, 79 "b) MT-unsafe modification of inline cache"); 80 81 // Update stub. 82 method_loader->set_data((intptr_t)callee()); 83 jump->set_jump_destination(entry); 84 85 // Update jump to call. 86 set_destination_mt_safe(stub); 87 } 88 89 #ifdef NEVER_CALLED 90 void CompiledPltStaticCall::set_stub_to_clean(static_stub_Relocation* static_stub) { 91 assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), "mt unsafe call"); 92 // Reset stub. 93 address stub = static_stub->addr(); 94 assert(stub != NULL, "stub not found"); 95 // Creation also verifies the object. 96 NativeLoadGot* method_loader = nativeLoadGot_at(stub); 97 NativeGotJump* jump = nativeGotJump_at(method_loader->next_instruction_address()); 98 method_loader->set_data(0); 99 jump->set_jump_destination((address)-1); 100 } 101 #endif 102 103 #ifndef PRODUCT 104 void CompiledPltStaticCall::verify() { 105 // Verify call. 106 _call->verify(); 107 108 #ifdef ASSERT 109 CodeBlob *cb = CodeCache::find_blob_unsafe((address) _call); 110 assert(cb && cb->is_aot(), "CompiledPltStaticCall can only be used on AOTCompiledMethod"); 111 #endif 112 113 // Verify stub. 114 address stub = find_stub(); 115 assert(stub != NULL, "no stub found for static call"); 116 // Creation also verifies the object. 117 NativeLoadGot* method_loader = nativeLoadGot_at(stub); 118 NativeGotJump* jump = nativeGotJump_at(method_loader->next_instruction_address()); 119 // Verify state. 120 assert(is_clean() || is_call_to_compiled() || is_call_to_interpreted(), "sanity check"); 121 } 122 #endif // !PRODUCT