1 /*
2 * Copyright (c) 2020, 2024, 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_STACKCHUNKFRAMESTREAM_HPP
26 #define SHARE_RUNTIME_STACKCHUNKFRAMESTREAM_HPP
27
28 #include "memory/allocation.hpp"
29 #include "memory/iterator.hpp"
30 #include "oops/oopsHierarchy.hpp"
31 #include "utilities/globalDefinitions.hpp"
32 #include "utilities/macros.hpp"
33
34 class CodeBlob;
35 class frame;
36 class ImmutableOopMap;
37 class RegisterMap;
38 class VMRegImpl;
39 typedef VMRegImpl* VMReg;
40
41 enum ChunkFrames { CompiledOnly, Mixed };
42
43 template <ChunkFrames frame_kind>
44 class StackChunkFrameStream : public StackObj {
45 private:
46 intptr_t* _end;
47 intptr_t* _sp;
48 intptr_t* _unextended_sp; // used only when mixed
49 CodeBlob* _cb;
50 mutable const ImmutableOopMap* _oopmap;
51 bool _callee_augmented;
52
53 #ifndef PRODUCT
54 stackChunkOop _chunk;
55 int _index;
56 #endif
57
58 #ifdef ASSERT
59 int _has_stub;
60 #endif
61
62 public:
63 StackChunkFrameStream() { NOT_PRODUCT(_chunk = nullptr; _index = -1;) DEBUG_ONLY(_has_stub = false;) }
64 inline StackChunkFrameStream(stackChunkOop chunk);
65 inline StackChunkFrameStream(stackChunkOop chunk, const frame& f);
66
67 bool is_done() const { return _sp >= _end; }
68
69 // Query
70 intptr_t* sp() const { return _sp; }
71 inline address pc() const { return get_pc(); }
72 inline intptr_t* fp() const;
73 inline intptr_t* unextended_sp() const { return _unextended_sp; }
74 inline address orig_pc() const;
75
76 inline bool is_interpreted() const;
77 inline bool is_stub() const;
78 inline bool is_compiled() const;
79 CodeBlob* cb() const { return _cb; }
80 inline void get_cb();
81 const ImmutableOopMap* oopmap() const { if (_oopmap == nullptr) get_oopmap(); return _oopmap; }
82 inline int frame_size() const;
83 inline int stack_argsize() const;
84 template <typename RegisterMapT>
85 inline int num_oops(RegisterMapT* map) const;
86
87 inline void initialize_register_map(RegisterMap* map);
88 template <typename RegisterMapT> inline void next(RegisterMapT* map, bool stop = false);
89
90 template <typename RegisterMapT> inline void update_reg_map(RegisterMapT* map);
91
92 void handle_deopted() const;
93
94 inline frame to_frame() const;
95
96 #ifdef ASSERT
97 bool is_in_frame(void* p) const;
98 template <typename RegisterMapT> bool is_in_oops(void* p, const RegisterMapT* map) const;
99 #endif
100
101 void print_on(outputStream* st) const PRODUCT_RETURN;
102
103 private:
104 inline address get_pc() const;
105
106 inline int interpreter_frame_size() const;
107 template <typename RegisterMapT>
108 inline int interpreter_frame_num_oops(RegisterMapT* map) const;
109 inline int interpreter_frame_stack_argsize() const;
110 inline void next_for_interpreter_frame();
111 inline intptr_t* unextended_sp_for_interpreter_frame() const;
112 inline intptr_t* derelativize(int offset) const;
113 inline void get_oopmap() const;
114 inline void get_oopmap(address pc, int oopmap_slot) const;
115
116 template <typename RegisterMapT> inline void update_reg_map_pd(RegisterMapT* map);
117
118 template <typename RegisterMapT>
119 inline void* reg_to_loc(VMReg reg, const RegisterMapT* map) const;
120
121 void assert_is_interpreted_and_frame_type_mixed() const NOT_DEBUG_RETURN;
122
123 public:
124 template <class OopClosureType, class RegisterMapT>
125 inline void iterate_oops(OopClosureType* closure, const RegisterMapT* map) const;
126 template <class DerivedOopClosureType, class RegisterMapT>
127 inline void iterate_derived_pointers(DerivedOopClosureType* closure, const RegisterMapT* map) const;
128 };
129
130 class InterpreterOopCount : public OopClosure {
131 int _count;
132 public:
133 InterpreterOopCount() : _count(0) {}
134 void do_oop(oop* p) override { _count++; }
135 void do_oop(narrowOop* p) override { _count++; }
136 int count() { return _count; }
137 };
138
139 #endif // SHARE_RUNTIME_STACKCHUNKFRAMESTREAM_HPP