1 /* 2 * Copyright (c) 2015, 2016 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 26 #ifndef SHARE_VM_PRIMS_STACKWALK_HPP 27 #define SHARE_VM_PRIMS_STACKWALK_HPP 28 29 #include "oops/oop.hpp" 30 #include "runtime/vframe.hpp" 31 32 // 33 // JavaFrameStream is used by StackWalker to iterate through Java stack frames 34 // on the given JavaThread. 35 // 36 class JavaFrameStream : public StackObj { 37 private: 38 enum { 39 magic_pos = 0 40 }; 41 42 JavaThread* _thread; 43 javaVFrame* _jvf; 44 jlong _anchor; 45 public: 46 JavaFrameStream(JavaThread* thread, RegisterMap* rm) 47 : _thread(thread), _anchor(0L) { 48 _jvf = _thread->last_java_vframe(rm); 49 } 50 51 javaVFrame* java_frame() { return _jvf; } 52 void next() { _jvf = _jvf->java_sender(); } 53 bool at_end() { return _jvf == NULL; } 54 55 Method* method() { return _jvf->method(); } 56 int bci() { return _jvf->bci(); } 57 58 void setup_magic_on_entry(objArrayHandle frames_array); 59 bool check_magic(objArrayHandle frames_array); 60 bool cleanup_magic_on_exit(objArrayHandle frames_array); 61 62 bool is_valid_in(Thread* thread, objArrayHandle frames_array) { 63 return (_thread == thread && check_magic(frames_array)); 64 } 65 66 jlong address_value() { 67 return (jlong) castable_address(this); 68 } 69 70 static JavaFrameStream* from_current(JavaThread* thread, jlong magic, objArrayHandle frames_array); 71 }; 72 73 class StackWalk : public AllStatic { 74 private: 75 static int fill_in_frames(jlong mode, JavaFrameStream& stream, 76 int max_nframes, int start_index, 77 objArrayHandle frames_array, 78 int& end_index, TRAPS); 79 80 static void fill_stackframe(Handle stackFrame, const methodHandle& method, int bci); 81 82 static void fill_live_stackframe(Handle stackFrame, const methodHandle& method, int bci, 83 javaVFrame* jvf, TRAPS); 84 85 static inline bool skip_hidden_frames(int mode) { 86 return (mode & JVM_STACKWALK_SHOW_HIDDEN_FRAMES) == 0; 87 } 88 static inline bool need_method_info(int mode) { 89 return (mode & JVM_STACKWALK_FILL_CLASS_REFS_ONLY) == 0; 90 } 91 static inline bool live_frame_info(int mode) { 92 return (mode & JVM_STACKWALK_FILL_LIVE_STACK_FRAMES) != 0; 93 } 94 95 public: 96 static inline bool use_frames_array(int mode) { 97 return (mode & JVM_STACKWALK_FILL_CLASS_REFS_ONLY) == 0; 98 } 99 static oop walk(Handle stackStream, jlong mode, 100 int skip_frames, int frame_count, int start_index, 101 objArrayHandle frames_array, 102 TRAPS); 103 104 static jint moreFrames(Handle stackStream, jlong mode, jlong magic, 105 int frame_count, int start_index, 106 objArrayHandle frames_array, 107 TRAPS); 108 }; 109 #endif // SHARE_VM_PRIMS_STACKWALK_HPP