1 /*
 2  * Copyright (c) 2021, 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_STACKFRAMESTREAM_HPP
26 #define SHARE_RUNTIME_STACKFRAMESTREAM_HPP
27 
28 #include "memory/allocation.hpp"
29 #include "runtime/frame.hpp"
30 #include "runtime/registerMap.hpp"
31 
32 class JavaThread;
33 
34 //
35 // StackFrameStream iterates through the frames of a thread starting from
36 // top most frame. It automatically takes care of updating the location of
37 // all (callee-saved) registers iff the update flag is set. It also
38 // automatically takes care of lazily applying deferred GC processing
39 // onto exposed frames, such that all oops are valid iff the process_frames
40 // flag is set.
41 //
42 // Notice: If a thread is stopped at a safepoint, all registers are saved,
43 // not only the callee-saved ones.
44 //
45 // Use:
46 //
47 //   for(StackFrameStream fst(thread, true /* update */, true /* process_frames */);
48 //       !fst.is_done();
49 //       fst.next()) {
50 //     ...
51 //   }
52 //
53 class StackFrameStream : public StackObj {
54  private:
55   frame       _fr;
56   RegisterMap _reg_map;
57   bool        _is_done;
58  public:
59   StackFrameStream(JavaThread *thread, bool update, bool process_frames);
60 
61   // Iteration
62   inline bool is_done();
63   void next()                     { if (!_is_done) _fr = _fr.sender(&_reg_map); }
64 
65   // Query
66   frame *current()                { return &_fr; }
67   RegisterMap* register_map()     { return &_reg_map; }
68 };
69 
70 #endif // SHARE_RUNTIME_STACKFRAMESTREAM_HPP
71 
72