@@ -165,6 +165,7 @@ void TemplateTable::patch_bytecode(Bytecodes::Code bc, Register bc_reg,
165165 switch (bc) {
166166 case Bytecodes::_fast_aputfield:
167167 case Bytecodes::_fast_bputfield:
168+ case Bytecodes::_fast_zputfield:
168169 case Bytecodes::_fast_cputfield:
169170 case Bytecodes::_fast_dputfield:
170171 case Bytecodes::_fast_fputfield:
@@ -922,8 +923,20 @@ void TemplateTable::bastore() {
922923 transition (itos, vtos);
923924 __ pop_i (O2); // index
924925 // Otos_i: val
926+ // O2: index
925927 // O3: array
926928 __ index_check (O3, O2, 0 , G3_scratch, O2);
929+ // Need to check whether array is boolean or byte
930+ // since both types share the bastore bytecode.
931+ __ load_klass (O3, G4_scratch);
932+ __ ld (G4_scratch, in_bytes (Klass::layout_helper_offset ()), G4_scratch);
933+ __ set (Klass::layout_helper_boolean_diffbit (), G3_scratch);
934+ __ andcc (G3_scratch, G4_scratch, G0);
935+ Label L_skip;
936+ __ br (Assembler::zero, false , Assembler::pn, L_skip);
937+ __ delayed ()->nop ();
938+ __ and3 (Otos_i, 1 , Otos_i); // if it is a T_BOOLEAN array, mask the stored value to 0/1
939+ __ bind (L_skip);
927940 __ stb (Otos_i, O2, arrayOopDesc::base_offset_in_bytes (T_BYTE));
928941}
929942
@@ -2008,6 +2021,12 @@ void TemplateTable::_return(TosState state) {
20082021 __ bind (skip_register_finalizer);
20092022 }
20102023
2024+ // Narrow result if state is itos but result type is smaller.
2025+ // Need to narrow in the return bytecode rather than in generate_return_entry
2026+ // since compiled code callers expect the result to already be narrowed.
2027+ if (state == itos) {
2028+ __ narrow (Otos_i);
2029+ }
20112030 __ remove_activation (state, /* throw_monitor_exception */ true );
20122031
20132032 // The caller's SP was adjusted upon method entry to accomodate
@@ -2218,7 +2237,7 @@ void TemplateTable::getfield_or_static(int byte_no, bool is_static, RewriteContr
22182237 Label checkVolatile;
22192238
22202239 // compute field type
2221- Label notByte, notInt, notShort, notChar, notLong, notFloat, notObj;
2240+ Label notByte, notBool, notInt, notShort, notChar, notLong, notFloat, notObj;
22222241 __ srl (Rflags, ConstantPoolCacheEntry::tos_state_shift, Rflags);
22232242 // Make sure we don't need to mask Rflags after the above shift
22242243 ConstantPoolCacheEntry::verify_tos_state_shift ();
@@ -2273,7 +2292,7 @@ void TemplateTable::getfield_or_static(int byte_no, bool is_static, RewriteContr
22732292
22742293 // cmp(Rflags, btos);
22752294 __ br (Assembler::notEqual, false , Assembler::pt, notByte);
2276- __ delayed () ->cmp (Rflags, ctos );
2295+ __ delayed () ->cmp (Rflags, ztos );
22772296
22782297 // btos
22792298 __ ldsb (Rclass, Roffset, Otos_i);
@@ -2286,6 +2305,22 @@ void TemplateTable::getfield_or_static(int byte_no, bool is_static, RewriteContr
22862305
22872306 __ bind (notByte);
22882307
2308+ // cmp(Rflags, ztos);
2309+ __ br (Assembler::notEqual, false , Assembler::pt, notBool);
2310+ __ delayed () ->cmp (Rflags, ctos);
2311+
2312+ // ztos
2313+ __ ldsb (Rclass, Roffset, Otos_i);
2314+ __ push (itos);
2315+ if (!is_static && rc == may_rewrite) {
2316+ // use btos rewriting, no truncating to t/f bit is needed for getfield.
2317+ patch_bytecode (Bytecodes::_fast_bgetfield, G3_scratch, G4_scratch);
2318+ }
2319+ __ ba (checkVolatile);
2320+ __ delayed ()->tst (Lscratch);
2321+
2322+ __ bind (notBool);
2323+
22892324 // cmp(Rflags, ctos);
22902325 __ br (Assembler::notEqual, false , Assembler::pt, notChar);
22912326 __ delayed () ->cmp (Rflags, stos);
@@ -2449,6 +2484,7 @@ void TemplateTable::jvmti_post_fast_field_mod() {
24492484 switch (bytecode ()) { // save tos values before call_VM() clobbers them
24502485 case Bytecodes::_fast_aputfield: __ push_ptr (Otos_i); break ;
24512486 case Bytecodes::_fast_bputfield: // fall through
2487+ case Bytecodes::_fast_zputfield: // fall through
24522488 case Bytecodes::_fast_sputfield: // fall through
24532489 case Bytecodes::_fast_cputfield: // fall through
24542490 case Bytecodes::_fast_iputfield: __ push_i (Otos_i); break ;
@@ -2466,6 +2502,7 @@ void TemplateTable::jvmti_post_fast_field_mod() {
24662502 switch (bytecode ()) { // restore tos values
24672503 case Bytecodes::_fast_aputfield: __ pop_ptr (Otos_i); break ;
24682504 case Bytecodes::_fast_bputfield: // fall through
2505+ case Bytecodes::_fast_zputfield: // fall through
24692506 case Bytecodes::_fast_sputfield: // fall through
24702507 case Bytecodes::_fast_cputfield: // fall through
24712508 case Bytecodes::_fast_iputfield: __ pop_i (Otos_i); break ;
@@ -2581,7 +2618,7 @@ void TemplateTable::putfield_or_static(int byte_no, bool is_static, RewriteContr
25812618 ConstantPoolCacheEntry::verify_tos_state_shift ();
25822619
25832620 // compute field type
2584- Label notInt, notShort, notChar, notObj, notByte, notLong, notFloat;
2621+ Label notInt, notShort, notChar, notObj, notByte, notBool, notLong, notFloat;
25852622
25862623 if (is_static) {
25872624 // putstatic with object type most likely, check that first
@@ -2649,7 +2686,7 @@ void TemplateTable::putfield_or_static(int byte_no, bool is_static, RewriteContr
26492686
26502687 // cmp(Rflags, btos);
26512688 __ br (Assembler::notEqual, false , Assembler::pt, notByte);
2652- __ delayed ()->cmp (Rflags, ltos );
2689+ __ delayed ()->cmp (Rflags, ztos );
26532690
26542691 // btos
26552692 {
@@ -2664,6 +2701,25 @@ void TemplateTable::putfield_or_static(int byte_no, bool is_static, RewriteContr
26642701 }
26652702
26662703 __ bind (notByte);
2704+
2705+ // cmp(Rflags, btos);
2706+ __ br (Assembler::notEqual, false , Assembler::pt, notBool);
2707+ __ delayed ()->cmp (Rflags, ltos);
2708+
2709+ // ztos
2710+ {
2711+ __ pop_i ();
2712+ if (!is_static) pop_and_check_object (Rclass);
2713+ __ and3 (Otos_i, 1 , Otos_i);
2714+ __ stb (Otos_i, Rclass, Roffset);
2715+ if (!is_static && rc == may_rewrite) {
2716+ patch_bytecode (Bytecodes::_fast_zputfield, G3_scratch, G4_scratch, true , byte_no);
2717+ }
2718+ __ ba (checkVolatile);
2719+ __ delayed ()->tst (Lscratch);
2720+ }
2721+
2722+ __ bind (notBool);
26672723 // cmp(Rflags, ltos);
26682724 __ br (Assembler::notEqual, false , Assembler::pt, notLong);
26692725 __ delayed ()->cmp (Rflags, ctos);
@@ -2787,6 +2843,7 @@ void TemplateTable::fast_storefield(TosState state) {
27872843 pop_and_check_object (Rclass);
27882844
27892845 switch (bytecode ()) {
2846+ case Bytecodes::_fast_zputfield: __ and3 (Otos_i, 1 , Otos_i); // fall through to bputfield
27902847 case Bytecodes::_fast_bputfield: __ stb (Otos_i, Rclass, Roffset); break ;
27912848 case Bytecodes::_fast_cputfield: /* fall through */
27922849 case Bytecodes::_fast_sputfield: __ sth (Otos_i, Rclass, Roffset); break ;
0 commit comments