3838
3939#define __ _masm->
4040
41+ // describe amount of space in bytes occupied by type on native stack
42+ #ifdef __APPLE__
43+ const int nativeByteSpace = sizeof (jbyte);
44+ const int nativeShortSpace = sizeof (jshort);
45+ const int nativeIntSpace = sizeof (jint);
46+ const int nativeLongSpace = wordSize;
47+ const int nativeFloatSpace = nativeIntSpace;
48+ const int nativeDoubleSpace = nativeLongSpace;
49+ #else
50+ const int nativeByteSpace = wordSize;
51+ const int nativeShortSpace = wordSize;
52+ const int nativeIntSpace = wordSize;
53+ const int nativeLongSpace = wordSize;
54+ const int nativeFloatSpace = nativeIntSpace;
55+ const int nativeDoubleSpace = nativeLongSpace;
56+ #endif
57+
58+ template <typename T>
59+ static inline void store_and_inc (char * &to, T value, int inc_size) {
60+ to = align_up (to, inc_size);
61+ *(T *)to = value;
62+ to = to + inc_size;
63+ }
64+
4165// Implementation of SignatureHandlerGenerator
4266Register InterpreterRuntime::SignatureHandlerGenerator::from () { return rlocals; }
4367Register InterpreterRuntime::SignatureHandlerGenerator::to () { return sp; }
@@ -51,6 +75,95 @@ InterpreterRuntime::SignatureHandlerGenerator::SignatureHandlerGenerator(
5175 _stack_offset = 0 ;
5276}
5377
78+ // On macos/aarch64 native stack is packed, int/float are using only 4 bytes
79+ // on stack. Natural alignment for types are still in place,
80+ // for example double/long should be 8 bytes alligned
81+
82+ void InterpreterRuntime::SignatureHandlerGenerator::pass_byte () {
83+ const Address src (from (), Interpreter::local_offset_in_bytes (offset ()));
84+
85+ switch (_num_int_args) {
86+ case 0 :
87+ __ ldr (c_rarg1, src);
88+ _num_int_args++;
89+ break ;
90+ case 1 :
91+ __ ldr (c_rarg2, src);
92+ _num_int_args++;
93+ break ;
94+ case 2 :
95+ __ ldr (c_rarg3, src);
96+ _num_int_args++;
97+ break ;
98+ case 3 :
99+ __ ldr (c_rarg4, src);
100+ _num_int_args++;
101+ break ;
102+ case 4 :
103+ __ ldr (c_rarg5, src);
104+ _num_int_args++;
105+ break ;
106+ case 5 :
107+ __ ldr (c_rarg6, src);
108+ _num_int_args++;
109+ break ;
110+ case 6 :
111+ __ ldr (c_rarg7, src);
112+ _num_int_args++;
113+ break ;
114+ default :
115+ __ ldrb (r0, src);
116+ __ strb (r0, Address (to (), _stack_offset));
117+ _stack_offset += nativeByteSpace;
118+
119+ _num_int_args++;
120+ break ;
121+ }
122+ }
123+
124+ void InterpreterRuntime::SignatureHandlerGenerator::pass_short () {
125+ const Address src (from (), Interpreter::local_offset_in_bytes (offset ()));
126+
127+ switch (_num_int_args) {
128+ case 0 :
129+ __ ldr (c_rarg1, src);
130+ _num_int_args++;
131+ break ;
132+ case 1 :
133+ __ ldr (c_rarg2, src);
134+ _num_int_args++;
135+ break ;
136+ case 2 :
137+ __ ldr (c_rarg3, src);
138+ _num_int_args++;
139+ break ;
140+ case 3 :
141+ __ ldr (c_rarg4, src);
142+ _num_int_args++;
143+ break ;
144+ case 4 :
145+ __ ldr (c_rarg5, src);
146+ _num_int_args++;
147+ break ;
148+ case 5 :
149+ __ ldr (c_rarg6, src);
150+ _num_int_args++;
151+ break ;
152+ case 6 :
153+ __ ldr (c_rarg7, src);
154+ _num_int_args++;
155+ break ;
156+ default :
157+ _stack_offset = align_up (_stack_offset, nativeShortSpace);
158+ __ ldrh (r0, src);
159+ __ strh (r0, Address (to (), _stack_offset));
160+ _stack_offset += nativeShortSpace;
161+
162+ _num_int_args++;
163+ break ;
164+ }
165+ }
166+
54167void InterpreterRuntime::SignatureHandlerGenerator::pass_int () {
55168 const Address src (from (), Interpreter::local_offset_in_bytes (offset ()));
56169
@@ -84,9 +197,10 @@ void InterpreterRuntime::SignatureHandlerGenerator::pass_int() {
84197 _num_int_args++;
85198 break ;
86199 default :
200+ _stack_offset = align_up (_stack_offset, nativeIntSpace);
87201 __ ldr (r0, src);
88202 __ str (r0, Address (to (), _stack_offset));
89- _stack_offset += wordSize ;
203+ _stack_offset += nativeIntSpace ;
90204 _num_int_args++;
91205 break ;
92206 }
@@ -125,9 +239,10 @@ void InterpreterRuntime::SignatureHandlerGenerator::pass_long() {
125239 _num_int_args++;
126240 break ;
127241 default :
242+ _stack_offset = align_up (_stack_offset, nativeLongSpace);
128243 __ ldr (r0, src);
129244 __ str (r0, Address (to (), _stack_offset));
130- _stack_offset += wordSize ;
245+ _stack_offset += nativeLongSpace ;
131246 _num_int_args++;
132247 break ;
133248 }
@@ -139,9 +254,10 @@ void InterpreterRuntime::SignatureHandlerGenerator::pass_float() {
139254 if (_num_fp_args < Argument::n_float_register_parameters_c) {
140255 __ ldrs (as_FloatRegister (_num_fp_args++), src);
141256 } else {
257+ _stack_offset = align_up (_stack_offset, nativeFloatSpace);
142258 __ ldrw (r0, src);
143259 __ strw (r0, Address (to (), _stack_offset));
144- _stack_offset += wordSize ;
260+ _stack_offset += nativeFloatSpace ;
145261 _num_fp_args++;
146262 }
147263}
@@ -152,9 +268,10 @@ void InterpreterRuntime::SignatureHandlerGenerator::pass_double() {
152268 if (_num_fp_args < Argument::n_float_register_parameters_c) {
153269 __ ldrd (as_FloatRegister (_num_fp_args++), src);
154270 } else {
271+ _stack_offset = align_up (_stack_offset, nativeDoubleSpace);
155272 __ ldr (r0, src);
156273 __ str (r0, Address (to (), _stack_offset));
157- _stack_offset += wordSize ;
274+ _stack_offset += nativeDoubleSpace ;
158275 _num_fp_args++;
159276 }
160277}
@@ -247,6 +364,7 @@ void InterpreterRuntime::SignatureHandlerGenerator::pass_object() {
247364 __ cbnz (temp (), L);
248365 __ mov (r0, zr);
249366 __ bind (L);
367+ _stack_offset = align_up (_stack_offset, wordSize);
250368 __ str (r0, Address (to (), _stack_offset));
251369 _stack_offset += wordSize;
252370 _num_int_args++;
@@ -276,13 +394,45 @@ class SlowSignatureHandler
276394 : public NativeSignatureIterator {
277395 private:
278396 address _from;
279- intptr_t * _to;
397+ char * _to;
280398 intptr_t * _int_args;
281399 intptr_t * _fp_args;
282400 intptr_t * _fp_identifiers;
283401 unsigned int _num_int_args;
284402 unsigned int _num_fp_args;
285403
404+
405+ virtual void pass_byte ()
406+ {
407+ NOT_MACOS (return pass_int ();)
408+ jbyte from_obj = *(jbyte *)(_from+Interpreter::local_offset_in_bytes (0 ));
409+ _from -= Interpreter::stackElementSize;
410+
411+ if (_num_int_args < Argument::n_int_register_parameters_c-1 ) {
412+ *_int_args++ = from_obj;
413+ _num_int_args++;
414+ } else {
415+ store_and_inc (_to, from_obj, nativeByteSpace);
416+
417+ _num_int_args++;
418+ }
419+ }
420+
421+ virtual void pass_short ()
422+ {
423+ NOT_MACOS (return pass_int ();)
424+ jshort from_obj = *(jshort *)(_from+Interpreter::local_offset_in_bytes (0 ));
425+ _from -= Interpreter::stackElementSize;
426+
427+ if (_num_int_args < Argument::n_int_register_parameters_c-1 ) {
428+ *_int_args++ = from_obj;
429+ _num_int_args++;
430+ } else {
431+ store_and_inc (_to, from_obj, nativeShortSpace);
432+
433+ _num_int_args++;
434+ }
435+ }
286436 virtual void pass_int ()
287437 {
288438 jint from_obj = *(jint *)(_from+Interpreter::local_offset_in_bytes (0 ));
@@ -292,7 +442,8 @@ class SlowSignatureHandler
292442 *_int_args++ = from_obj;
293443 _num_int_args++;
294444 } else {
295- *_to++ = from_obj;
445+ store_and_inc (_to, from_obj, nativeIntSpace);
446+
296447 _num_int_args++;
297448 }
298449 }
@@ -306,7 +457,7 @@ class SlowSignatureHandler
306457 *_int_args++ = from_obj;
307458 _num_int_args++;
308459 } else {
309- * _to++ = from_obj;
460+ store_and_inc ( _to, from_obj, nativeLongSpace) ;
310461 _num_int_args++;
311462 }
312463 }
@@ -320,7 +471,7 @@ class SlowSignatureHandler
320471 *_int_args++ = (*from_addr == 0 ) ? NULL : (intptr_t )from_addr;
321472 _num_int_args++;
322473 } else {
323- * _to++ = (*from_addr == 0 ) ? NULL : (intptr_t ) from_addr;
474+ store_and_inc ( _to, (*from_addr == 0 ) ? ( intptr_t ) NULL : (intptr_t ) from_addr, wordSize) ;
324475 _num_int_args++;
325476 }
326477 }
@@ -334,7 +485,8 @@ class SlowSignatureHandler
334485 *_fp_args++ = from_obj;
335486 _num_fp_args++;
336487 } else {
337- *_to++ = from_obj;
488+ store_and_inc (_to, from_obj, nativeFloatSpace);
489+
338490 _num_fp_args++;
339491 }
340492 }
@@ -349,7 +501,7 @@ class SlowSignatureHandler
349501 *_fp_identifiers |= (1ull << _num_fp_args); // mark as double
350502 _num_fp_args++;
351503 } else {
352- * _to++ = from_obj;
504+ store_and_inc ( _to, from_obj, nativeDoubleSpace) ;
353505 _num_fp_args++;
354506 }
355507 }
@@ -359,7 +511,7 @@ class SlowSignatureHandler
359511 : NativeSignatureIterator(method)
360512 {
361513 _from = from;
362- _to = to;
514+ _to = ( char *) to;
363515
364516 _int_args = to - (method->is_static () ? 16 : 17 );
365517 _fp_args = to - 8 ;
0 commit comments