1 /*
 2  * Copyright (c) 2020, 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 #ifndef SHARE_PRIMS_FOREIGN_GLOBALS
25 #define SHARE_PRIMS_FOREIGN_GLOBALS
26 
27 #include "code/vmreg.hpp"
28 #include "oops/oopsHierarchy.hpp"
29 #include "utilities/growableArray.hpp"
30 #include "utilities/macros.hpp"
31 
32 #include CPU_HEADER(foreign_globals)
33 
34 struct CallRegs {
35   VMReg* _arg_regs;
36   int _args_length;
37 
38   VMReg* _ret_regs;
39   int _rets_length;
40 
41   void calling_convention(BasicType* sig_bt, VMRegPair *parm_regs, uint argcnt) const;
42 };
43 
44 class ForeignGlobals {
45 private:
46   struct {
47     int inputStorage_offset;
48     int outputStorage_offset;
49     int volatileStorage_offset;
50     int stackAlignment_offset;
51     int shadowSpace_offset;
52   } ABI;
53 
54   struct {
55     int index_offset;
56     int type_offset;
57   } VMS;
58 
59   struct {
60     int size_offset;
61     int arguments_next_pc_offset;
62     int stack_args_bytes_offset;
63     int stack_args_offset;
64     int input_type_offsets_offset;
65     int output_type_offsets_offset;
66   } BL;
67 
68   struct {
69     int arg_regs_offset;
70     int ret_regs_offset;
71   } CallConvOffsets;
72 
73   ForeignGlobals();
74 
75   static const ForeignGlobals& instance();
76 
77   template<typename R>
78   static R cast(oop theOop);
79 
80   template<typename T, typename Func>
81   void loadArray(objArrayOop jarray, int type_index, GrowableArray<T>& array, Func converter) const;
82 
83   const ABIDescriptor parse_abi_descriptor_impl(jobject jabi) const;
84   const BufferLayout parse_buffer_layout_impl(jobject jlayout) const;
85   const CallRegs parse_call_regs_impl(jobject jconv) const;
86 public:
87   static const ABIDescriptor parse_abi_descriptor(jobject jabi);
88   static const BufferLayout parse_buffer_layout(jobject jlayout);
89   static const CallRegs parse_call_regs(jobject jconv);
90 };
91 
92 #endif // SHARE_PRIMS_FOREIGN_GLOBALS