hotspot/src/share/vm/prims/stackwalk.hpp
author bchristi
Fri, 06 May 2016 22:45:32 -0700
changeset 38213 2f32787e31b1
parent 37438 873c4aea8d1b
child 40001 f37246e66d2b
permissions -rw-r--r--
8147039: Incorrect locals and operands in compiled frames Summary: Implement stack walking using javaVFrame instead of vframeStream Reviewed-by: mchung, vlivanov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
     1
/*
38213
2f32787e31b1 8147039: Incorrect locals and operands in compiled frames
bchristi
parents: 37438
diff changeset
     2
 * Copyright (c) 2015, 2016 Oracle and/or its affiliates. All rights reserved.
34253
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
38213
2f32787e31b1 8147039: Incorrect locals and operands in compiled frames
bchristi
parents: 37438
diff changeset
    32
//
2f32787e31b1 8147039: Incorrect locals and operands in compiled frames
bchristi
parents: 37438
diff changeset
    33
// JavaFrameStream is used by StackWalker to iterate through Java stack frames
2f32787e31b1 8147039: Incorrect locals and operands in compiled frames
bchristi
parents: 37438
diff changeset
    34
// on the given JavaThread.
2f32787e31b1 8147039: Incorrect locals and operands in compiled frames
bchristi
parents: 37438
diff changeset
    35
//
2f32787e31b1 8147039: Incorrect locals and operands in compiled frames
bchristi
parents: 37438
diff changeset
    36
class JavaFrameStream : public StackObj {
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    37
private:
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    38
  enum {
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    39
    magic_pos = 0
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    40
  };
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    41
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    42
  JavaThread*           _thread;
38213
2f32787e31b1 8147039: Incorrect locals and operands in compiled frames
bchristi
parents: 37438
diff changeset
    43
  javaVFrame*           _jvf;
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    44
  jlong                 _anchor;
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    45
public:
38213
2f32787e31b1 8147039: Incorrect locals and operands in compiled frames
bchristi
parents: 37438
diff changeset
    46
  JavaFrameStream(JavaThread* thread, RegisterMap* rm)
2f32787e31b1 8147039: Incorrect locals and operands in compiled frames
bchristi
parents: 37438
diff changeset
    47
    : _thread(thread), _anchor(0L) {
2f32787e31b1 8147039: Incorrect locals and operands in compiled frames
bchristi
parents: 37438
diff changeset
    48
    _jvf = _thread->last_java_vframe(rm);
2f32787e31b1 8147039: Incorrect locals and operands in compiled frames
bchristi
parents: 37438
diff changeset
    49
  }
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    50
38213
2f32787e31b1 8147039: Incorrect locals and operands in compiled frames
bchristi
parents: 37438
diff changeset
    51
  javaVFrame*     java_frame()        { return _jvf; }
2f32787e31b1 8147039: Incorrect locals and operands in compiled frames
bchristi
parents: 37438
diff changeset
    52
  void            next()              { _jvf = _jvf->java_sender(); }
2f32787e31b1 8147039: Incorrect locals and operands in compiled frames
bchristi
parents: 37438
diff changeset
    53
  bool            at_end()            { return _jvf == NULL; }
2f32787e31b1 8147039: Incorrect locals and operands in compiled frames
bchristi
parents: 37438
diff changeset
    54
2f32787e31b1 8147039: Incorrect locals and operands in compiled frames
bchristi
parents: 37438
diff changeset
    55
  Method* method()                    { return _jvf->method(); }
2f32787e31b1 8147039: Incorrect locals and operands in compiled frames
bchristi
parents: 37438
diff changeset
    56
  int bci()                           { return _jvf->bci(); }
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    57
37438
873c4aea8d1b 8153123: Streamline StackWalker code
bchristi
parents: 34253
diff changeset
    58
  void setup_magic_on_entry(objArrayHandle frames_array);
873c4aea8d1b 8153123: Streamline StackWalker code
bchristi
parents: 34253
diff changeset
    59
  bool check_magic(objArrayHandle frames_array);
873c4aea8d1b 8153123: Streamline StackWalker code
bchristi
parents: 34253
diff changeset
    60
  bool cleanup_magic_on_exit(objArrayHandle frames_array);
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    61
37438
873c4aea8d1b 8153123: Streamline StackWalker code
bchristi
parents: 34253
diff changeset
    62
  bool is_valid_in(Thread* thread, objArrayHandle frames_array) {
873c4aea8d1b 8153123: Streamline StackWalker code
bchristi
parents: 34253
diff changeset
    63
    return (_thread == thread && check_magic(frames_array));
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    64
  }
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    65
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    66
  jlong address_value() {
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    67
    return (jlong) castable_address(this);
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    68
  }
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    69
38213
2f32787e31b1 8147039: Incorrect locals and operands in compiled frames
bchristi
parents: 37438
diff changeset
    70
  static JavaFrameStream* from_current(JavaThread* thread, jlong magic, objArrayHandle frames_array);
34253
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
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    73
class StackWalk : public AllStatic {
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    74
private:
38213
2f32787e31b1 8147039: Incorrect locals and operands in compiled frames
bchristi
parents: 37438
diff changeset
    75
  static int fill_in_frames(jlong mode, JavaFrameStream& stream,
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    76
                            int max_nframes, int start_index,
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    77
                            objArrayHandle frames_array,
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    78
                            int& end_index, TRAPS);
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    79
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    80
  static void fill_stackframe(Handle stackFrame, const methodHandle& method, int bci);
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    81
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    82
  static void fill_live_stackframe(Handle stackFrame, const methodHandle& method, int bci,
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    83
                                   javaVFrame* jvf, TRAPS);
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
  static inline bool skip_hidden_frames(int mode) {
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    86
    return (mode & JVM_STACKWALK_SHOW_HIDDEN_FRAMES) == 0;
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    87
  }
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    88
  static inline bool need_method_info(int mode) {
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    89
    return (mode & JVM_STACKWALK_FILL_CLASS_REFS_ONLY) == 0;
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    90
  }
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    91
  static inline bool live_frame_info(int mode) {
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    92
    return (mode & JVM_STACKWALK_FILL_LIVE_STACK_FRAMES) != 0;
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
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    95
public:
37438
873c4aea8d1b 8153123: Streamline StackWalker code
bchristi
parents: 34253
diff changeset
    96
  static inline bool use_frames_array(int mode) {
873c4aea8d1b 8153123: Streamline StackWalker code
bchristi
parents: 34253
diff changeset
    97
    return (mode & JVM_STACKWALK_FILL_CLASS_REFS_ONLY) == 0;
873c4aea8d1b 8153123: Streamline StackWalker code
bchristi
parents: 34253
diff changeset
    98
  }
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    99
  static oop walk(Handle stackStream, jlong mode,
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   100
                  int skip_frames, int frame_count, int start_index,
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   101
                  objArrayHandle frames_array,
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   102
                  TRAPS);
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   103
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   104
  static jint moreFrames(Handle stackStream, jlong mode, jlong magic,
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   105
                         int frame_count, int start_index,
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   106
                         objArrayHandle frames_array,
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   107
                         TRAPS);
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   108
};
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   109
#endif // SHARE_VM_PRIMS_STACKWALK_HPP