src/hotspot/share/prims/stackwalk.cpp
author naoto
Tue, 09 Jul 2019 08:05:38 -0700
changeset 55627 9c1885fb2a42
parent 54786 ebf733a324d4
child 58177 4932dce35882
permissions -rw-r--r--
8227127: Era designator not displayed correctly using the COMPAT provider Reviewed-by: rriggs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
     1
/*
53205
8f79bae1a535 8214442: Improve stack walk API by adding handle marks
hseigel
parents: 49658
diff changeset
     2
 * Copyright (c) 2015, 2019, 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
#include "precompiled.hpp"
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    26
#include "classfile/javaClasses.hpp"
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    27
#include "classfile/javaClasses.inline.hpp"
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    28
#include "classfile/vmSymbols.hpp"
41664
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents: 41307
diff changeset
    29
#include "logging/log.hpp"
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46505
diff changeset
    30
#include "logging/logStream.hpp"
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    31
#include "memory/oopFactory.hpp"
54786
ebf733a324d4 8223624: Cleanup includes of universe.hpp
stefank
parents: 54432
diff changeset
    32
#include "memory/universe.hpp"
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    33
#include "oops/oop.inline.hpp"
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    34
#include "oops/objArrayOop.inline.hpp"
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    35
#include "prims/stackwalk.hpp"
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    36
#include "runtime/globals.hpp"
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    37
#include "runtime/handles.inline.hpp"
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    38
#include "runtime/javaCalls.hpp"
53590
ce36f8180d03 8218140: Build failures after JDK-8218041 (Assorted wrong/missing includes)
shade
parents: 53205
diff changeset
    39
#include "runtime/thread.inline.hpp"
49480
d7df2dd501ce 8199809: Don't include frame.inline.hpp and other.inline.hpp from .hpp files
coleenp
parents: 47818
diff changeset
    40
#include "runtime/vframe.inline.hpp"
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    41
#include "utilities/globalDefinitions.hpp"
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    42
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    43
// setup and cleanup actions
41280
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
    44
void BaseFrameStream::setup_magic_on_entry(objArrayHandle frames_array) {
37438
873c4aea8d1b 8153123: Streamline StackWalker code
bchristi
parents: 34253
diff changeset
    45
  frames_array->obj_at_put(magic_pos, _thread->threadObj());
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    46
  _anchor = address_value();
37438
873c4aea8d1b 8153123: Streamline StackWalker code
bchristi
parents: 34253
diff changeset
    47
  assert(check_magic(frames_array), "invalid magic");
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    48
}
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    49
41280
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
    50
bool BaseFrameStream::check_magic(objArrayHandle frames_array) {
37438
873c4aea8d1b 8153123: Streamline StackWalker code
bchristi
parents: 34253
diff changeset
    51
  oop   m1 = frames_array->obj_at(magic_pos);
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    52
  jlong m2 = _anchor;
49658
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents: 49480
diff changeset
    53
  if (oopDesc::equals(m1, _thread->threadObj()) && m2 == address_value())  return true;
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    54
  return false;
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
41280
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
    57
bool BaseFrameStream::cleanup_magic_on_exit(objArrayHandle frames_array) {
37438
873c4aea8d1b 8153123: Streamline StackWalker code
bchristi
parents: 34253
diff changeset
    58
  bool ok = check_magic(frames_array);
873c4aea8d1b 8153123: Streamline StackWalker code
bchristi
parents: 34253
diff changeset
    59
  frames_array->obj_at_put(magic_pos, NULL);
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    60
  _anchor = 0L;
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    61
  return ok;
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
41280
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
    64
JavaFrameStream::JavaFrameStream(JavaThread* thread, int mode)
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
    65
  : BaseFrameStream(thread), _vfst(thread) {
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
    66
  _need_method_info = StackWalk::need_method_info(mode);
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
    67
}
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
    68
49480
d7df2dd501ce 8199809: Don't include frame.inline.hpp and other.inline.hpp from .hpp files
coleenp
parents: 47818
diff changeset
    69
void JavaFrameStream::next() { _vfst.next();}
d7df2dd501ce 8199809: Don't include frame.inline.hpp and other.inline.hpp from .hpp files
coleenp
parents: 47818
diff changeset
    70
41280
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
    71
// Returns the BaseFrameStream for the current stack being traversed.
34253
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
// Parameters:
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    74
//  thread         Current Java thread.
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    75
//  magic          Magic value used for each stack walking
37438
873c4aea8d1b 8153123: Streamline StackWalker code
bchristi
parents: 34253
diff changeset
    76
//  frames_array   User-supplied buffers.  The 0th element is reserved
41280
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
    77
//                 for this BaseFrameStream to use
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    78
//
41280
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
    79
BaseFrameStream* BaseFrameStream::from_current(JavaThread* thread, jlong magic,
37438
873c4aea8d1b 8153123: Streamline StackWalker code
bchristi
parents: 34253
diff changeset
    80
                                               objArrayHandle frames_array)
34253
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
  assert(thread != NULL && thread->is_Java_thread(), "");
37438
873c4aea8d1b 8153123: Streamline StackWalker code
bchristi
parents: 34253
diff changeset
    83
  oop m1 = frames_array->obj_at(magic_pos);
49658
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents: 49480
diff changeset
    84
  if (!oopDesc::equals(m1, thread->threadObj())) return NULL;
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    85
  if (magic == 0L)                    return NULL;
41280
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
    86
  BaseFrameStream* stream = (BaseFrameStream*) (intptr_t) magic;
38213
2f32787e31b1 8147039: Incorrect locals and operands in compiled frames
bchristi
parents: 37438
diff changeset
    87
  if (!stream->is_valid_in(thread, frames_array))   return NULL;
2f32787e31b1 8147039: Incorrect locals and operands in compiled frames
bchristi
parents: 37438
diff changeset
    88
  return stream;
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    89
}
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
// Unpacks one or more frames into user-supplied buffers.
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    92
// Updates the end index, and returns the number of unpacked frames.
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    93
// Always start with the existing vfst.method and bci.
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    94
// Do not call vfst.next to advance over the last returned value.
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    95
// In other words, do not leave any stale data in the vfst.
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    96
//
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    97
// Parameters:
38213
2f32787e31b1 8147039: Incorrect locals and operands in compiled frames
bchristi
parents: 37438
diff changeset
    98
//   mode             Restrict which frames to be decoded.
41280
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
    99
//   BaseFrameStream  stream of frames
38213
2f32787e31b1 8147039: Incorrect locals and operands in compiled frames
bchristi
parents: 37438
diff changeset
   100
//   max_nframes      Maximum number of frames to be filled.
2f32787e31b1 8147039: Incorrect locals and operands in compiled frames
bchristi
parents: 37438
diff changeset
   101
//   start_index      Start index to the user-supplied buffers.
2f32787e31b1 8147039: Incorrect locals and operands in compiled frames
bchristi
parents: 37438
diff changeset
   102
//   frames_array     Buffer to store Class or StackFrame in, starting at start_index.
2f32787e31b1 8147039: Incorrect locals and operands in compiled frames
bchristi
parents: 37438
diff changeset
   103
//                    frames array is a Class<?>[] array when only getting caller
2f32787e31b1 8147039: Incorrect locals and operands in compiled frames
bchristi
parents: 37438
diff changeset
   104
//                    reference, and a StackFrameInfo[] array (or derivative)
2f32787e31b1 8147039: Incorrect locals and operands in compiled frames
bchristi
parents: 37438
diff changeset
   105
//                    otherwise. It should never be null.
2f32787e31b1 8147039: Incorrect locals and operands in compiled frames
bchristi
parents: 37438
diff changeset
   106
//   end_index        End index to the user-supplied buffers with unpacked frames.
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   107
//
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   108
// Returns the number of frames whose information was transferred into the buffers.
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   109
//
41280
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
   110
int StackWalk::fill_in_frames(jlong mode, BaseFrameStream& stream,
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   111
                              int max_nframes, int start_index,
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   112
                              objArrayHandle  frames_array,
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   113
                              int& end_index, TRAPS) {
41664
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents: 41307
diff changeset
   114
  log_debug(stackwalk)("fill_in_frames limit=%d start=%d frames length=%d",
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents: 41307
diff changeset
   115
                       max_nframes, start_index, frames_array->length());
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   116
  assert(max_nframes > 0, "invalid max_nframes");
37438
873c4aea8d1b 8153123: Streamline StackWalker code
bchristi
parents: 34253
diff changeset
   117
  assert(start_index + max_nframes <= frames_array->length(), "oob");
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   118
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   119
  int frames_decoded = 0;
38213
2f32787e31b1 8147039: Incorrect locals and operands in compiled frames
bchristi
parents: 37438
diff changeset
   120
  for (; !stream.at_end(); stream.next()) {
2f32787e31b1 8147039: Incorrect locals and operands in compiled frames
bchristi
parents: 37438
diff changeset
   121
    Method* method = stream.method();
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   122
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   123
    if (method == NULL) continue;
41095
97cca074c2be 8157464: Disallow StackWalker.getCallerClass() be called by caller-sensitive method
mchung
parents: 40001
diff changeset
   124
97cca074c2be 8157464: Disallow StackWalker.getCallerClass() be called by caller-sensitive method
mchung
parents: 40001
diff changeset
   125
    // skip hidden frames for default StackWalker option (i.e. SHOW_HIDDEN_FRAMES
97cca074c2be 8157464: Disallow StackWalker.getCallerClass() be called by caller-sensitive method
mchung
parents: 40001
diff changeset
   126
    // not set) and when StackWalker::getCallerClass is called
97cca074c2be 8157464: Disallow StackWalker.getCallerClass() be called by caller-sensitive method
mchung
parents: 40001
diff changeset
   127
    if (!ShowHiddenFrames && (skip_hidden_frames(mode) || get_caller_class(mode))) {
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   128
      if (method->is_hidden()) {
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46505
diff changeset
   129
        LogTarget(Debug, stackwalk) lt;
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46505
diff changeset
   130
        if (lt.is_enabled()) {
41664
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents: 41307
diff changeset
   131
          ResourceMark rm(THREAD);
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46505
diff changeset
   132
          LogStream ls(lt);
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46505
diff changeset
   133
          ls.print("  hidden method: ");
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46505
diff changeset
   134
          method->print_short_name(&ls);
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46505
diff changeset
   135
          ls.cr();
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   136
        }
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   137
        continue;
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   138
      }
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   139
    }
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   140
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   141
    int index = end_index++;
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46505
diff changeset
   142
    LogTarget(Debug, stackwalk) lt;
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46505
diff changeset
   143
    if (lt.is_enabled()) {
41664
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents: 41307
diff changeset
   144
      ResourceMark rm(THREAD);
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46505
diff changeset
   145
      LogStream ls(lt);
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46505
diff changeset
   146
      ls.print("  %d: frame method: ", index);
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46505
diff changeset
   147
      method->print_short_name(&ls);
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46505
diff changeset
   148
      ls.print_cr(" bci=%d", stream.bci());
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   149
    }
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   150
41280
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
   151
    if (!need_method_info(mode) && get_caller_class(mode) &&
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
   152
          index == start_index && method->caller_sensitive()) {
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
   153
      ResourceMark rm(THREAD);
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
   154
      THROW_MSG_0(vmSymbols::java_lang_UnsupportedOperationException(),
54432
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53590
diff changeset
   155
        err_msg("StackWalker::getCallerClass called from @CallerSensitive '%s' method",
532e88de77eb 8221470: Print methods in exception messages in java-like Syntax.
goetz
parents: 53590
diff changeset
   156
                method->external_name()));
41280
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
   157
    }
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   158
    // fill in StackFrameInfo and initialize MemberName
41280
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
   159
    stream.fill_frame(index, frames_array, method, CHECK_0);
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   160
    if (++frames_decoded >= max_nframes)  break;
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   161
  }
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   162
  return frames_decoded;
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   163
}
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   164
41280
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
   165
// Fill in the LiveStackFrameInfo at the given index in frames_array
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
   166
void LiveFrameStream::fill_frame(int index, objArrayHandle  frames_array,
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
   167
                                 const methodHandle& method, TRAPS) {
53205
8f79bae1a535 8214442: Improve stack walk API by adding handle marks
hseigel
parents: 49658
diff changeset
   168
  HandleMark hm(THREAD);
41280
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
   169
  Handle stackFrame(THREAD, frames_array->obj_at(index));
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
   170
  fill_live_stackframe(stackFrame, method, CHECK);
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
   171
}
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
   172
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
   173
// Fill in the StackFrameInfo at the given index in frames_array
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
   174
void JavaFrameStream::fill_frame(int index, objArrayHandle  frames_array,
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
   175
                                 const methodHandle& method, TRAPS) {
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
   176
  if (_need_method_info) {
53205
8f79bae1a535 8214442: Improve stack walk API by adding handle marks
hseigel
parents: 49658
diff changeset
   177
    HandleMark hm(THREAD);
41280
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
   178
    Handle stackFrame(THREAD, frames_array->obj_at(index));
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents: 46329
diff changeset
   179
    fill_stackframe(stackFrame, method, CHECK);
41280
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
   180
  } else {
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
   181
    frames_array->obj_at_put(index, method->method_holder()->java_mirror());
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
   182
  }
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
   183
}
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
   184
43677
5228814c1da2 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 41664
diff changeset
   185
// Create and return a LiveStackFrame.PrimitiveSlot (if needed) for the
5228814c1da2 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 41664
diff changeset
   186
// StackValue at the given index. 'type' is expected to be T_INT, T_LONG,
5228814c1da2 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 41664
diff changeset
   187
// T_OBJECT, or T_CONFLICT.
5228814c1da2 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 41664
diff changeset
   188
oop LiveFrameStream::create_primitive_slot_instance(StackValueCollection* values,
5228814c1da2 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 41664
diff changeset
   189
                                                    int i, BasicType type, TRAPS) {
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   190
  Klass* k = SystemDictionary::resolve_or_null(vmSymbols::java_lang_LiveStackFrameInfo(), CHECK_NULL);
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 46289
diff changeset
   191
  InstanceKlass* ik = InstanceKlass::cast(k);
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   192
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   193
  JavaValue result(T_OBJECT);
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   194
  JavaCallArguments args;
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   195
  Symbol* signature = NULL;
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   196
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   197
  // ## TODO: type is only available in LocalVariable table, if present.
43677
5228814c1da2 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 41664
diff changeset
   198
  // ## StackValue type is T_INT or T_OBJECT (or converted to T_LONG on 64-bit)
5228814c1da2 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 41664
diff changeset
   199
  switch (type) {
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   200
    case T_INT:
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   201
      args.push_int(values->int_at(i));
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   202
      signature = vmSymbols::asPrimitive_int_signature();
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   203
      break;
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   204
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   205
    case T_LONG:
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   206
      args.push_long(values->long_at(i));
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   207
      signature = vmSymbols::asPrimitive_long_signature();
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   208
      break;
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   209
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   210
    case T_FLOAT:
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   211
    case T_DOUBLE:
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   212
    case T_BYTE:
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   213
    case T_SHORT:
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   214
    case T_CHAR:
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   215
    case T_BOOLEAN:
43677
5228814c1da2 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 41664
diff changeset
   216
      THROW_MSG_(vmSymbols::java_lang_InternalError(), "Unexpected StackValue type", NULL);
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   217
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   218
    case T_OBJECT:
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   219
      return values->obj_at(i)();
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   220
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   221
    case T_CONFLICT:
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   222
      // put a non-null slot
43677
5228814c1da2 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 41664
diff changeset
   223
      #ifdef _LP64
5228814c1da2 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 41664
diff changeset
   224
        args.push_long(0);
5228814c1da2 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 41664
diff changeset
   225
        signature = vmSymbols::asPrimitive_long_signature();
5228814c1da2 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 41664
diff changeset
   226
      #else
5228814c1da2 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 41664
diff changeset
   227
        args.push_int(0);
5228814c1da2 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 41664
diff changeset
   228
        signature = vmSymbols::asPrimitive_int_signature();
5228814c1da2 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 41664
diff changeset
   229
      #endif
5228814c1da2 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 41664
diff changeset
   230
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   231
      break;
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   232
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   233
    default: ShouldNotReachHere();
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   234
  }
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   235
  JavaCalls::call_static(&result,
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   236
                         ik,
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   237
                         vmSymbols::asPrimitive_name(),
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   238
                         signature,
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   239
                         &args,
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   240
                         CHECK_NULL);
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   241
  return (instanceOop) result.get_jobject();
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   242
}
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   243
41280
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
   244
objArrayHandle LiveFrameStream::values_to_object_array(StackValueCollection* values, TRAPS) {
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   245
  objArrayHandle empty;
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   246
  int length = values->size();
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   247
  objArrayOop array_oop = oopFactory::new_objArray(SystemDictionary::Object_klass(),
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   248
                                                   length, CHECK_(empty));
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   249
  objArrayHandle array_h(THREAD, array_oop);
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   250
  for (int i = 0; i < values->size(); i++) {
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   251
    StackValue* st = values->at(i);
43677
5228814c1da2 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 41664
diff changeset
   252
    BasicType type = st->type();
5228814c1da2 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 41664
diff changeset
   253
    int index = i;
5228814c1da2 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 41664
diff changeset
   254
#ifdef _LP64
5228814c1da2 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 41664
diff changeset
   255
    if (type != T_OBJECT && type != T_CONFLICT) {
5228814c1da2 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 41664
diff changeset
   256
        intptr_t ret = st->get_int(); // read full 64-bit slot
5228814c1da2 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 41664
diff changeset
   257
        type = T_LONG;                // treat as long
5228814c1da2 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 41664
diff changeset
   258
        index--;                      // undo +1 in StackValueCollection::long_at
5228814c1da2 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 41664
diff changeset
   259
    }
5228814c1da2 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 41664
diff changeset
   260
#endif
5228814c1da2 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 41664
diff changeset
   261
    oop obj = create_primitive_slot_instance(values, index, type, CHECK_(empty));
5228814c1da2 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 41664
diff changeset
   262
    if (obj != NULL) {
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   263
      array_h->obj_at_put(i, obj);
43677
5228814c1da2 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 41664
diff changeset
   264
    }
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   265
  }
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   266
  return array_h;
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   267
}
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   268
41280
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
   269
objArrayHandle LiveFrameStream::monitors_to_object_array(GrowableArray<MonitorInfo*>* monitors, TRAPS) {
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   270
  int length = monitors->length();
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   271
  objArrayOop array_oop = oopFactory::new_objArray(SystemDictionary::Object_klass(),
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   272
                                                   length, CHECK_(objArrayHandle()));
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   273
  objArrayHandle array_h(THREAD, array_oop);
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   274
  for (int i = 0; i < length; i++) {
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   275
    MonitorInfo* monitor = monitors->at(i);
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   276
    array_h->obj_at_put(i, monitor->owner());
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   277
  }
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   278
  return array_h;
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   279
}
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   280
47818
2f6ab27efb60 8185925: StackFrameInfo::walker field can be replaced with bitmap to save footprint
bchristi
parents: 47216
diff changeset
   281
// Fill StackFrameInfo with bci and initialize memberName
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents: 46329
diff changeset
   282
void BaseFrameStream::fill_stackframe(Handle stackFrame, const methodHandle& method, TRAPS) {
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents: 46329
diff changeset
   283
  java_lang_StackFrameInfo::set_method_and_bci(stackFrame, method, bci(), THREAD);
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   284
}
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   285
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   286
// Fill LiveStackFrameInfo with locals, monitors, and expressions
41280
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
   287
void LiveFrameStream::fill_live_stackframe(Handle stackFrame,
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
   288
                                           const methodHandle& method, TRAPS) {
46505
fd4bc78630b1 8174749: Use hash table/oops for MemberName table
coleenp
parents: 46329
diff changeset
   289
  fill_stackframe(stackFrame, method, CHECK);
41280
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
   290
  if (_jvf != NULL) {
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
   291
    StackValueCollection* locals = _jvf->locals();
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
   292
    StackValueCollection* expressions = _jvf->expressions();
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
   293
    GrowableArray<MonitorInfo*>* monitors = _jvf->monitors();
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   294
43677
5228814c1da2 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 41664
diff changeset
   295
    int mode = 0;
5228814c1da2 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 41664
diff changeset
   296
    if (_jvf->is_interpreted_frame()) {
5228814c1da2 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 41664
diff changeset
   297
      mode = MODE_INTERPRETED;
5228814c1da2 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 41664
diff changeset
   298
    } else if (_jvf->is_compiled_frame()) {
5228814c1da2 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 41664
diff changeset
   299
      mode = MODE_COMPILED;
5228814c1da2 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 41664
diff changeset
   300
    }
5228814c1da2 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 41664
diff changeset
   301
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   302
    if (!locals->is_empty()) {
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   303
      objArrayHandle locals_h = values_to_object_array(locals, CHECK);
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   304
      java_lang_LiveStackFrameInfo::set_locals(stackFrame(), locals_h());
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   305
    }
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   306
    if (!expressions->is_empty()) {
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   307
      objArrayHandle expressions_h = values_to_object_array(expressions, CHECK);
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   308
      java_lang_LiveStackFrameInfo::set_operands(stackFrame(), expressions_h());
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   309
    }
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   310
    if (monitors->length() > 0) {
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   311
      objArrayHandle monitors_h = monitors_to_object_array(monitors, CHECK);
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   312
      java_lang_LiveStackFrameInfo::set_monitors(stackFrame(), monitors_h());
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   313
    }
43677
5228814c1da2 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 41664
diff changeset
   314
    java_lang_LiveStackFrameInfo::set_mode(stackFrame(), mode);
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   315
  }
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   316
}
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   317
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   318
// Begins stack walking.
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   319
//
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   320
// Parameters:
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   321
//   stackStream    StackStream object
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   322
//   mode           Stack walking mode.
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   323
//   skip_frames    Number of frames to be skipped.
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   324
//   frame_count    Number of frames to be traversed.
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   325
//   start_index    Start index to the user-supplied buffers.
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   326
//   frames_array   Buffer to store StackFrame in, starting at start_index.
37438
873c4aea8d1b 8153123: Streamline StackWalker code
bchristi
parents: 34253
diff changeset
   327
//                  frames array is a Class<?>[] array when only getting caller
873c4aea8d1b 8153123: Streamline StackWalker code
bchristi
parents: 34253
diff changeset
   328
//                  reference, and a StackFrameInfo[] array (or derivative)
873c4aea8d1b 8153123: Streamline StackWalker code
bchristi
parents: 34253
diff changeset
   329
//                  otherwise. It should never be null.
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   330
//
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   331
// Returns Object returned from AbstractStackWalker::doStackWalk call.
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   332
//
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   333
oop StackWalk::walk(Handle stackStream, jlong mode,
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   334
                    int skip_frames, int frame_count, int start_index,
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   335
                    objArrayHandle frames_array,
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   336
                    TRAPS) {
38213
2f32787e31b1 8147039: Incorrect locals and operands in compiled frames
bchristi
parents: 37438
diff changeset
   337
  ResourceMark rm(THREAD);
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   338
  JavaThread* jt = (JavaThread*)THREAD;
41664
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents: 41307
diff changeset
   339
  log_debug(stackwalk)("Start walking: mode " JLONG_FORMAT " skip %d frames batch size %d",
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents: 41307
diff changeset
   340
                       mode, skip_frames, frame_count);
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   341
37438
873c4aea8d1b 8153123: Streamline StackWalker code
bchristi
parents: 34253
diff changeset
   342
  if (frames_array.is_null()) {
873c4aea8d1b 8153123: Streamline StackWalker code
bchristi
parents: 34253
diff changeset
   343
    THROW_MSG_(vmSymbols::java_lang_NullPointerException(), "frames_array is NULL", NULL);
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   344
  }
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   345
41280
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
   346
  // Setup traversal onto my stack.
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
   347
  if (live_frame_info(mode)) {
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
   348
    assert (use_frames_array(mode), "Bad mode for get live frame");
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
   349
    RegisterMap regMap(jt, true);
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
   350
    LiveFrameStream stream(jt, &regMap);
41307
a89905798992 8166501: compilation error in stackwalk.cpp on some gccs
bchristi
parents: 41280
diff changeset
   351
    return fetchFirstBatch(stream, stackStream, mode, skip_frames, frame_count,
a89905798992 8166501: compilation error in stackwalk.cpp on some gccs
bchristi
parents: 41280
diff changeset
   352
                           start_index, frames_array, THREAD);
41280
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
   353
  } else {
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
   354
    JavaFrameStream stream(jt, mode);
41307
a89905798992 8166501: compilation error in stackwalk.cpp on some gccs
bchristi
parents: 41280
diff changeset
   355
    return fetchFirstBatch(stream, stackStream, mode, skip_frames, frame_count,
a89905798992 8166501: compilation error in stackwalk.cpp on some gccs
bchristi
parents: 41280
diff changeset
   356
                           start_index, frames_array, THREAD);
41280
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
   357
  }
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
   358
}
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   359
41280
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
   360
oop StackWalk::fetchFirstBatch(BaseFrameStream& stream, Handle stackStream,
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
   361
                               jlong mode, int skip_frames, int frame_count,
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
   362
                               int start_index, objArrayHandle frames_array, TRAPS) {
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   363
  methodHandle m_doStackWalk(THREAD, Universe::do_stack_walk_method());
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   364
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   365
  {
41280
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
   366
    Klass* stackWalker_klass = SystemDictionary::StackWalker_klass();
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
   367
    Klass* abstractStackWalker_klass = SystemDictionary::AbstractStackWalker_klass();
38213
2f32787e31b1 8147039: Incorrect locals and operands in compiled frames
bchristi
parents: 37438
diff changeset
   368
    while (!stream.at_end()) {
2f32787e31b1 8147039: Incorrect locals and operands in compiled frames
bchristi
parents: 37438
diff changeset
   369
      InstanceKlass* ik = stream.method()->method_holder();
37438
873c4aea8d1b 8153123: Streamline StackWalker code
bchristi
parents: 34253
diff changeset
   370
      if (ik != stackWalker_klass &&
873c4aea8d1b 8153123: Streamline StackWalker code
bchristi
parents: 34253
diff changeset
   371
            ik != abstractStackWalker_klass && ik->super() != abstractStackWalker_klass)  {
873c4aea8d1b 8153123: Streamline StackWalker code
bchristi
parents: 34253
diff changeset
   372
        break;
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   373
      }
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   374
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46505
diff changeset
   375
      LogTarget(Debug, stackwalk) lt;
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46505
diff changeset
   376
      if (lt.is_enabled()) {
41664
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents: 41307
diff changeset
   377
        ResourceMark rm(THREAD);
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46505
diff changeset
   378
        LogStream ls(lt);
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46505
diff changeset
   379
        ls.print("  skip ");
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46505
diff changeset
   380
        stream.method()->print_short_name(&ls);
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46505
diff changeset
   381
        ls.cr();
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   382
      }
38213
2f32787e31b1 8147039: Incorrect locals and operands in compiled frames
bchristi
parents: 37438
diff changeset
   383
      stream.next();
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   384
    }
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   385
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   386
    // stack frame has been traversed individually and resume stack walk
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   387
    // from the stack frame at depth == skip_frames.
38213
2f32787e31b1 8147039: Incorrect locals and operands in compiled frames
bchristi
parents: 37438
diff changeset
   388
    for (int n=0; n < skip_frames && !stream.at_end(); stream.next(), n++) {
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46505
diff changeset
   389
      LogTarget(Debug, stackwalk) lt;
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46505
diff changeset
   390
      if (lt.is_enabled()) {
41664
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents: 41307
diff changeset
   391
        ResourceMark rm(THREAD);
46701
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46505
diff changeset
   392
        LogStream ls(lt);
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46505
diff changeset
   393
        ls.print("  skip ");
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46505
diff changeset
   394
        stream.method()->print_short_name(&ls);
f559541c0daa 8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents: 46505
diff changeset
   395
        ls.cr();
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   396
      }
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   397
    }
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   398
  }
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   399
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   400
  int end_index = start_index;
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   401
  int numFrames = 0;
38213
2f32787e31b1 8147039: Incorrect locals and operands in compiled frames
bchristi
parents: 37438
diff changeset
   402
  if (!stream.at_end()) {
2f32787e31b1 8147039: Incorrect locals and operands in compiled frames
bchristi
parents: 37438
diff changeset
   403
    numFrames = fill_in_frames(mode, stream, frame_count, start_index,
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   404
                               frames_array, end_index, CHECK_NULL);
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   405
    if (numFrames < 1) {
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   406
      THROW_MSG_(vmSymbols::java_lang_InternalError(), "stack walk: decode failed", NULL);
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   407
    }
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   408
  }
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   409
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   410
  // JVM_CallStackWalk walks the stack and fills in stack frames, then calls to
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   411
  // Java method java.lang.StackStreamFactory.AbstractStackWalker::doStackWalk
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   412
  // which calls the implementation to consume the stack frames.
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   413
  // When JVM_CallStackWalk returns, it invalidates the stack stream.
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   414
  JavaValue result(T_OBJECT);
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   415
  JavaCallArguments args(stackStream);
38213
2f32787e31b1 8147039: Incorrect locals and operands in compiled frames
bchristi
parents: 37438
diff changeset
   416
  args.push_long(stream.address_value());
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   417
  args.push_int(skip_frames);
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   418
  args.push_int(frame_count);
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   419
  args.push_int(start_index);
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   420
  args.push_int(end_index);
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   421
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   422
  // Link the thread and vframe stream into the callee-visible object
38213
2f32787e31b1 8147039: Incorrect locals and operands in compiled frames
bchristi
parents: 37438
diff changeset
   423
  stream.setup_magic_on_entry(frames_array);
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   424
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   425
  JavaCalls::call(&result, m_doStackWalk, &args, THREAD);
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   426
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   427
  // Do this before anything else happens, to disable any lingering stream objects
38213
2f32787e31b1 8147039: Incorrect locals and operands in compiled frames
bchristi
parents: 37438
diff changeset
   428
  bool ok = stream.cleanup_magic_on_exit(frames_array);
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   429
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   430
  // Throw pending exception if we must
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   431
  (void) (CHECK_NULL);
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   432
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   433
  if (!ok) {
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   434
    THROW_MSG_(vmSymbols::java_lang_InternalError(), "doStackWalk: corrupted buffers on exit", NULL);
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   435
  }
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   436
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   437
  // Return normally
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   438
  return (oop)result.get_jobject();
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   439
}
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   440
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   441
// Walk the next batch of stack frames
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   442
//
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   443
// Parameters:
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   444
//   stackStream    StackStream object
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   445
//   mode           Stack walking mode.
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   446
//   magic          Must be valid value to continue the stack walk
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   447
//   frame_count    Number of frames to be decoded.
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   448
//   start_index    Start index to the user-supplied buffers.
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   449
//   frames_array   Buffer to store StackFrame in, starting at start_index.
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   450
//
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   451
// Returns the end index of frame filled in the buffer.
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   452
//
41280
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
   453
jint StackWalk::fetchNextBatch(Handle stackStream, jlong mode, jlong magic,
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
   454
                               int frame_count, int start_index,
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
   455
                               objArrayHandle frames_array,
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
   456
                               TRAPS)
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   457
{
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   458
  JavaThread* jt = (JavaThread*)THREAD;
41280
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
   459
  BaseFrameStream* existing_stream = BaseFrameStream::from_current(jt, magic, frames_array);
38213
2f32787e31b1 8147039: Incorrect locals and operands in compiled frames
bchristi
parents: 37438
diff changeset
   460
  if (existing_stream == NULL) {
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   461
    THROW_MSG_(vmSymbols::java_lang_InternalError(), "doStackWalk: corrupted buffers", 0L);
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   462
  }
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   463
37438
873c4aea8d1b 8153123: Streamline StackWalker code
bchristi
parents: 34253
diff changeset
   464
  if (frames_array.is_null()) {
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   465
    THROW_MSG_(vmSymbols::java_lang_NullPointerException(), "frames_array is NULL", 0L);
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   466
  }
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   467
41664
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents: 41307
diff changeset
   468
  log_debug(stackwalk)("StackWalk::fetchNextBatch frame_count %d existing_stream "
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents: 41307
diff changeset
   469
                       PTR_FORMAT " start %d frames %d",
07e88a4b405f 8160064: StackWalker implementation added logging option without using UL
rprotacio
parents: 41307
diff changeset
   470
                       frame_count, p2i(existing_stream), start_index, frames_array->length());
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   471
  int end_index = start_index;
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   472
  if (frame_count <= 0) {
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   473
    return end_index;        // No operation.
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   474
  }
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   475
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   476
  int count = frame_count + start_index;
37438
873c4aea8d1b 8153123: Streamline StackWalker code
bchristi
parents: 34253
diff changeset
   477
  assert (frames_array->length() >= count, "not enough space in buffers");
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   478
41280
74b314ad1e9a 8165372: StackWalker performance regression following JDK-8147039
bchristi
parents: 41095
diff changeset
   479
  BaseFrameStream& stream = (*existing_stream);
38213
2f32787e31b1 8147039: Incorrect locals and operands in compiled frames
bchristi
parents: 37438
diff changeset
   480
  if (!stream.at_end()) {
2f32787e31b1 8147039: Incorrect locals and operands in compiled frames
bchristi
parents: 37438
diff changeset
   481
    stream.next(); // advance past the last frame decoded in previous batch
2f32787e31b1 8147039: Incorrect locals and operands in compiled frames
bchristi
parents: 37438
diff changeset
   482
    if (!stream.at_end()) {
2f32787e31b1 8147039: Incorrect locals and operands in compiled frames
bchristi
parents: 37438
diff changeset
   483
      int n = fill_in_frames(mode, stream, frame_count, start_index,
34253
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   484
                             frames_array, end_index, CHECK_0);
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   485
      if (n < 1) {
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   486
        THROW_MSG_(vmSymbols::java_lang_InternalError(), "doStackWalk: later decode failed", 0L);
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   487
      }
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   488
      return end_index;
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   489
    }
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   490
  }
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   491
  return end_index;
ba3946143842 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   492
}