1 /* 2 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. 3 * Copyright (c) 2018, Red Hat Inc. 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 */ 24 25 #include "aot/compiledIC_aot.hpp" 26 #include "code/codeCache.hpp" 27 #include "memory/resourceArea.hpp" 28 #include "memory/universe.hpp" 29 30 void CompiledDirectStaticCall::set_to_far(const methodHandle& callee, address entry) { 31 if (TraceICs) { 32 ResourceMark rm; 33 tty->print_cr("CompiledDirectStaticCall@" INTPTR_FORMAT ": set_to_far %s", 34 p2i(instruction_address()), 35 callee->name_and_sig_as_C_string()); 36 } 37 38 set_destination_mt_safe(entry); 39 } 40 41 void CompiledPltStaticCall::set_to_interpreted(const methodHandle& callee, address entry) { 42 address stub = find_stub(); 43 guarantee(stub != NULL, "stub not found"); 44 if (TraceICs) { 45 ResourceMark rm; 46 tty->print_cr("CompiledPltStaticCall@" INTPTR_FORMAT ": set_to_interpreted %s", 47 p2i(instruction_address()), 48 callee->name_and_sig_as_C_string()); 49 } 50 51 // Creation also verifies the object. 52 NativeLoadGot* method_loader = nativeLoadGot_at(stub); 53 NativeGotJump* jump = nativeGotJump_at(method_loader->next_instruction_address()); 54 55 intptr_t data = method_loader->data(); 56 address destination = jump->destination(); 57 assert(data == 0 || data == (intptr_t)callee(), 58 "a) MT-unsafe modification of inline cache"); 59 assert(destination == (address)Universe::non_oop_word() 60 || destination == entry, 61 "b) MT-unsafe modification of inline cache"); 62 63 // Update stub. 64 method_loader->set_data((intptr_t)callee()); 65 jump->set_jump_destination(entry); 66 67 // Update jump to call. 68 set_destination_mt_safe(stub); 69 } 70 71 #ifdef NEVER_CALLED 72 void CompiledPltStaticCall::set_stub_to_clean(static_stub_Relocation* static_stub) { 73 // Reset stub. 74 address stub = static_stub->addr(); 75 assert(stub != NULL, "stub not found"); 76 assert(CompiledICLocker::is_safe(stub), "mt unsafe call"); 77 // Creation also verifies the object. 78 NativeLoadGot* method_loader = nativeLoadGot_at(stub); 79 NativeGotJump* jump = nativeGotJump_at(method_loader->next_instruction_address()); 80 method_loader->set_data(0); 81 jump->set_jump_destination((address)-1); 82 } 83 #endif 84 85 #ifndef PRODUCT 86 void CompiledPltStaticCall::verify() { 87 // Verify call. 88 _call->verify(); 89 90 #ifdef ASSERT 91 CodeBlob *cb = CodeCache::find_blob_unsafe((address) _call); 92 assert(cb && cb->is_aot(), "CompiledPltStaticCall can only be used on AOTCompiledMethod"); 93 #endif 94 95 // Verify stub. 96 address stub = find_stub(); 97 assert(stub != NULL, "no stub found for static call"); 98 // Creation also verifies the object. 99 NativeLoadGot* method_loader = nativeLoadGot_at(stub); 100 NativeGotJump* jump = nativeGotJump_at(method_loader->next_instruction_address()); 101 // Verify state. 102 assert(is_clean() || is_call_to_compiled() || is_call_to_interpreted(), "sanity check"); 103 } 104 #endif // !PRODUCT