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 *
24 */
25
26 #include "precompiled.hpp"
27 #include "asm/assembler.inline.hpp"
28 #include "interpreter/interpreter.hpp"
29 #include "interpreter/interpreterRuntime.hpp"
30 #include "memory/allocation.inline.hpp"
31 #include "memory/universe.inline.hpp"
32 #include "oops/method.hpp"
33 #include "oops/oop.inline.hpp"
34 #include "runtime/handles.inline.hpp"
35 #include "runtime/icache.hpp"
36 #include "runtime/interfaceSupport.hpp"
37 #include "runtime/signature.hpp"
38
39 #define __ _masm->
40
41 // Access macros for Java and C arguments.
42 // The first Java argument is at index -1.
43 #define locals_j_arg_at(index) (Interpreter::local_offset_in_bytes(index)), R18_locals
44 // The first C argument is at index 0.
45 #define sp_c_arg_at(index) ((index)*wordSize + _abi(carg_1)), R1_SP
46
47 // Implementation of SignatureHandlerGenerator
48
pass_int()49 void InterpreterRuntime::SignatureHandlerGenerator::pass_int() {
50 Argument jni_arg(jni_offset());
51 Register r = jni_arg.is_register() ? jni_arg.as_register() : R0;
52
53 __ lwa(r, locals_j_arg_at(offset())); // sign extension of integer
54 if (DEBUG_ONLY(true ||) !jni_arg.is_register()) {
55 __ std(r, sp_c_arg_at(jni_arg.number()));
56 }
57 }
58
pass_long()59 void InterpreterRuntime::SignatureHandlerGenerator::pass_long() {
60 Argument jni_arg(jni_offset());
61 Register r = jni_arg.is_register() ? jni_arg.as_register() : R0;
62
63 __ ld(r, locals_j_arg_at(offset()+1)); // long resides in upper slot
64 if (DEBUG_ONLY(true ||) !jni_arg.is_register()) {
65 __ std(r, sp_c_arg_at(jni_arg.number()));
66 }
67 }
68
pass_float()69 void InterpreterRuntime::SignatureHandlerGenerator::pass_float() {
70 FloatRegister fp_reg = (_num_used_fp_arg_regs < 13/*max_fp_register_arguments*/)
71 ? as_FloatRegister((_num_used_fp_arg_regs++) + F1_ARG1->encoding())
72 : F0;
73
74 __ lfs(fp_reg, locals_j_arg_at(offset()));
75 if (DEBUG_ONLY(true ||) jni_offset() > 8) {
76 __ stfs(fp_reg, sp_c_arg_at(jni_offset()));
77 }
78 }
79
pass_double()80 void InterpreterRuntime::SignatureHandlerGenerator::pass_double() {
81 FloatRegister fp_reg = (_num_used_fp_arg_regs < 13/*max_fp_register_arguments*/)
82 ? as_FloatRegister((_num_used_fp_arg_regs++) + F1_ARG1->encoding())
83 : F0;
84
85 __ lfd(fp_reg, locals_j_arg_at(offset()+1));
86 if (DEBUG_ONLY(true ||) jni_offset() > 8) {
87 __ stfd(fp_reg, sp_c_arg_at(jni_offset()));
88 }
89 }
90
pass_object()91 void InterpreterRuntime::SignatureHandlerGenerator::pass_object() {
92 Argument jni_arg(jni_offset());
93 Register r = jni_arg.is_register() ? jni_arg.as_register() : R11_scratch1;
94
95 // The handle for a receiver will never be null.
96 bool do_NULL_check = offset() != 0 || is_static();
97
98 Label do_null;
99 if (do_NULL_check) {
100 __ ld(R0, locals_j_arg_at(offset()));
101 __ cmpdi(CCR0, R0, 0);
102 __ li(r, 0);
103 __ beq(CCR0, do_null);
104 }
105 __ addir(r, locals_j_arg_at(offset()));
106 __ bind(do_null);
107 if (DEBUG_ONLY(true ||) !jni_arg.is_register()) {
108 __ std(r, sp_c_arg_at(jni_arg.number()));
109 }
110 }
111
generate(uint64_t fingerprint)112 void InterpreterRuntime::SignatureHandlerGenerator::generate(uint64_t fingerprint) {
113 #if !defined(ABI_ELFv2)
114 // Emit fd for current codebuffer. Needs patching!
115 __ emit_fd();
116 #endif
117
118 // Generate code to handle arguments.
119 iterate(fingerprint);
120
121 // Return the result handler.
122 __ load_const(R3_RET, AbstractInterpreter::result_handler(method()->result_type()));
123 __ blr();
124
125 __ flush();
126 }
127
128 #undef __
129
130 // Implementation of SignatureHandlerLibrary
131
pd_set_handler(address handler)132 void SignatureHandlerLibrary::pd_set_handler(address handler) {
133 #if !defined(ABI_ELFv2)
134 // patch fd here.
135 FunctionDescriptor* fd = (FunctionDescriptor*) handler;
136
137 fd->set_entry(handler + (int)sizeof(FunctionDescriptor));
138 assert(fd->toc() == (address)0xcafe, "need to adjust TOC here");
139 #endif
140 }
141
142
143 // Access function to get the signature.
144 IRT_ENTRY(address, InterpreterRuntime::get_signature(JavaThread* thread, Method* method))
145 methodHandle m(thread, method);
146 assert(m->is_native(), "sanity check");
147 Symbol *s = m->signature();
148 return (address) s->base();
149 IRT_END
150
151 IRT_ENTRY(address, InterpreterRuntime::get_result_handler(JavaThread* thread, Method* method))
152 methodHandle m(thread, method);
153 assert(m->is_native(), "sanity check");
154 return AbstractInterpreter::result_handler(m->result_type());
155 IRT_END
156