hotspot/src/share/vm/prims/stackwalk.hpp
author bchristi
Fri, 08 Apr 2016 12:26:29 -0700
changeset 37438 873c4aea8d1b
parent 34253 ba3946143842
child 38213 2f32787e31b1
permissions -rw-r--r--
8153123: Streamline StackWalker code Reviewed-by: coleenp, dfuchs, mchung, redestad
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
     1
/*
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
     4
 *
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
     7
 * published by the Free Software Foundation.
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
     8
 *
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    13
 * accompanied this code).
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    14
 *
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    18
 *
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    21
 * questions.
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    22
 *
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    23
 */
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    24
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    25
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    26
#ifndef SHARE_VM_PRIMS_STACKWALK_HPP
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    27
#define SHARE_VM_PRIMS_STACKWALK_HPP
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    28
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    29
#include "oops/oop.hpp"
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    30
#include "runtime/vframe.hpp"
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    31
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    32
class StackWalkAnchor : public StackObj {
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    33
private:
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    34
  enum {
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    35
    magic_pos = 0
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    36
  };
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    37
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    38
  JavaThread*           _thread;
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    39
  vframeStream          _vfst;
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    40
  jlong                 _anchor;
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    41
public:
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    42
  StackWalkAnchor(JavaThread* thread)
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    43
    : _thread(thread), _vfst(thread), _anchor(0L) {}
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    44
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    45
  vframeStream&   vframe_stream()         { return _vfst; }
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    46
  JavaThread*     thread()                { return _thread; }
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    47
37438
873c4aea8d1b 8153123: Streamline StackWalker code
bchristi
parents: 34253
diff changeset
    48
  void setup_magic_on_entry(objArrayHandle frames_array);
873c4aea8d1b 8153123: Streamline StackWalker code
bchristi
parents: 34253
diff changeset
    49
  bool check_magic(objArrayHandle frames_array);
873c4aea8d1b 8153123: Streamline StackWalker code
bchristi
parents: 34253
diff changeset
    50
  bool cleanup_magic_on_exit(objArrayHandle frames_array);
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    51
37438
873c4aea8d1b 8153123: Streamline StackWalker code
bchristi
parents: 34253
diff changeset
    52
  bool is_valid_in(Thread* thread, objArrayHandle frames_array) {
873c4aea8d1b 8153123: Streamline StackWalker code
bchristi
parents: 34253
diff changeset
    53
    return (_thread == thread && check_magic(frames_array));
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    54
  }
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    55
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    56
  jlong address_value() {
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    57
    return (jlong) castable_address(this);
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    58
  }
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    59
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    60
  static StackWalkAnchor* from_current(JavaThread* thread, jlong anchor, objArrayHandle frames_array);
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    61
};
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    62
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    63
class StackWalk : public AllStatic {
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    64
private:
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    65
  static int fill_in_frames(jlong mode, vframeStream& vfst,
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    66
                            int max_nframes, int start_index,
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    67
                            objArrayHandle frames_array,
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    68
                            int& end_index, TRAPS);
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    69
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    70
  static void fill_stackframe(Handle stackFrame, const methodHandle& method, int bci);
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    71
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    72
  static void fill_live_stackframe(Handle stackFrame, const methodHandle& method, int bci,
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    73
                                   javaVFrame* jvf, TRAPS);
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    74
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    75
  static inline bool skip_hidden_frames(int mode) {
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    76
    return (mode & JVM_STACKWALK_SHOW_HIDDEN_FRAMES) == 0;
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    77
  }
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    78
  static inline bool need_method_info(int mode) {
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    79
    return (mode & JVM_STACKWALK_FILL_CLASS_REFS_ONLY) == 0;
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    80
  }
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    81
  static inline bool live_frame_info(int mode) {
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    82
    return (mode & JVM_STACKWALK_FILL_LIVE_STACK_FRAMES) != 0;
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    83
  }
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    84
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    85
public:
37438
873c4aea8d1b 8153123: Streamline StackWalker code
bchristi
parents: 34253
diff changeset
    86
  static inline bool use_frames_array(int mode) {
873c4aea8d1b 8153123: Streamline StackWalker code
bchristi
parents: 34253
diff changeset
    87
    return (mode & JVM_STACKWALK_FILL_CLASS_REFS_ONLY) == 0;
873c4aea8d1b 8153123: Streamline StackWalker code
bchristi
parents: 34253
diff changeset
    88
  }
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    89
  static oop walk(Handle stackStream, jlong mode,
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    90
                  int skip_frames, int frame_count, int start_index,
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    91
                  objArrayHandle frames_array,
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    92
                  TRAPS);
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    93
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    94
  static jint moreFrames(Handle stackStream, jlong mode, jlong magic,
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    95
                         int frame_count, int start_index,
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    96
                         objArrayHandle frames_array,
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    97
                         TRAPS);
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    98
};
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    99
#endif // SHARE_VM_PRIMS_STACKWALK_HPP