1 /*
 2  * Copyright (c) 2019, 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 
25 #ifndef SHARE_RUNTIME_SIGNATURE_CC_HPP
26 #define SHARE_RUNTIME_SIGNATURE_CC_HPP
27 
28 #include "runtime/signature.hpp"
29 
30 // Stream that iterates over a scalarized signature
31 class ScalarizedInlineArgsStream : public StackObj {
32   const GrowableArray<SigEntry>* _sig;
33   int _sig_idx;
34   const VMRegPair* _regs;
35   int _regs_count;
36   int _regs_idx;
37   int _depth;
38   int _step;
39   DEBUG_ONLY(bool _finished);
40 
41 public:
42   ScalarizedInlineArgsStream(const GrowableArray<SigEntry>* sig, int sig_idx, VMRegPair* regs, int regs_count, int regs_idx, int step = 1)
43     : _sig(sig), _sig_idx(sig_idx), _regs(regs), _regs_count(regs_count), _regs_idx(regs_idx), _step(step) {
44     assert(_sig->at(_sig_idx)._bt == (step > 0) ? T_INLINE_TYPE : T_VOID, "should be at inline type delimiter");
45     _depth = 1;
46     DEBUG_ONLY(_finished = false);
47   }
48 
49   bool next(VMReg& reg, BasicType& bt) {
50     assert(!_finished, "sanity");
51     do {
52       _sig_idx += _step;
53       bt = _sig->at(_sig_idx)._bt;
54       if (bt == T_INLINE_TYPE) {
55         _depth += _step;
56       } else if (bt == T_VOID &&
57                  _sig->at(_sig_idx-1)._bt != T_LONG &&
58                  _sig->at(_sig_idx-1)._bt != T_DOUBLE) {
59         _depth -= _step;
60       } else {
61         assert(_regs_idx >= 0 && _regs_idx < _regs_count, "out of bounds");
62         const VMRegPair pair = _regs[_regs_idx];
63         _regs_idx += _step;
64         reg = pair.first();
65         if (!reg->is_valid()) {
66           assert(!pair.second()->is_valid(), "must be invalid");
67         } else {
68           return true;
69         }
70       }
71     } while (_depth != 0);
72 
73     DEBUG_ONLY(_finished = true);
74     return false;
75   }
76 
77   int sig_index()  { return _sig_idx;  }
78   int regs_index() { return _regs_idx; }
79 };
80 
81 #endif // SHARE_RUNTIME_SIGNATURE_CC_HPP