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 reset(sig_idx, regs_idx);
45 }
46
47 bool next(VMReg& reg, BasicType& bt) {
48 assert(!_finished, "sanity");
49 do {
50 _sig_idx += _step;
51 bt = _sig->at(_sig_idx)._bt;
52 if (bt == T_METADATA) {
53 _depth += _step;
54 } else if (bt == T_VOID &&
55 _sig->at(_sig_idx-1)._bt != T_LONG &&
56 _sig->at(_sig_idx-1)._bt != T_DOUBLE) {
57 _depth -= _step;
58 } else {
59 assert(_regs_idx >= 0 && _regs_idx < _regs_count, "out of bounds");
60 const VMRegPair pair = _regs[_regs_idx];
61 _regs_idx += _step;
62 reg = pair.first();
63 if (!reg->is_valid()) {
64 assert(!pair.second()->is_valid(), "must be invalid");
65 } else {
66 return true;
67 }
68 }
69 } while (_depth != 0);
70
71 DEBUG_ONLY(_finished = true);
72 return false;
73 }
74
75 void reset(int sig_idx, int regs_idx) {
76 _sig_idx = sig_idx;
77 _regs_idx = regs_idx;
78 assert(_sig->at(_sig_idx)._bt == (_step > 0) ? T_METADATA : T_VOID, "should be at inline type delimiter");
79 _depth = 1;
80 DEBUG_ONLY(_finished = false);
81 }
82
83 int sig_index() { return _sig_idx; }
84 int regs_index() { return _regs_idx; }
85 };
86
87 #endif // SHARE_RUNTIME_SIGNATURE_CC_HPP