< prev index next >

src/hotspot/cpu/riscv/vtableStubs_riscv.cpp

Print this page

  1 /*
  2  * Copyright (c) 2003, 2025, Oracle and/or its affiliates. All rights reserved.
  3  * Copyright (c) 2014, Red Hat Inc. All rights reserved.
  4  * Copyright (c) 2020, 2023, Huawei Technologies Co., Ltd. All rights reserved.
  5  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  6  *
  7  * This code is free software; you can redistribute it and/or modify it
  8  * under the terms of the GNU General Public License version 2 only, as
  9  * published by the Free Software Foundation.
 10  *
 11  * This code is distributed in the hope that it will be useful, but WITHOUT
 12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  * version 2 for more details (a copy is included in the LICENSE file that
 15  * accompanied this code).
 16  *
 17  * You should have received a copy of the GNU General Public License version
 18  * 2 along with this work; if not, write to the Free Software Foundation,
 19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  *
 21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22  * or visit www.oracle.com if you need additional information or have any

 30 #include "code/vtableStubs.hpp"
 31 #include "interp_masm_riscv.hpp"
 32 #include "memory/resourceArea.hpp"
 33 #include "oops/instanceKlass.hpp"
 34 #include "oops/klassVtable.hpp"
 35 #include "runtime/sharedRuntime.hpp"
 36 #include "vmreg_riscv.inline.hpp"
 37 #ifdef COMPILER2
 38 #include "opto/runtime.hpp"
 39 #endif
 40 
 41 // machine-dependent part of VtableStubs: create VtableStub of correct size and
 42 // initialize its code
 43 
 44 #define __ masm->
 45 
 46 #ifndef PRODUCT
 47 extern "C" void bad_compiled_vtable_index(JavaThread* thread, oop receiver, int index);
 48 #endif
 49 
 50 VtableStub* VtableStubs::create_vtable_stub(int vtable_index) {
 51   // Read "A word on VtableStub sizing" in share/code/vtableStubs.hpp for details on stub sizing.
 52   const int stub_code_length = code_size_limit(true);
 53   VtableStub* s = new(stub_code_length) VtableStub(true, vtable_index);
 54   // Can be null if there is no free space in the code cache.
 55   if (s == nullptr) {
 56     return nullptr;
 57   }
 58 
 59   // Count unused bytes in instruction sequences of variable size.
 60   // We add them to the computed buffer size in order to avoid
 61   // overflow in subsequently generated stubs.
 62   address   start_pc = nullptr;
 63   int       slop_bytes = 0;
 64   int       slop_delta = 0;
 65 
 66   ResourceMark    rm;
 67   CodeBuffer      cb(s->entry_point(), stub_code_length);
 68   MacroAssembler* masm = new MacroAssembler(&cb);
 69   assert_cond(masm != nullptr);
 70 
 71 #if (!defined(PRODUCT) && defined(COMPILER2))
 72   if (CountCompiledCalls) {
 73     __ la(t2, ExternalAddress((address) SharedRuntime::nof_megamorphic_calls_addr()));

122     __ ld(t0, Address(xmethod, Method::from_compiled_offset()));
123     __ bnez(t0, L);
124     __ stop("Vtable entry is null");
125     __ bind(L);
126   }
127 #endif // PRODUCT
128 
129   // x10: receiver klass
130   // xmethod: Method*
131   // x12: receiver
132   address ame_addr = __ pc();
133   __ ld(t1, Address(xmethod, Method::from_compiled_offset()));
134   __ jr(t1);
135 
136   masm->flush();
137   bookkeeping(masm, tty, s, npe_addr, ame_addr, true, vtable_index, slop_bytes, 0);
138 
139   return s;
140 }
141 
142 VtableStub* VtableStubs::create_itable_stub(int itable_index) {
143   // Read "A word on VtableStub sizing" in share/code/vtableStubs.hpp for details on stub sizing.
144   const int stub_code_length = code_size_limit(false);
145   VtableStub* s = new(stub_code_length) VtableStub(false, itable_index);
146   // Can be null if there is no free space in the code cache.
147   if (s == nullptr) {
148     return nullptr;
149   }
150   // Count unused bytes in instruction sequences of variable size.
151   // We add them to the computed buffer size in order to avoid
152   // overflow in subsequently generated stubs.
153   address   start_pc = nullptr;
154   int       slop_bytes = 0;
155   int       slop_delta = 0;
156 
157   ResourceMark    rm;
158   CodeBuffer      cb(s->entry_point(), stub_code_length);
159   MacroAssembler* masm = new MacroAssembler(&cb);
160   assert_cond(masm != nullptr);
161 
162   // Real entry arguments:
163   //  t0: CompiledICData
164   //  j_rarg0: Receiver
165   // Make sure the move of CompiledICData from t0 to t1 is the frist thing that happens.

  1 /*
  2  * Copyright (c) 2003, 2026, Oracle and/or its affiliates. All rights reserved.
  3  * Copyright (c) 2014, Red Hat Inc. All rights reserved.
  4  * Copyright (c) 2020, 2023, Huawei Technologies Co., Ltd. All rights reserved.
  5  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  6  *
  7  * This code is free software; you can redistribute it and/or modify it
  8  * under the terms of the GNU General Public License version 2 only, as
  9  * published by the Free Software Foundation.
 10  *
 11  * This code is distributed in the hope that it will be useful, but WITHOUT
 12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  * version 2 for more details (a copy is included in the LICENSE file that
 15  * accompanied this code).
 16  *
 17  * You should have received a copy of the GNU General Public License version
 18  * 2 along with this work; if not, write to the Free Software Foundation,
 19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  *
 21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22  * or visit www.oracle.com if you need additional information or have any

 30 #include "code/vtableStubs.hpp"
 31 #include "interp_masm_riscv.hpp"
 32 #include "memory/resourceArea.hpp"
 33 #include "oops/instanceKlass.hpp"
 34 #include "oops/klassVtable.hpp"
 35 #include "runtime/sharedRuntime.hpp"
 36 #include "vmreg_riscv.inline.hpp"
 37 #ifdef COMPILER2
 38 #include "opto/runtime.hpp"
 39 #endif
 40 
 41 // machine-dependent part of VtableStubs: create VtableStub of correct size and
 42 // initialize its code
 43 
 44 #define __ masm->
 45 
 46 #ifndef PRODUCT
 47 extern "C" void bad_compiled_vtable_index(JavaThread* thread, oop receiver, int index);
 48 #endif
 49 
 50 VtableStub* VtableStubs::create_vtable_stub(int vtable_index, bool caller_is_c1) {
 51   // Read "A word on VtableStub sizing" in share/code/vtableStubs.hpp for details on stub sizing.
 52   const int stub_code_length = code_size_limit(true);
 53   VtableStub* s = new(stub_code_length) VtableStub(true, vtable_index, caller_is_c1);
 54   // Can be null if there is no free space in the code cache.
 55   if (s == nullptr) {
 56     return nullptr;
 57   }
 58 
 59   // Count unused bytes in instruction sequences of variable size.
 60   // We add them to the computed buffer size in order to avoid
 61   // overflow in subsequently generated stubs.
 62   address   start_pc = nullptr;
 63   int       slop_bytes = 0;
 64   int       slop_delta = 0;
 65 
 66   ResourceMark    rm;
 67   CodeBuffer      cb(s->entry_point(), stub_code_length);
 68   MacroAssembler* masm = new MacroAssembler(&cb);
 69   assert_cond(masm != nullptr);
 70 
 71 #if (!defined(PRODUCT) && defined(COMPILER2))
 72   if (CountCompiledCalls) {
 73     __ la(t2, ExternalAddress((address) SharedRuntime::nof_megamorphic_calls_addr()));

122     __ ld(t0, Address(xmethod, Method::from_compiled_offset()));
123     __ bnez(t0, L);
124     __ stop("Vtable entry is null");
125     __ bind(L);
126   }
127 #endif // PRODUCT
128 
129   // x10: receiver klass
130   // xmethod: Method*
131   // x12: receiver
132   address ame_addr = __ pc();
133   __ ld(t1, Address(xmethod, Method::from_compiled_offset()));
134   __ jr(t1);
135 
136   masm->flush();
137   bookkeeping(masm, tty, s, npe_addr, ame_addr, true, vtable_index, slop_bytes, 0);
138 
139   return s;
140 }
141 
142 VtableStub* VtableStubs::create_itable_stub(int itable_index, bool caller_is_c1) {
143   // Read "A word on VtableStub sizing" in share/code/vtableStubs.hpp for details on stub sizing.
144   const int stub_code_length = code_size_limit(false);
145   VtableStub* s = new(stub_code_length) VtableStub(false, itable_index, caller_is_c1);
146   // Can be null if there is no free space in the code cache.
147   if (s == nullptr) {
148     return nullptr;
149   }
150   // Count unused bytes in instruction sequences of variable size.
151   // We add them to the computed buffer size in order to avoid
152   // overflow in subsequently generated stubs.
153   address   start_pc = nullptr;
154   int       slop_bytes = 0;
155   int       slop_delta = 0;
156 
157   ResourceMark    rm;
158   CodeBuffer      cb(s->entry_point(), stub_code_length);
159   MacroAssembler* masm = new MacroAssembler(&cb);
160   assert_cond(masm != nullptr);
161 
162   // Real entry arguments:
163   //  t0: CompiledICData
164   //  j_rarg0: Receiver
165   // Make sure the move of CompiledICData from t0 to t1 is the frist thing that happens.
< prev index next >