annotate src/share/vm/prims/jvmtiEnvBase.cpp @ 20197:ce8f6bb717c9

8042195: Introduce umbrella header orderAccess.inline.hpp. Reviewed-by: dholmes, kvn, stefank, twisti
author goetz
date Tue, 29 Apr 2014 15:17:27 +0200
parents 5ee250974db9
children 7848fc12602b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
7951
8b46b0196eb0 8000692: Remove old KERNEL code
zgu
parents: 6983
diff changeset
2 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1144
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1144
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1144
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1905
diff changeset
25 #include "precompiled.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1905
diff changeset
26 #include "classfile/systemDictionary.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1905
diff changeset
27 #include "jvmtifiles/jvmtiEnv.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1905
diff changeset
28 #include "oops/objArrayKlass.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1905
diff changeset
29 #include "oops/objArrayOop.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1905
diff changeset
30 #include "prims/jvmtiEnvBase.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1905
diff changeset
31 #include "prims/jvmtiEventController.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1905
diff changeset
32 #include "prims/jvmtiExtensions.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1905
diff changeset
33 #include "prims/jvmtiImpl.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1905
diff changeset
34 #include "prims/jvmtiManageCapabilities.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1905
diff changeset
35 #include "prims/jvmtiTagMap.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1905
diff changeset
36 #include "prims/jvmtiThreadState.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1905
diff changeset
37 #include "runtime/biasedLocking.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1905
diff changeset
38 #include "runtime/deoptimization.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1905
diff changeset
39 #include "runtime/interfaceSupport.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1905
diff changeset
40 #include "runtime/jfieldIDWorkaround.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1905
diff changeset
41 #include "runtime/objectMonitor.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1905
diff changeset
42 #include "runtime/objectMonitor.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1905
diff changeset
43 #include "runtime/signature.hpp"
20197
ce8f6bb717c9 8042195: Introduce umbrella header orderAccess.inline.hpp.
goetz
parents: 8673
diff changeset
44 #include "runtime/thread.inline.hpp"
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1905
diff changeset
45 #include "runtime/vframe.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1905
diff changeset
46 #include "runtime/vframe_hp.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1905
diff changeset
47 #include "runtime/vmThread.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1905
diff changeset
48 #include "runtime/vm_operations.hpp"
0
a61af66fc99e Initial load
duke
parents:
diff changeset
49
a61af66fc99e Initial load
duke
parents:
diff changeset
50 ///////////////////////////////////////////////////////////////
a61af66fc99e Initial load
duke
parents:
diff changeset
51 //
a61af66fc99e Initial load
duke
parents:
diff changeset
52 // JvmtiEnvBase
a61af66fc99e Initial load
duke
parents:
diff changeset
53 //
a61af66fc99e Initial load
duke
parents:
diff changeset
54
a61af66fc99e Initial load
duke
parents:
diff changeset
55 JvmtiEnvBase* JvmtiEnvBase::_head_environment = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
56
a61af66fc99e Initial load
duke
parents:
diff changeset
57 bool JvmtiEnvBase::_globally_initialized = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
58 volatile bool JvmtiEnvBase::_needs_clean_up = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
59
a61af66fc99e Initial load
duke
parents:
diff changeset
60 jvmtiPhase JvmtiEnvBase::_phase = JVMTI_PHASE_PRIMORDIAL;
a61af66fc99e Initial load
duke
parents:
diff changeset
61
a61af66fc99e Initial load
duke
parents:
diff changeset
62 volatile int JvmtiEnvBase::_dying_thread_env_iteration_count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
63
a61af66fc99e Initial load
duke
parents:
diff changeset
64 extern jvmtiInterface_1_ jvmti_Interface;
a61af66fc99e Initial load
duke
parents:
diff changeset
65 extern jvmtiInterface_1_ jvmtiTrace_Interface;
a61af66fc99e Initial load
duke
parents:
diff changeset
66
a61af66fc99e Initial load
duke
parents:
diff changeset
67
a61af66fc99e Initial load
duke
parents:
diff changeset
68 // perform initializations that must occur before any JVMTI environments
a61af66fc99e Initial load
duke
parents:
diff changeset
69 // are released but which should only be initialized once (no matter
a61af66fc99e Initial load
duke
parents:
diff changeset
70 // how many environments are created).
a61af66fc99e Initial load
duke
parents:
diff changeset
71 void
a61af66fc99e Initial load
duke
parents:
diff changeset
72 JvmtiEnvBase::globally_initialize() {
a61af66fc99e Initial load
duke
parents:
diff changeset
73 assert(Threads::number_of_threads() == 0 || JvmtiThreadState_lock->is_locked(), "sanity check");
a61af66fc99e Initial load
duke
parents:
diff changeset
74 assert(_globally_initialized == false, "bad call");
a61af66fc99e Initial load
duke
parents:
diff changeset
75
a61af66fc99e Initial load
duke
parents:
diff changeset
76 JvmtiManageCapabilities::initialize();
a61af66fc99e Initial load
duke
parents:
diff changeset
77
a61af66fc99e Initial load
duke
parents:
diff changeset
78 // register extension functions and events
a61af66fc99e Initial load
duke
parents:
diff changeset
79 JvmtiExtensions::register_extensions();
a61af66fc99e Initial load
duke
parents:
diff changeset
80
a61af66fc99e Initial load
duke
parents:
diff changeset
81 #ifdef JVMTI_TRACE
a61af66fc99e Initial load
duke
parents:
diff changeset
82 JvmtiTrace::initialize();
a61af66fc99e Initial load
duke
parents:
diff changeset
83 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
84
a61af66fc99e Initial load
duke
parents:
diff changeset
85 _globally_initialized = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
86 }
a61af66fc99e Initial load
duke
parents:
diff changeset
87
a61af66fc99e Initial load
duke
parents:
diff changeset
88
a61af66fc99e Initial load
duke
parents:
diff changeset
89 void
a61af66fc99e Initial load
duke
parents:
diff changeset
90 JvmtiEnvBase::initialize() {
a61af66fc99e Initial load
duke
parents:
diff changeset
91 assert(Threads::number_of_threads() == 0 || JvmtiThreadState_lock->is_locked(), "sanity check");
a61af66fc99e Initial load
duke
parents:
diff changeset
92
a61af66fc99e Initial load
duke
parents:
diff changeset
93 // Add this environment to the end of the environment list (order is important)
a61af66fc99e Initial load
duke
parents:
diff changeset
94 {
a61af66fc99e Initial load
duke
parents:
diff changeset
95 // This block of code must not contain any safepoints, as list deallocation
a61af66fc99e Initial load
duke
parents:
diff changeset
96 // (which occurs at a safepoint) cannot occur simultaneously with this list
a61af66fc99e Initial load
duke
parents:
diff changeset
97 // addition. Note: No_Safepoint_Verifier cannot, currently, be used before
a61af66fc99e Initial load
duke
parents:
diff changeset
98 // threads exist.
a61af66fc99e Initial load
duke
parents:
diff changeset
99 JvmtiEnvIterator it;
a61af66fc99e Initial load
duke
parents:
diff changeset
100 JvmtiEnvBase *previous_env = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
101 for (JvmtiEnvBase* env = it.first(); env != NULL; env = it.next(env)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
102 previous_env = env;
a61af66fc99e Initial load
duke
parents:
diff changeset
103 }
a61af66fc99e Initial load
duke
parents:
diff changeset
104 if (previous_env == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
105 _head_environment = this;
a61af66fc99e Initial load
duke
parents:
diff changeset
106 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
107 previous_env->set_next_environment(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
108 }
a61af66fc99e Initial load
duke
parents:
diff changeset
109 }
a61af66fc99e Initial load
duke
parents:
diff changeset
110
a61af66fc99e Initial load
duke
parents:
diff changeset
111 if (_globally_initialized == false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
112 globally_initialize();
a61af66fc99e Initial load
duke
parents:
diff changeset
113 }
a61af66fc99e Initial load
duke
parents:
diff changeset
114 }
a61af66fc99e Initial load
duke
parents:
diff changeset
115
a61af66fc99e Initial load
duke
parents:
diff changeset
116
611
2f716c0acb64 6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents: 609
diff changeset
117 bool
2f716c0acb64 6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents: 609
diff changeset
118 JvmtiEnvBase::is_valid() {
2f716c0acb64 6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents: 609
diff changeset
119 jint value = 0;
2f716c0acb64 6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents: 609
diff changeset
120
2f716c0acb64 6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents: 609
diff changeset
121 // This object might not be a JvmtiEnvBase so we can't assume
2f716c0acb64 6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents: 609
diff changeset
122 // the _magic field is properly aligned. Get the value in a safe
2f716c0acb64 6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents: 609
diff changeset
123 // way and then check against JVMTI_MAGIC.
2f716c0acb64 6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents: 609
diff changeset
124
2f716c0acb64 6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents: 609
diff changeset
125 switch (sizeof(_magic)) {
2f716c0acb64 6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents: 609
diff changeset
126 case 2:
2f716c0acb64 6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents: 609
diff changeset
127 value = Bytes::get_native_u2((address)&_magic);
2f716c0acb64 6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents: 609
diff changeset
128 break;
2f716c0acb64 6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents: 609
diff changeset
129
2f716c0acb64 6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents: 609
diff changeset
130 case 4:
2f716c0acb64 6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents: 609
diff changeset
131 value = Bytes::get_native_u4((address)&_magic);
2f716c0acb64 6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents: 609
diff changeset
132 break;
2f716c0acb64 6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents: 609
diff changeset
133
2f716c0acb64 6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents: 609
diff changeset
134 case 8:
2f716c0acb64 6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents: 609
diff changeset
135 value = Bytes::get_native_u8((address)&_magic);
2f716c0acb64 6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents: 609
diff changeset
136 break;
2f716c0acb64 6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents: 609
diff changeset
137
2f716c0acb64 6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents: 609
diff changeset
138 default:
2f716c0acb64 6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents: 609
diff changeset
139 guarantee(false, "_magic field is an unexpected size");
2f716c0acb64 6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents: 609
diff changeset
140 }
2f716c0acb64 6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents: 609
diff changeset
141
2f716c0acb64 6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents: 609
diff changeset
142 return value == JVMTI_MAGIC;
2f716c0acb64 6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents: 609
diff changeset
143 }
2f716c0acb64 6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents: 609
diff changeset
144
2f716c0acb64 6567360: 3/4 SIGBUS in jvmti RawMonitor magic check for unaligned bad monitor pointer
dcubed
parents: 609
diff changeset
145
1122
dcubed
parents: 844 1121
diff changeset
146 bool
1121
98cd9901c161 6849968: 3/2 JVMTI tests fails on jdk5.0 with hs14
dcubed
parents: 470
diff changeset
147 JvmtiEnvBase::use_version_1_0_semantics() {
98cd9901c161 6849968: 3/2 JVMTI tests fails on jdk5.0 with hs14
dcubed
parents: 470
diff changeset
148 int major, minor, micro;
98cd9901c161 6849968: 3/2 JVMTI tests fails on jdk5.0 with hs14
dcubed
parents: 470
diff changeset
149
98cd9901c161 6849968: 3/2 JVMTI tests fails on jdk5.0 with hs14
dcubed
parents: 470
diff changeset
150 JvmtiExport::decode_version_values(_version, &major, &minor, &micro);
98cd9901c161 6849968: 3/2 JVMTI tests fails on jdk5.0 with hs14
dcubed
parents: 470
diff changeset
151 return major == 1 && minor == 0; // micro version doesn't matter here
98cd9901c161 6849968: 3/2 JVMTI tests fails on jdk5.0 with hs14
dcubed
parents: 470
diff changeset
152 }
98cd9901c161 6849968: 3/2 JVMTI tests fails on jdk5.0 with hs14
dcubed
parents: 470
diff changeset
153
98cd9901c161 6849968: 3/2 JVMTI tests fails on jdk5.0 with hs14
dcubed
parents: 470
diff changeset
154
98cd9901c161 6849968: 3/2 JVMTI tests fails on jdk5.0 with hs14
dcubed
parents: 470
diff changeset
155 bool
98cd9901c161 6849968: 3/2 JVMTI tests fails on jdk5.0 with hs14
dcubed
parents: 470
diff changeset
156 JvmtiEnvBase::use_version_1_1_semantics() {
98cd9901c161 6849968: 3/2 JVMTI tests fails on jdk5.0 with hs14
dcubed
parents: 470
diff changeset
157 int major, minor, micro;
98cd9901c161 6849968: 3/2 JVMTI tests fails on jdk5.0 with hs14
dcubed
parents: 470
diff changeset
158
98cd9901c161 6849968: 3/2 JVMTI tests fails on jdk5.0 with hs14
dcubed
parents: 470
diff changeset
159 JvmtiExport::decode_version_values(_version, &major, &minor, &micro);
98cd9901c161 6849968: 3/2 JVMTI tests fails on jdk5.0 with hs14
dcubed
parents: 470
diff changeset
160 return major == 1 && minor == 1; // micro version doesn't matter here
98cd9901c161 6849968: 3/2 JVMTI tests fails on jdk5.0 with hs14
dcubed
parents: 470
diff changeset
161 }
98cd9901c161 6849968: 3/2 JVMTI tests fails on jdk5.0 with hs14
dcubed
parents: 470
diff changeset
162
1988
684faacebf20 7003782: Update JVMTI version to 1.2 for jdk7
kamg
parents: 1972
diff changeset
163 bool
684faacebf20 7003782: Update JVMTI version to 1.2 for jdk7
kamg
parents: 1972
diff changeset
164 JvmtiEnvBase::use_version_1_2_semantics() {
684faacebf20 7003782: Update JVMTI version to 1.2 for jdk7
kamg
parents: 1972
diff changeset
165 int major, minor, micro;
684faacebf20 7003782: Update JVMTI version to 1.2 for jdk7
kamg
parents: 1972
diff changeset
166
684faacebf20 7003782: Update JVMTI version to 1.2 for jdk7
kamg
parents: 1972
diff changeset
167 JvmtiExport::decode_version_values(_version, &major, &minor, &micro);
684faacebf20 7003782: Update JVMTI version to 1.2 for jdk7
kamg
parents: 1972
diff changeset
168 return major == 1 && minor == 2; // micro version doesn't matter here
684faacebf20 7003782: Update JVMTI version to 1.2 for jdk7
kamg
parents: 1972
diff changeset
169 }
684faacebf20 7003782: Update JVMTI version to 1.2 for jdk7
kamg
parents: 1972
diff changeset
170
1121
98cd9901c161 6849968: 3/2 JVMTI tests fails on jdk5.0 with hs14
dcubed
parents: 470
diff changeset
171
98cd9901c161 6849968: 3/2 JVMTI tests fails on jdk5.0 with hs14
dcubed
parents: 470
diff changeset
172 JvmtiEnvBase::JvmtiEnvBase(jint version) : _env_event_enable() {
98cd9901c161 6849968: 3/2 JVMTI tests fails on jdk5.0 with hs14
dcubed
parents: 470
diff changeset
173 _version = version;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
174 _env_local_storage = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
175 _tag_map = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
176 _native_method_prefix_count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
177 _native_method_prefixes = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
178 _next = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
179 _class_file_load_hook_ever_enabled = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
180
a61af66fc99e Initial load
duke
parents:
diff changeset
181 // Moot since ClassFileLoadHook not yet enabled.
a61af66fc99e Initial load
duke
parents:
diff changeset
182 // But "true" will give a more predictable ClassFileLoadHook behavior
a61af66fc99e Initial load
duke
parents:
diff changeset
183 // for environment creation during ClassFileLoadHook.
a61af66fc99e Initial load
duke
parents:
diff changeset
184 _is_retransformable = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
185
a61af66fc99e Initial load
duke
parents:
diff changeset
186 // all callbacks initially NULL
a61af66fc99e Initial load
duke
parents:
diff changeset
187 memset(&_event_callbacks,0,sizeof(jvmtiEventCallbacks));
a61af66fc99e Initial load
duke
parents:
diff changeset
188
a61af66fc99e Initial load
duke
parents:
diff changeset
189 // all capabilities initially off
a61af66fc99e Initial load
duke
parents:
diff changeset
190 memset(&_current_capabilities, 0, sizeof(_current_capabilities));
a61af66fc99e Initial load
duke
parents:
diff changeset
191
a61af66fc99e Initial load
duke
parents:
diff changeset
192 // all prohibited capabilities initially off
a61af66fc99e Initial load
duke
parents:
diff changeset
193 memset(&_prohibited_capabilities, 0, sizeof(_prohibited_capabilities));
a61af66fc99e Initial load
duke
parents:
diff changeset
194
a61af66fc99e Initial load
duke
parents:
diff changeset
195 _magic = JVMTI_MAGIC;
a61af66fc99e Initial load
duke
parents:
diff changeset
196
a61af66fc99e Initial load
duke
parents:
diff changeset
197 JvmtiEventController::env_initialize((JvmtiEnv*)this);
a61af66fc99e Initial load
duke
parents:
diff changeset
198
a61af66fc99e Initial load
duke
parents:
diff changeset
199 #ifdef JVMTI_TRACE
371
dbec32712472 6753795: HotSpot crash in strlen() when JVMTI is used
never
parents: 0
diff changeset
200 _jvmti_external.functions = TraceJVMTI != NULL ? &jvmtiTrace_Interface : &jvmti_Interface;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
201 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
202 _jvmti_external.functions = &jvmti_Interface;
a61af66fc99e Initial load
duke
parents:
diff changeset
203 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
204 }
a61af66fc99e Initial load
duke
parents:
diff changeset
205
a61af66fc99e Initial load
duke
parents:
diff changeset
206
a61af66fc99e Initial load
duke
parents:
diff changeset
207 void
a61af66fc99e Initial load
duke
parents:
diff changeset
208 JvmtiEnvBase::dispose() {
a61af66fc99e Initial load
duke
parents:
diff changeset
209
a61af66fc99e Initial load
duke
parents:
diff changeset
210 #ifdef JVMTI_TRACE
a61af66fc99e Initial load
duke
parents:
diff changeset
211 JvmtiTrace::shutdown();
a61af66fc99e Initial load
duke
parents:
diff changeset
212 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
213
a61af66fc99e Initial load
duke
parents:
diff changeset
214 // Dispose of event info and let the event controller call us back
a61af66fc99e Initial load
duke
parents:
diff changeset
215 // in a locked state (env_dispose, below)
a61af66fc99e Initial load
duke
parents:
diff changeset
216 JvmtiEventController::env_dispose(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
217 }
a61af66fc99e Initial load
duke
parents:
diff changeset
218
a61af66fc99e Initial load
duke
parents:
diff changeset
219 void
a61af66fc99e Initial load
duke
parents:
diff changeset
220 JvmtiEnvBase::env_dispose() {
a61af66fc99e Initial load
duke
parents:
diff changeset
221 assert(Threads::number_of_threads() == 0 || JvmtiThreadState_lock->is_locked(), "sanity check");
a61af66fc99e Initial load
duke
parents:
diff changeset
222
a61af66fc99e Initial load
duke
parents:
diff changeset
223 // We have been entered with all events disabled on this environment.
a61af66fc99e Initial load
duke
parents:
diff changeset
224 // A race to re-enable events (by setting callbacks) is prevented by
a61af66fc99e Initial load
duke
parents:
diff changeset
225 // checking for a valid environment when setting callbacks (while
a61af66fc99e Initial load
duke
parents:
diff changeset
226 // holding the JvmtiThreadState_lock).
a61af66fc99e Initial load
duke
parents:
diff changeset
227
a61af66fc99e Initial load
duke
parents:
diff changeset
228 // Mark as invalid.
a61af66fc99e Initial load
duke
parents:
diff changeset
229 _magic = DISPOSED_MAGIC;
a61af66fc99e Initial load
duke
parents:
diff changeset
230
a61af66fc99e Initial load
duke
parents:
diff changeset
231 // Relinquish all capabilities.
a61af66fc99e Initial load
duke
parents:
diff changeset
232 jvmtiCapabilities *caps = get_capabilities();
a61af66fc99e Initial load
duke
parents:
diff changeset
233 JvmtiManageCapabilities::relinquish_capabilities(caps, caps, caps);
a61af66fc99e Initial load
duke
parents:
diff changeset
234
a61af66fc99e Initial load
duke
parents:
diff changeset
235 // Same situation as with events (see above)
a61af66fc99e Initial load
duke
parents:
diff changeset
236 set_native_method_prefixes(0, NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
237
a61af66fc99e Initial load
duke
parents:
diff changeset
238 JvmtiTagMap* tag_map_to_deallocate = _tag_map;
a61af66fc99e Initial load
duke
parents:
diff changeset
239 set_tag_map(NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
240 // A tag map can be big, deallocate it now
a61af66fc99e Initial load
duke
parents:
diff changeset
241 if (tag_map_to_deallocate != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
242 delete tag_map_to_deallocate;
a61af66fc99e Initial load
duke
parents:
diff changeset
243 }
a61af66fc99e Initial load
duke
parents:
diff changeset
244
a61af66fc99e Initial load
duke
parents:
diff changeset
245 _needs_clean_up = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
246 }
a61af66fc99e Initial load
duke
parents:
diff changeset
247
a61af66fc99e Initial load
duke
parents:
diff changeset
248
a61af66fc99e Initial load
duke
parents:
diff changeset
249 JvmtiEnvBase::~JvmtiEnvBase() {
a61af66fc99e Initial load
duke
parents:
diff changeset
250 assert(SafepointSynchronize::is_at_safepoint(), "sanity check");
a61af66fc99e Initial load
duke
parents:
diff changeset
251
a61af66fc99e Initial load
duke
parents:
diff changeset
252 // There is a small window of time during which the tag map of a
a61af66fc99e Initial load
duke
parents:
diff changeset
253 // disposed environment could have been reallocated.
a61af66fc99e Initial load
duke
parents:
diff changeset
254 // Make sure it is gone.
a61af66fc99e Initial load
duke
parents:
diff changeset
255 JvmtiTagMap* tag_map_to_deallocate = _tag_map;
a61af66fc99e Initial load
duke
parents:
diff changeset
256 set_tag_map(NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
257 // A tag map can be big, deallocate it now
a61af66fc99e Initial load
duke
parents:
diff changeset
258 if (tag_map_to_deallocate != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
259 delete tag_map_to_deallocate;
a61af66fc99e Initial load
duke
parents:
diff changeset
260 }
a61af66fc99e Initial load
duke
parents:
diff changeset
261
a61af66fc99e Initial load
duke
parents:
diff changeset
262 _magic = BAD_MAGIC;
a61af66fc99e Initial load
duke
parents:
diff changeset
263 }
a61af66fc99e Initial load
duke
parents:
diff changeset
264
a61af66fc99e Initial load
duke
parents:
diff changeset
265
a61af66fc99e Initial load
duke
parents:
diff changeset
266 void
a61af66fc99e Initial load
duke
parents:
diff changeset
267 JvmtiEnvBase::periodic_clean_up() {
a61af66fc99e Initial load
duke
parents:
diff changeset
268 assert(SafepointSynchronize::is_at_safepoint(), "sanity check");
a61af66fc99e Initial load
duke
parents:
diff changeset
269
a61af66fc99e Initial load
duke
parents:
diff changeset
270 // JvmtiEnvBase reference is saved in JvmtiEnvThreadState. So
a61af66fc99e Initial load
duke
parents:
diff changeset
271 // clean up JvmtiThreadState before deleting JvmtiEnv pointer.
a61af66fc99e Initial load
duke
parents:
diff changeset
272 JvmtiThreadState::periodic_clean_up();
a61af66fc99e Initial load
duke
parents:
diff changeset
273
a61af66fc99e Initial load
duke
parents:
diff changeset
274 // Unlink all invalid environments from the list of environments
a61af66fc99e Initial load
duke
parents:
diff changeset
275 // and deallocate them
a61af66fc99e Initial load
duke
parents:
diff changeset
276 JvmtiEnvIterator it;
a61af66fc99e Initial load
duke
parents:
diff changeset
277 JvmtiEnvBase* previous_env = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
278 JvmtiEnvBase* env = it.first();
a61af66fc99e Initial load
duke
parents:
diff changeset
279 while (env != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
280 if (env->is_valid()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
281 previous_env = env;
a61af66fc99e Initial load
duke
parents:
diff changeset
282 env = it.next(env);
a61af66fc99e Initial load
duke
parents:
diff changeset
283 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
284 // This one isn't valid, remove it from the list and deallocate it
a61af66fc99e Initial load
duke
parents:
diff changeset
285 JvmtiEnvBase* defunct_env = env;
a61af66fc99e Initial load
duke
parents:
diff changeset
286 env = it.next(env);
a61af66fc99e Initial load
duke
parents:
diff changeset
287 if (previous_env == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
288 _head_environment = env;
a61af66fc99e Initial load
duke
parents:
diff changeset
289 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
290 previous_env->set_next_environment(env);
a61af66fc99e Initial load
duke
parents:
diff changeset
291 }
a61af66fc99e Initial load
duke
parents:
diff changeset
292 delete defunct_env;
a61af66fc99e Initial load
duke
parents:
diff changeset
293 }
a61af66fc99e Initial load
duke
parents:
diff changeset
294 }
a61af66fc99e Initial load
duke
parents:
diff changeset
295
a61af66fc99e Initial load
duke
parents:
diff changeset
296 }
a61af66fc99e Initial load
duke
parents:
diff changeset
297
a61af66fc99e Initial load
duke
parents:
diff changeset
298
a61af66fc99e Initial load
duke
parents:
diff changeset
299 void
a61af66fc99e Initial load
duke
parents:
diff changeset
300 JvmtiEnvBase::check_for_periodic_clean_up() {
a61af66fc99e Initial load
duke
parents:
diff changeset
301 assert(SafepointSynchronize::is_at_safepoint(), "sanity check");
a61af66fc99e Initial load
duke
parents:
diff changeset
302
a61af66fc99e Initial load
duke
parents:
diff changeset
303 class ThreadInsideIterationClosure: public ThreadClosure {
a61af66fc99e Initial load
duke
parents:
diff changeset
304 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
305 bool _inside;
a61af66fc99e Initial load
duke
parents:
diff changeset
306 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
307 ThreadInsideIterationClosure() : _inside(false) {};
a61af66fc99e Initial load
duke
parents:
diff changeset
308
a61af66fc99e Initial load
duke
parents:
diff changeset
309 void do_thread(Thread* thread) {
a61af66fc99e Initial load
duke
parents:
diff changeset
310 _inside |= thread->is_inside_jvmti_env_iteration();
a61af66fc99e Initial load
duke
parents:
diff changeset
311 }
a61af66fc99e Initial load
duke
parents:
diff changeset
312
a61af66fc99e Initial load
duke
parents:
diff changeset
313 bool is_inside_jvmti_env_iteration() {
a61af66fc99e Initial load
duke
parents:
diff changeset
314 return _inside;
a61af66fc99e Initial load
duke
parents:
diff changeset
315 }
a61af66fc99e Initial load
duke
parents:
diff changeset
316 };
a61af66fc99e Initial load
duke
parents:
diff changeset
317
a61af66fc99e Initial load
duke
parents:
diff changeset
318 if (_needs_clean_up) {
a61af66fc99e Initial load
duke
parents:
diff changeset
319 // Check if we are currently iterating environment,
a61af66fc99e Initial load
duke
parents:
diff changeset
320 // deallocation should not occur if we are
a61af66fc99e Initial load
duke
parents:
diff changeset
321 ThreadInsideIterationClosure tiic;
a61af66fc99e Initial load
duke
parents:
diff changeset
322 Threads::threads_do(&tiic);
a61af66fc99e Initial load
duke
parents:
diff changeset
323 if (!tiic.is_inside_jvmti_env_iteration() &&
a61af66fc99e Initial load
duke
parents:
diff changeset
324 !is_inside_dying_thread_env_iteration()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
325 _needs_clean_up = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
326 JvmtiEnvBase::periodic_clean_up();
a61af66fc99e Initial load
duke
parents:
diff changeset
327 }
a61af66fc99e Initial load
duke
parents:
diff changeset
328 }
a61af66fc99e Initial load
duke
parents:
diff changeset
329 }
a61af66fc99e Initial load
duke
parents:
diff changeset
330
a61af66fc99e Initial load
duke
parents:
diff changeset
331
a61af66fc99e Initial load
duke
parents:
diff changeset
332 void
a61af66fc99e Initial load
duke
parents:
diff changeset
333 JvmtiEnvBase::record_first_time_class_file_load_hook_enabled() {
a61af66fc99e Initial load
duke
parents:
diff changeset
334 assert(Threads::number_of_threads() == 0 || JvmtiThreadState_lock->is_locked(),
a61af66fc99e Initial load
duke
parents:
diff changeset
335 "sanity check");
a61af66fc99e Initial load
duke
parents:
diff changeset
336
a61af66fc99e Initial load
duke
parents:
diff changeset
337 if (!_class_file_load_hook_ever_enabled) {
a61af66fc99e Initial load
duke
parents:
diff changeset
338 _class_file_load_hook_ever_enabled = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
339
a61af66fc99e Initial load
duke
parents:
diff changeset
340 if (get_capabilities()->can_retransform_classes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
341 _is_retransformable = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
342 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
343 _is_retransformable = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
344
a61af66fc99e Initial load
duke
parents:
diff changeset
345 // cannot add retransform capability after ClassFileLoadHook has been enabled
a61af66fc99e Initial load
duke
parents:
diff changeset
346 get_prohibited_capabilities()->can_retransform_classes = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
347 }
a61af66fc99e Initial load
duke
parents:
diff changeset
348 }
a61af66fc99e Initial load
duke
parents:
diff changeset
349 }
a61af66fc99e Initial load
duke
parents:
diff changeset
350
a61af66fc99e Initial load
duke
parents:
diff changeset
351
a61af66fc99e Initial load
duke
parents:
diff changeset
352 void
a61af66fc99e Initial load
duke
parents:
diff changeset
353 JvmtiEnvBase::record_class_file_load_hook_enabled() {
a61af66fc99e Initial load
duke
parents:
diff changeset
354 if (!_class_file_load_hook_ever_enabled) {
a61af66fc99e Initial load
duke
parents:
diff changeset
355 if (Threads::number_of_threads() == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
356 record_first_time_class_file_load_hook_enabled();
a61af66fc99e Initial load
duke
parents:
diff changeset
357 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
358 MutexLocker mu(JvmtiThreadState_lock);
a61af66fc99e Initial load
duke
parents:
diff changeset
359 record_first_time_class_file_load_hook_enabled();
a61af66fc99e Initial load
duke
parents:
diff changeset
360 }
a61af66fc99e Initial load
duke
parents:
diff changeset
361 }
a61af66fc99e Initial load
duke
parents:
diff changeset
362 }
a61af66fc99e Initial load
duke
parents:
diff changeset
363
a61af66fc99e Initial load
duke
parents:
diff changeset
364
a61af66fc99e Initial load
duke
parents:
diff changeset
365 jvmtiError
a61af66fc99e Initial load
duke
parents:
diff changeset
366 JvmtiEnvBase::set_native_method_prefixes(jint prefix_count, char** prefixes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
367 assert(Threads::number_of_threads() == 0 || JvmtiThreadState_lock->is_locked(),
a61af66fc99e Initial load
duke
parents:
diff changeset
368 "sanity check");
a61af66fc99e Initial load
duke
parents:
diff changeset
369
a61af66fc99e Initial load
duke
parents:
diff changeset
370 int old_prefix_count = get_native_method_prefix_count();
a61af66fc99e Initial load
duke
parents:
diff changeset
371 char **old_prefixes = get_native_method_prefixes();
a61af66fc99e Initial load
duke
parents:
diff changeset
372
a61af66fc99e Initial load
duke
parents:
diff changeset
373 // allocate and install the new prefixex
a61af66fc99e Initial load
duke
parents:
diff changeset
374 if (prefix_count == 0 || !is_valid()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
375 _native_method_prefix_count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
376 _native_method_prefixes = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
377 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
378 // there are prefixes, allocate an array to hold them, and fill it
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 3938
diff changeset
379 char** new_prefixes = (char**)os::malloc((prefix_count) * sizeof(char*), mtInternal);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
380 if (new_prefixes == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
381 return JVMTI_ERROR_OUT_OF_MEMORY;
a61af66fc99e Initial load
duke
parents:
diff changeset
382 }
a61af66fc99e Initial load
duke
parents:
diff changeset
383 for (int i = 0; i < prefix_count; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
384 char* prefix = prefixes[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
385 if (prefix == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
386 for (int j = 0; j < (i-1); j++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
387 os::free(new_prefixes[j]);
a61af66fc99e Initial load
duke
parents:
diff changeset
388 }
a61af66fc99e Initial load
duke
parents:
diff changeset
389 os::free(new_prefixes);
a61af66fc99e Initial load
duke
parents:
diff changeset
390 return JVMTI_ERROR_NULL_POINTER;
a61af66fc99e Initial load
duke
parents:
diff changeset
391 }
a61af66fc99e Initial load
duke
parents:
diff changeset
392 prefix = os::strdup(prefixes[i]);
a61af66fc99e Initial load
duke
parents:
diff changeset
393 if (prefix == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
394 for (int j = 0; j < (i-1); j++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
395 os::free(new_prefixes[j]);
a61af66fc99e Initial load
duke
parents:
diff changeset
396 }
a61af66fc99e Initial load
duke
parents:
diff changeset
397 os::free(new_prefixes);
a61af66fc99e Initial load
duke
parents:
diff changeset
398 return JVMTI_ERROR_OUT_OF_MEMORY;
a61af66fc99e Initial load
duke
parents:
diff changeset
399 }
a61af66fc99e Initial load
duke
parents:
diff changeset
400 new_prefixes[i] = prefix;
a61af66fc99e Initial load
duke
parents:
diff changeset
401 }
a61af66fc99e Initial load
duke
parents:
diff changeset
402 _native_method_prefix_count = prefix_count;
a61af66fc99e Initial load
duke
parents:
diff changeset
403 _native_method_prefixes = new_prefixes;
a61af66fc99e Initial load
duke
parents:
diff changeset
404 }
a61af66fc99e Initial load
duke
parents:
diff changeset
405
a61af66fc99e Initial load
duke
parents:
diff changeset
406 // now that we know the new prefixes have been successfully installed we can
a61af66fc99e Initial load
duke
parents:
diff changeset
407 // safely remove the old ones
a61af66fc99e Initial load
duke
parents:
diff changeset
408 if (old_prefix_count != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
409 for (int i = 0; i < old_prefix_count; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
410 os::free(old_prefixes[i]);
a61af66fc99e Initial load
duke
parents:
diff changeset
411 }
a61af66fc99e Initial load
duke
parents:
diff changeset
412 os::free(old_prefixes);
a61af66fc99e Initial load
duke
parents:
diff changeset
413 }
a61af66fc99e Initial load
duke
parents:
diff changeset
414
a61af66fc99e Initial load
duke
parents:
diff changeset
415 return JVMTI_ERROR_NONE;
a61af66fc99e Initial load
duke
parents:
diff changeset
416 }
a61af66fc99e Initial load
duke
parents:
diff changeset
417
a61af66fc99e Initial load
duke
parents:
diff changeset
418
a61af66fc99e Initial load
duke
parents:
diff changeset
419 // Collect all the prefixes which have been set in any JVM TI environments
a61af66fc99e Initial load
duke
parents:
diff changeset
420 // by the SetNativeMethodPrefix(es) functions. Be sure to maintain the
a61af66fc99e Initial load
duke
parents:
diff changeset
421 // order of environments and the order of prefixes within each environment.
a61af66fc99e Initial load
duke
parents:
diff changeset
422 // Return in a resource allocated array.
a61af66fc99e Initial load
duke
parents:
diff changeset
423 char**
a61af66fc99e Initial load
duke
parents:
diff changeset
424 JvmtiEnvBase::get_all_native_method_prefixes(int* count_ptr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
425 assert(Threads::number_of_threads() == 0 ||
a61af66fc99e Initial load
duke
parents:
diff changeset
426 SafepointSynchronize::is_at_safepoint() ||
a61af66fc99e Initial load
duke
parents:
diff changeset
427 JvmtiThreadState_lock->is_locked(),
a61af66fc99e Initial load
duke
parents:
diff changeset
428 "sanity check");
a61af66fc99e Initial load
duke
parents:
diff changeset
429
a61af66fc99e Initial load
duke
parents:
diff changeset
430 int total_count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
431 GrowableArray<char*>* prefix_array =new GrowableArray<char*>(5);
a61af66fc99e Initial load
duke
parents:
diff changeset
432
a61af66fc99e Initial load
duke
parents:
diff changeset
433 JvmtiEnvIterator it;
a61af66fc99e Initial load
duke
parents:
diff changeset
434 for (JvmtiEnvBase* env = it.first(); env != NULL; env = it.next(env)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
435 int prefix_count = env->get_native_method_prefix_count();
a61af66fc99e Initial load
duke
parents:
diff changeset
436 char** prefixes = env->get_native_method_prefixes();
a61af66fc99e Initial load
duke
parents:
diff changeset
437 for (int j = 0; j < prefix_count; j++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
438 // retrieve a prefix and so that it is safe against asynchronous changes
a61af66fc99e Initial load
duke
parents:
diff changeset
439 // copy it into the resource area
a61af66fc99e Initial load
duke
parents:
diff changeset
440 char* prefix = prefixes[j];
a61af66fc99e Initial load
duke
parents:
diff changeset
441 char* prefix_copy = NEW_RESOURCE_ARRAY(char, strlen(prefix)+1);
a61af66fc99e Initial load
duke
parents:
diff changeset
442 strcpy(prefix_copy, prefix);
a61af66fc99e Initial load
duke
parents:
diff changeset
443 prefix_array->at_put_grow(total_count++, prefix_copy);
a61af66fc99e Initial load
duke
parents:
diff changeset
444 }
a61af66fc99e Initial load
duke
parents:
diff changeset
445 }
a61af66fc99e Initial load
duke
parents:
diff changeset
446
a61af66fc99e Initial load
duke
parents:
diff changeset
447 char** all_prefixes = NEW_RESOURCE_ARRAY(char*, total_count);
a61af66fc99e Initial load
duke
parents:
diff changeset
448 char** p = all_prefixes;
a61af66fc99e Initial load
duke
parents:
diff changeset
449 for (int i = 0; i < total_count; ++i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
450 *p++ = prefix_array->at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
451 }
a61af66fc99e Initial load
duke
parents:
diff changeset
452 *count_ptr = total_count;
a61af66fc99e Initial load
duke
parents:
diff changeset
453 return all_prefixes;
a61af66fc99e Initial load
duke
parents:
diff changeset
454 }
a61af66fc99e Initial load
duke
parents:
diff changeset
455
a61af66fc99e Initial load
duke
parents:
diff changeset
456 void
a61af66fc99e Initial load
duke
parents:
diff changeset
457 JvmtiEnvBase::set_event_callbacks(const jvmtiEventCallbacks* callbacks,
a61af66fc99e Initial load
duke
parents:
diff changeset
458 jint size_of_callbacks) {
a61af66fc99e Initial load
duke
parents:
diff changeset
459 assert(Threads::number_of_threads() == 0 || JvmtiThreadState_lock->is_locked(), "sanity check");
a61af66fc99e Initial load
duke
parents:
diff changeset
460
a61af66fc99e Initial load
duke
parents:
diff changeset
461 size_t byte_cnt = sizeof(jvmtiEventCallbacks);
a61af66fc99e Initial load
duke
parents:
diff changeset
462
a61af66fc99e Initial load
duke
parents:
diff changeset
463 // clear in either case to be sure we got any gap between sizes
a61af66fc99e Initial load
duke
parents:
diff changeset
464 memset(&_event_callbacks, 0, byte_cnt);
a61af66fc99e Initial load
duke
parents:
diff changeset
465
a61af66fc99e Initial load
duke
parents:
diff changeset
466 // Now that JvmtiThreadState_lock is held, prevent a possible race condition where events
a61af66fc99e Initial load
duke
parents:
diff changeset
467 // are re-enabled by a call to set event callbacks where the DisposeEnvironment
a61af66fc99e Initial load
duke
parents:
diff changeset
468 // occurs after the boiler-plate environment check and before the lock is acquired.
a61af66fc99e Initial load
duke
parents:
diff changeset
469 if (callbacks != NULL && is_valid()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
470 if (size_of_callbacks < (jint)byte_cnt) {
a61af66fc99e Initial load
duke
parents:
diff changeset
471 byte_cnt = size_of_callbacks;
a61af66fc99e Initial load
duke
parents:
diff changeset
472 }
a61af66fc99e Initial load
duke
parents:
diff changeset
473 memcpy(&_event_callbacks, callbacks, byte_cnt);
a61af66fc99e Initial load
duke
parents:
diff changeset
474 }
a61af66fc99e Initial load
duke
parents:
diff changeset
475 }
a61af66fc99e Initial load
duke
parents:
diff changeset
476
a61af66fc99e Initial load
duke
parents:
diff changeset
477 // Called from JVMTI entry points which perform stack walking. If the
a61af66fc99e Initial load
duke
parents:
diff changeset
478 // associated JavaThread is the current thread, then wait_for_suspend
a61af66fc99e Initial load
duke
parents:
diff changeset
479 // is not used. Otherwise, it determines if we should wait for the
a61af66fc99e Initial load
duke
parents:
diff changeset
480 // "other" thread to complete external suspension. (NOTE: in future
a61af66fc99e Initial load
duke
parents:
diff changeset
481 // releases the suspension mechanism should be reimplemented so this
a61af66fc99e Initial load
duke
parents:
diff changeset
482 // is not necessary.)
a61af66fc99e Initial load
duke
parents:
diff changeset
483 //
a61af66fc99e Initial load
duke
parents:
diff changeset
484 bool
a61af66fc99e Initial load
duke
parents:
diff changeset
485 JvmtiEnvBase::is_thread_fully_suspended(JavaThread* thr, bool wait_for_suspend, uint32_t *bits) {
a61af66fc99e Initial load
duke
parents:
diff changeset
486 // "other" threads require special handling
a61af66fc99e Initial load
duke
parents:
diff changeset
487 if (thr != JavaThread::current()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
488 if (wait_for_suspend) {
a61af66fc99e Initial load
duke
parents:
diff changeset
489 // We are allowed to wait for the external suspend to complete
a61af66fc99e Initial load
duke
parents:
diff changeset
490 // so give the other thread a chance to get suspended.
a61af66fc99e Initial load
duke
parents:
diff changeset
491 if (!thr->wait_for_ext_suspend_completion(SuspendRetryCount,
a61af66fc99e Initial load
duke
parents:
diff changeset
492 SuspendRetryDelay, bits)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
493 // didn't make it so let the caller know
a61af66fc99e Initial load
duke
parents:
diff changeset
494 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
495 }
a61af66fc99e Initial load
duke
parents:
diff changeset
496 }
a61af66fc99e Initial load
duke
parents:
diff changeset
497 // We aren't allowed to wait for the external suspend to complete
a61af66fc99e Initial load
duke
parents:
diff changeset
498 // so if the other thread isn't externally suspended we need to
a61af66fc99e Initial load
duke
parents:
diff changeset
499 // let the caller know.
a61af66fc99e Initial load
duke
parents:
diff changeset
500 else if (!thr->is_ext_suspend_completed_with_lock(bits)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
501 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
502 }
a61af66fc99e Initial load
duke
parents:
diff changeset
503 }
a61af66fc99e Initial load
duke
parents:
diff changeset
504
a61af66fc99e Initial load
duke
parents:
diff changeset
505 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
506 }
a61af66fc99e Initial load
duke
parents:
diff changeset
507
a61af66fc99e Initial load
duke
parents:
diff changeset
508
a61af66fc99e Initial load
duke
parents:
diff changeset
509 // In the fullness of time, all users of the method should instead
a61af66fc99e Initial load
duke
parents:
diff changeset
510 // directly use allocate, besides being cleaner and faster, this will
a61af66fc99e Initial load
duke
parents:
diff changeset
511 // mean much better out of memory handling
a61af66fc99e Initial load
duke
parents:
diff changeset
512 unsigned char *
a61af66fc99e Initial load
duke
parents:
diff changeset
513 JvmtiEnvBase::jvmtiMalloc(jlong size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
514 unsigned char* mem;
a61af66fc99e Initial load
duke
parents:
diff changeset
515 jvmtiError result = allocate(size, &mem);
a61af66fc99e Initial load
duke
parents:
diff changeset
516 assert(result == JVMTI_ERROR_NONE, "Allocate failed");
a61af66fc99e Initial load
duke
parents:
diff changeset
517 return mem;
a61af66fc99e Initial load
duke
parents:
diff changeset
518 }
a61af66fc99e Initial load
duke
parents:
diff changeset
519
a61af66fc99e Initial load
duke
parents:
diff changeset
520
a61af66fc99e Initial load
duke
parents:
diff changeset
521 //
a61af66fc99e Initial load
duke
parents:
diff changeset
522 // Threads
a61af66fc99e Initial load
duke
parents:
diff changeset
523 //
a61af66fc99e Initial load
duke
parents:
diff changeset
524
a61af66fc99e Initial load
duke
parents:
diff changeset
525 jobject *
a61af66fc99e Initial load
duke
parents:
diff changeset
526 JvmtiEnvBase::new_jobjectArray(int length, Handle *handles) {
a61af66fc99e Initial load
duke
parents:
diff changeset
527 if (length == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
528 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
529 }
a61af66fc99e Initial load
duke
parents:
diff changeset
530
a61af66fc99e Initial load
duke
parents:
diff changeset
531 jobject *objArray = (jobject *) jvmtiMalloc(sizeof(jobject) * length);
a61af66fc99e Initial load
duke
parents:
diff changeset
532 NULL_CHECK(objArray, NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
533
a61af66fc99e Initial load
duke
parents:
diff changeset
534 for (int i=0; i<length; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
535 objArray[i] = jni_reference(handles[i]);
a61af66fc99e Initial load
duke
parents:
diff changeset
536 }
a61af66fc99e Initial load
duke
parents:
diff changeset
537 return objArray;
a61af66fc99e Initial load
duke
parents:
diff changeset
538 }
a61af66fc99e Initial load
duke
parents:
diff changeset
539
a61af66fc99e Initial load
duke
parents:
diff changeset
540 jthread *
a61af66fc99e Initial load
duke
parents:
diff changeset
541 JvmtiEnvBase::new_jthreadArray(int length, Handle *handles) {
a61af66fc99e Initial load
duke
parents:
diff changeset
542 return (jthread *) new_jobjectArray(length,handles);
a61af66fc99e Initial load
duke
parents:
diff changeset
543 }
a61af66fc99e Initial load
duke
parents:
diff changeset
544
a61af66fc99e Initial load
duke
parents:
diff changeset
545 jthreadGroup *
a61af66fc99e Initial load
duke
parents:
diff changeset
546 JvmtiEnvBase::new_jthreadGroupArray(int length, Handle *handles) {
a61af66fc99e Initial load
duke
parents:
diff changeset
547 return (jthreadGroup *) new_jobjectArray(length,handles);
a61af66fc99e Initial load
duke
parents:
diff changeset
548 }
a61af66fc99e Initial load
duke
parents:
diff changeset
549
a61af66fc99e Initial load
duke
parents:
diff changeset
550
a61af66fc99e Initial load
duke
parents:
diff changeset
551 JavaThread *
a61af66fc99e Initial load
duke
parents:
diff changeset
552 JvmtiEnvBase::get_JavaThread(jthread jni_thread) {
a61af66fc99e Initial load
duke
parents:
diff changeset
553 oop t = JNIHandles::resolve_external_guard(jni_thread);
1142
4ce7240d622c 6914300: ciEnv should export all well known classes
never
parents: 844
diff changeset
554 if (t == NULL || !t->is_a(SystemDictionary::Thread_klass())) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
555 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
556 }
a61af66fc99e Initial load
duke
parents:
diff changeset
557 // The following returns NULL if the thread has not yet run or is in
a61af66fc99e Initial load
duke
parents:
diff changeset
558 // process of exiting
a61af66fc99e Initial load
duke
parents:
diff changeset
559 return java_lang_Thread::thread(t);
a61af66fc99e Initial load
duke
parents:
diff changeset
560 }
a61af66fc99e Initial load
duke
parents:
diff changeset
561
a61af66fc99e Initial load
duke
parents:
diff changeset
562
a61af66fc99e Initial load
duke
parents:
diff changeset
563 // return the vframe on the specified thread and depth, NULL if no such frame
a61af66fc99e Initial load
duke
parents:
diff changeset
564 vframe*
a61af66fc99e Initial load
duke
parents:
diff changeset
565 JvmtiEnvBase::vframeFor(JavaThread* java_thread, jint depth) {
a61af66fc99e Initial load
duke
parents:
diff changeset
566 if (!java_thread->has_last_Java_frame()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
567 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
568 }
a61af66fc99e Initial load
duke
parents:
diff changeset
569 RegisterMap reg_map(java_thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
570 vframe *vf = java_thread->last_java_vframe(&reg_map);
a61af66fc99e Initial load
duke
parents:
diff changeset
571 int d = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
572 while ((vf != NULL) && (d < depth)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
573 vf = vf->java_sender();
a61af66fc99e Initial load
duke
parents:
diff changeset
574 d++;
a61af66fc99e Initial load
duke
parents:
diff changeset
575 }
a61af66fc99e Initial load
duke
parents:
diff changeset
576 return vf;
a61af66fc99e Initial load
duke
parents:
diff changeset
577 }
a61af66fc99e Initial load
duke
parents:
diff changeset
578
a61af66fc99e Initial load
duke
parents:
diff changeset
579
a61af66fc99e Initial load
duke
parents:
diff changeset
580 //
a61af66fc99e Initial load
duke
parents:
diff changeset
581 // utilities: JNI objects
a61af66fc99e Initial load
duke
parents:
diff changeset
582 //
a61af66fc99e Initial load
duke
parents:
diff changeset
583
a61af66fc99e Initial load
duke
parents:
diff changeset
584
a61af66fc99e Initial load
duke
parents:
diff changeset
585 jclass
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
586 JvmtiEnvBase::get_jni_class_non_null(Klass* k) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
587 assert(k != NULL, "k != NULL");
6983
070d523b96a7 8001471: Klass::cast() does nothing
hseigel
parents: 6725
diff changeset
588 return (jclass)jni_reference(k->java_mirror());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
589 }
a61af66fc99e Initial load
duke
parents:
diff changeset
590
a61af66fc99e Initial load
duke
parents:
diff changeset
591 //
a61af66fc99e Initial load
duke
parents:
diff changeset
592 // Field Information
a61af66fc99e Initial load
duke
parents:
diff changeset
593 //
a61af66fc99e Initial load
duke
parents:
diff changeset
594
a61af66fc99e Initial load
duke
parents:
diff changeset
595 bool
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
596 JvmtiEnvBase::get_field_descriptor(Klass* k, jfieldID field, fieldDescriptor* fd) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
597 if (!jfieldIDWorkaround::is_valid_jfieldID(k, field)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
598 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
599 }
a61af66fc99e Initial load
duke
parents:
diff changeset
600 bool found = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
601 if (jfieldIDWorkaround::is_static_jfieldID(field)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
602 JNIid* id = jfieldIDWorkaround::from_static_jfieldID(field);
2376
c7f3d0b4570f 7017732: move static fields into Class to prepare for perm gen removal
never
parents: 2177
diff changeset
603 found = id->find_local_field(fd);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
604 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
605 // Non-static field. The fieldID is really the offset of the field within the object.
a61af66fc99e Initial load
duke
parents:
diff changeset
606 int offset = jfieldIDWorkaround::from_instance_jfieldID(k, field);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
607 found = InstanceKlass::cast(k)->find_field_from_offset(offset, false, fd);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
608 }
a61af66fc99e Initial load
duke
parents:
diff changeset
609 return found;
a61af66fc99e Initial load
duke
parents:
diff changeset
610 }
a61af66fc99e Initial load
duke
parents:
diff changeset
611
a61af66fc99e Initial load
duke
parents:
diff changeset
612 //
a61af66fc99e Initial load
duke
parents:
diff changeset
613 // Object Monitor Information
a61af66fc99e Initial load
duke
parents:
diff changeset
614 //
a61af66fc99e Initial load
duke
parents:
diff changeset
615
a61af66fc99e Initial load
duke
parents:
diff changeset
616 //
a61af66fc99e Initial load
duke
parents:
diff changeset
617 // Count the number of objects for a lightweight monitor. The hobj
a61af66fc99e Initial load
duke
parents:
diff changeset
618 // parameter is object that owns the monitor so this routine will
a61af66fc99e Initial load
duke
parents:
diff changeset
619 // count the number of times the same object was locked by frames
a61af66fc99e Initial load
duke
parents:
diff changeset
620 // in java_thread.
a61af66fc99e Initial load
duke
parents:
diff changeset
621 //
a61af66fc99e Initial load
duke
parents:
diff changeset
622 jint
a61af66fc99e Initial load
duke
parents:
diff changeset
623 JvmtiEnvBase::count_locked_objects(JavaThread *java_thread, Handle hobj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
624 jint ret = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
625 if (!java_thread->has_last_Java_frame()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
626 return ret; // no Java frames so no monitors
a61af66fc99e Initial load
duke
parents:
diff changeset
627 }
a61af66fc99e Initial load
duke
parents:
diff changeset
628
a61af66fc99e Initial load
duke
parents:
diff changeset
629 ResourceMark rm;
a61af66fc99e Initial load
duke
parents:
diff changeset
630 HandleMark hm;
a61af66fc99e Initial load
duke
parents:
diff changeset
631 RegisterMap reg_map(java_thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
632
a61af66fc99e Initial load
duke
parents:
diff changeset
633 for(javaVFrame *jvf=java_thread->last_java_vframe(&reg_map); jvf != NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
634 jvf = jvf->java_sender()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
635 GrowableArray<MonitorInfo*>* mons = jvf->monitors();
a61af66fc99e Initial load
duke
parents:
diff changeset
636 if (!mons->is_empty()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
637 for (int i = 0; i < mons->length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
638 MonitorInfo *mi = mons->at(i);
818
b109e761e927 6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents: 611
diff changeset
639 if (mi->owner_is_scalar_replaced()) continue;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
640
a61af66fc99e Initial load
duke
parents:
diff changeset
641 // see if owner of the monitor is our object
a61af66fc99e Initial load
duke
parents:
diff changeset
642 if (mi->owner() != NULL && mi->owner() == hobj()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
643 ret++;
a61af66fc99e Initial load
duke
parents:
diff changeset
644 }
a61af66fc99e Initial load
duke
parents:
diff changeset
645 }
a61af66fc99e Initial load
duke
parents:
diff changeset
646 }
a61af66fc99e Initial load
duke
parents:
diff changeset
647 }
a61af66fc99e Initial load
duke
parents:
diff changeset
648 return ret;
a61af66fc99e Initial load
duke
parents:
diff changeset
649 }
a61af66fc99e Initial load
duke
parents:
diff changeset
650
a61af66fc99e Initial load
duke
parents:
diff changeset
651
a61af66fc99e Initial load
duke
parents:
diff changeset
652
a61af66fc99e Initial load
duke
parents:
diff changeset
653 jvmtiError
a61af66fc99e Initial load
duke
parents:
diff changeset
654 JvmtiEnvBase::get_current_contended_monitor(JavaThread *calling_thread, JavaThread *java_thread, jobject *monitor_ptr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
655 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
656 uint32_t debug_bits = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
657 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
658 assert((SafepointSynchronize::is_at_safepoint() ||
a61af66fc99e Initial load
duke
parents:
diff changeset
659 is_thread_fully_suspended(java_thread, false, &debug_bits)),
a61af66fc99e Initial load
duke
parents:
diff changeset
660 "at safepoint or target thread is suspended");
a61af66fc99e Initial load
duke
parents:
diff changeset
661 oop obj = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
662 ObjectMonitor *mon = java_thread->current_waiting_monitor();
a61af66fc99e Initial load
duke
parents:
diff changeset
663 if (mon == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
664 // thread is not doing an Object.wait() call
a61af66fc99e Initial load
duke
parents:
diff changeset
665 mon = java_thread->current_pending_monitor();
a61af66fc99e Initial load
duke
parents:
diff changeset
666 if (mon != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
667 // The thread is trying to enter() or raw_enter() an ObjectMonitor.
a61af66fc99e Initial load
duke
parents:
diff changeset
668 obj = (oop)mon->object();
a61af66fc99e Initial load
duke
parents:
diff changeset
669 // If obj == NULL, then ObjectMonitor is raw which doesn't count
a61af66fc99e Initial load
duke
parents:
diff changeset
670 // as contended for this API
a61af66fc99e Initial load
duke
parents:
diff changeset
671 }
a61af66fc99e Initial load
duke
parents:
diff changeset
672 // implied else: no contended ObjectMonitor
a61af66fc99e Initial load
duke
parents:
diff changeset
673 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
674 // thread is doing an Object.wait() call
a61af66fc99e Initial load
duke
parents:
diff changeset
675 obj = (oop)mon->object();
a61af66fc99e Initial load
duke
parents:
diff changeset
676 assert(obj != NULL, "Object.wait() should have an object");
a61af66fc99e Initial load
duke
parents:
diff changeset
677 }
a61af66fc99e Initial load
duke
parents:
diff changeset
678
a61af66fc99e Initial load
duke
parents:
diff changeset
679 if (obj == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
680 *monitor_ptr = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
681 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
682 HandleMark hm;
a61af66fc99e Initial load
duke
parents:
diff changeset
683 Handle hobj(obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
684 *monitor_ptr = jni_reference(calling_thread, hobj);
a61af66fc99e Initial load
duke
parents:
diff changeset
685 }
a61af66fc99e Initial load
duke
parents:
diff changeset
686 return JVMTI_ERROR_NONE;
a61af66fc99e Initial load
duke
parents:
diff changeset
687 }
a61af66fc99e Initial load
duke
parents:
diff changeset
688
a61af66fc99e Initial load
duke
parents:
diff changeset
689
a61af66fc99e Initial load
duke
parents:
diff changeset
690 jvmtiError
a61af66fc99e Initial load
duke
parents:
diff changeset
691 JvmtiEnvBase::get_owned_monitors(JavaThread *calling_thread, JavaThread* java_thread,
a61af66fc99e Initial load
duke
parents:
diff changeset
692 GrowableArray<jvmtiMonitorStackDepthInfo*> *owned_monitors_list) {
a61af66fc99e Initial load
duke
parents:
diff changeset
693 jvmtiError err = JVMTI_ERROR_NONE;
a61af66fc99e Initial load
duke
parents:
diff changeset
694 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
695 uint32_t debug_bits = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
696 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
697 assert((SafepointSynchronize::is_at_safepoint() ||
a61af66fc99e Initial load
duke
parents:
diff changeset
698 is_thread_fully_suspended(java_thread, false, &debug_bits)),
a61af66fc99e Initial load
duke
parents:
diff changeset
699 "at safepoint or target thread is suspended");
a61af66fc99e Initial load
duke
parents:
diff changeset
700
a61af66fc99e Initial load
duke
parents:
diff changeset
701 if (java_thread->has_last_Java_frame()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
702 ResourceMark rm;
a61af66fc99e Initial load
duke
parents:
diff changeset
703 HandleMark hm;
a61af66fc99e Initial load
duke
parents:
diff changeset
704 RegisterMap reg_map(java_thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
705
a61af66fc99e Initial load
duke
parents:
diff changeset
706 int depth = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
707 for (javaVFrame *jvf = java_thread->last_java_vframe(&reg_map); jvf != NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
708 jvf = jvf->java_sender()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
709 if (depth++ < MaxJavaStackTraceDepth) { // check for stack too deep
a61af66fc99e Initial load
duke
parents:
diff changeset
710 // add locked objects for this frame into list
a61af66fc99e Initial load
duke
parents:
diff changeset
711 err = get_locked_objects_in_frame(calling_thread, java_thread, jvf, owned_monitors_list, depth-1);
a61af66fc99e Initial load
duke
parents:
diff changeset
712 if (err != JVMTI_ERROR_NONE) {
a61af66fc99e Initial load
duke
parents:
diff changeset
713 return err;
a61af66fc99e Initial load
duke
parents:
diff changeset
714 }
a61af66fc99e Initial load
duke
parents:
diff changeset
715 }
a61af66fc99e Initial load
duke
parents:
diff changeset
716 }
a61af66fc99e Initial load
duke
parents:
diff changeset
717 }
a61af66fc99e Initial load
duke
parents:
diff changeset
718
a61af66fc99e Initial load
duke
parents:
diff changeset
719 // Get off stack monitors. (e.g. acquired via jni MonitorEnter).
a61af66fc99e Initial load
duke
parents:
diff changeset
720 JvmtiMonitorClosure jmc(java_thread, calling_thread, owned_monitors_list, this);
a61af66fc99e Initial load
duke
parents:
diff changeset
721 ObjectSynchronizer::monitors_iterate(&jmc);
a61af66fc99e Initial load
duke
parents:
diff changeset
722 err = jmc.error();
a61af66fc99e Initial load
duke
parents:
diff changeset
723
a61af66fc99e Initial load
duke
parents:
diff changeset
724 return err;
a61af66fc99e Initial load
duke
parents:
diff changeset
725 }
a61af66fc99e Initial load
duke
parents:
diff changeset
726
a61af66fc99e Initial load
duke
parents:
diff changeset
727 // Save JNI local handles for any objects that this frame owns.
a61af66fc99e Initial load
duke
parents:
diff changeset
728 jvmtiError
a61af66fc99e Initial load
duke
parents:
diff changeset
729 JvmtiEnvBase::get_locked_objects_in_frame(JavaThread* calling_thread, JavaThread* java_thread,
a61af66fc99e Initial load
duke
parents:
diff changeset
730 javaVFrame *jvf, GrowableArray<jvmtiMonitorStackDepthInfo*>* owned_monitors_list, int stack_depth) {
a61af66fc99e Initial load
duke
parents:
diff changeset
731 jvmtiError err = JVMTI_ERROR_NONE;
a61af66fc99e Initial load
duke
parents:
diff changeset
732 ResourceMark rm;
a61af66fc99e Initial load
duke
parents:
diff changeset
733
a61af66fc99e Initial load
duke
parents:
diff changeset
734 GrowableArray<MonitorInfo*>* mons = jvf->monitors();
a61af66fc99e Initial load
duke
parents:
diff changeset
735 if (mons->is_empty()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
736 return err; // this javaVFrame holds no monitors
a61af66fc99e Initial load
duke
parents:
diff changeset
737 }
a61af66fc99e Initial load
duke
parents:
diff changeset
738
a61af66fc99e Initial load
duke
parents:
diff changeset
739 HandleMark hm;
a61af66fc99e Initial load
duke
parents:
diff changeset
740 oop wait_obj = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
741 {
a61af66fc99e Initial load
duke
parents:
diff changeset
742 // save object of current wait() call (if any) for later comparison
a61af66fc99e Initial load
duke
parents:
diff changeset
743 ObjectMonitor *mon = java_thread->current_waiting_monitor();
a61af66fc99e Initial load
duke
parents:
diff changeset
744 if (mon != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
745 wait_obj = (oop)mon->object();
a61af66fc99e Initial load
duke
parents:
diff changeset
746 }
a61af66fc99e Initial load
duke
parents:
diff changeset
747 }
a61af66fc99e Initial load
duke
parents:
diff changeset
748 oop pending_obj = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
749 {
a61af66fc99e Initial load
duke
parents:
diff changeset
750 // save object of current enter() call (if any) for later comparison
a61af66fc99e Initial load
duke
parents:
diff changeset
751 ObjectMonitor *mon = java_thread->current_pending_monitor();
a61af66fc99e Initial load
duke
parents:
diff changeset
752 if (mon != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
753 pending_obj = (oop)mon->object();
a61af66fc99e Initial load
duke
parents:
diff changeset
754 }
a61af66fc99e Initial load
duke
parents:
diff changeset
755 }
a61af66fc99e Initial load
duke
parents:
diff changeset
756
a61af66fc99e Initial load
duke
parents:
diff changeset
757 for (int i = 0; i < mons->length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
758 MonitorInfo *mi = mons->at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
759
818
b109e761e927 6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents: 611
diff changeset
760 if (mi->owner_is_scalar_replaced()) continue;
b109e761e927 6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents: 611
diff changeset
761
0
a61af66fc99e Initial load
duke
parents:
diff changeset
762 oop obj = mi->owner();
a61af66fc99e Initial load
duke
parents:
diff changeset
763 if (obj == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
764 // this monitor doesn't have an owning object so skip it
a61af66fc99e Initial load
duke
parents:
diff changeset
765 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
766 }
a61af66fc99e Initial load
duke
parents:
diff changeset
767
a61af66fc99e Initial load
duke
parents:
diff changeset
768 if (wait_obj == obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
769 // the thread is waiting on this monitor so it isn't really owned
a61af66fc99e Initial load
duke
parents:
diff changeset
770 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
771 }
a61af66fc99e Initial load
duke
parents:
diff changeset
772
a61af66fc99e Initial load
duke
parents:
diff changeset
773 if (pending_obj == obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
774 // the thread is pending on this monitor so it isn't really owned
a61af66fc99e Initial load
duke
parents:
diff changeset
775 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
776 }
a61af66fc99e Initial load
duke
parents:
diff changeset
777
a61af66fc99e Initial load
duke
parents:
diff changeset
778 if (owned_monitors_list->length() > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
779 // Our list has at least one object on it so we have to check
a61af66fc99e Initial load
duke
parents:
diff changeset
780 // for recursive object locking
a61af66fc99e Initial load
duke
parents:
diff changeset
781 bool found = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
782 for (int j = 0; j < owned_monitors_list->length(); j++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
783 jobject jobj = ((jvmtiMonitorStackDepthInfo*)owned_monitors_list->at(j))->monitor;
a61af66fc99e Initial load
duke
parents:
diff changeset
784 oop check = JNIHandles::resolve(jobj);
a61af66fc99e Initial load
duke
parents:
diff changeset
785 if (check == obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
786 found = true; // we found the object
a61af66fc99e Initial load
duke
parents:
diff changeset
787 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
788 }
a61af66fc99e Initial load
duke
parents:
diff changeset
789 }
a61af66fc99e Initial load
duke
parents:
diff changeset
790
a61af66fc99e Initial load
duke
parents:
diff changeset
791 if (found) {
a61af66fc99e Initial load
duke
parents:
diff changeset
792 // already have this object so don't include it
a61af66fc99e Initial load
duke
parents:
diff changeset
793 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
794 }
a61af66fc99e Initial load
duke
parents:
diff changeset
795 }
a61af66fc99e Initial load
duke
parents:
diff changeset
796
a61af66fc99e Initial load
duke
parents:
diff changeset
797 // add the owning object to our list
a61af66fc99e Initial load
duke
parents:
diff changeset
798 jvmtiMonitorStackDepthInfo *jmsdi;
a61af66fc99e Initial load
duke
parents:
diff changeset
799 err = allocate(sizeof(jvmtiMonitorStackDepthInfo), (unsigned char **)&jmsdi);
a61af66fc99e Initial load
duke
parents:
diff changeset
800 if (err != JVMTI_ERROR_NONE) {
a61af66fc99e Initial load
duke
parents:
diff changeset
801 return err;
a61af66fc99e Initial load
duke
parents:
diff changeset
802 }
a61af66fc99e Initial load
duke
parents:
diff changeset
803 Handle hobj(obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
804 jmsdi->monitor = jni_reference(calling_thread, hobj);
a61af66fc99e Initial load
duke
parents:
diff changeset
805 jmsdi->stack_depth = stack_depth;
a61af66fc99e Initial load
duke
parents:
diff changeset
806 owned_monitors_list->append(jmsdi);
a61af66fc99e Initial load
duke
parents:
diff changeset
807 }
a61af66fc99e Initial load
duke
parents:
diff changeset
808
a61af66fc99e Initial load
duke
parents:
diff changeset
809 return err;
a61af66fc99e Initial load
duke
parents:
diff changeset
810 }
a61af66fc99e Initial load
duke
parents:
diff changeset
811
a61af66fc99e Initial load
duke
parents:
diff changeset
812 jvmtiError
a61af66fc99e Initial load
duke
parents:
diff changeset
813 JvmtiEnvBase::get_stack_trace(JavaThread *java_thread,
a61af66fc99e Initial load
duke
parents:
diff changeset
814 jint start_depth, jint max_count,
a61af66fc99e Initial load
duke
parents:
diff changeset
815 jvmtiFrameInfo* frame_buffer, jint* count_ptr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
816 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
817 uint32_t debug_bits = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
818 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
819 assert((SafepointSynchronize::is_at_safepoint() ||
a61af66fc99e Initial load
duke
parents:
diff changeset
820 is_thread_fully_suspended(java_thread, false, &debug_bits)),
a61af66fc99e Initial load
duke
parents:
diff changeset
821 "at safepoint or target thread is suspended");
a61af66fc99e Initial load
duke
parents:
diff changeset
822 int count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
823 if (java_thread->has_last_Java_frame()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
824 RegisterMap reg_map(java_thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
825 Thread* current_thread = Thread::current();
a61af66fc99e Initial load
duke
parents:
diff changeset
826 ResourceMark rm(current_thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
827 javaVFrame *jvf = java_thread->last_java_vframe(&reg_map);
a61af66fc99e Initial load
duke
parents:
diff changeset
828 HandleMark hm(current_thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
829 if (start_depth != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
830 if (start_depth > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
831 for (int j = 0; j < start_depth && jvf != NULL; j++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
832 jvf = jvf->java_sender();
a61af66fc99e Initial load
duke
parents:
diff changeset
833 }
a61af66fc99e Initial load
duke
parents:
diff changeset
834 if (jvf == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
835 // start_depth is deeper than the stack depth
a61af66fc99e Initial load
duke
parents:
diff changeset
836 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
a61af66fc99e Initial load
duke
parents:
diff changeset
837 }
a61af66fc99e Initial load
duke
parents:
diff changeset
838 } else { // start_depth < 0
a61af66fc99e Initial load
duke
parents:
diff changeset
839 // we are referencing the starting depth based on the oldest
a61af66fc99e Initial load
duke
parents:
diff changeset
840 // part of the stack.
a61af66fc99e Initial load
duke
parents:
diff changeset
841 // optimize to limit the number of times that java_sender() is called
a61af66fc99e Initial load
duke
parents:
diff changeset
842 javaVFrame *jvf_cursor = jvf;
a61af66fc99e Initial load
duke
parents:
diff changeset
843 javaVFrame *jvf_prev = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
844 javaVFrame *jvf_prev_prev;
a61af66fc99e Initial load
duke
parents:
diff changeset
845 int j = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
846 while (jvf_cursor != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
847 jvf_prev_prev = jvf_prev;
a61af66fc99e Initial load
duke
parents:
diff changeset
848 jvf_prev = jvf_cursor;
a61af66fc99e Initial load
duke
parents:
diff changeset
849 for (j = 0; j > start_depth && jvf_cursor != NULL; j--) {
a61af66fc99e Initial load
duke
parents:
diff changeset
850 jvf_cursor = jvf_cursor->java_sender();
a61af66fc99e Initial load
duke
parents:
diff changeset
851 }
a61af66fc99e Initial load
duke
parents:
diff changeset
852 }
a61af66fc99e Initial load
duke
parents:
diff changeset
853 if (j == start_depth) {
a61af66fc99e Initial load
duke
parents:
diff changeset
854 // previous pointer is exactly where we want to start
a61af66fc99e Initial load
duke
parents:
diff changeset
855 jvf = jvf_prev;
a61af66fc99e Initial load
duke
parents:
diff changeset
856 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
857 // we need to back up further to get to the right place
a61af66fc99e Initial load
duke
parents:
diff changeset
858 if (jvf_prev_prev == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
859 // the -start_depth is greater than the stack depth
a61af66fc99e Initial load
duke
parents:
diff changeset
860 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
a61af66fc99e Initial load
duke
parents:
diff changeset
861 }
a61af66fc99e Initial load
duke
parents:
diff changeset
862 // j now is the number of frames on the stack starting with
a61af66fc99e Initial load
duke
parents:
diff changeset
863 // jvf_prev, we start from jvf_prev_prev and move older on
a61af66fc99e Initial load
duke
parents:
diff changeset
864 // the stack that many, the result is -start_depth frames
a61af66fc99e Initial load
duke
parents:
diff changeset
865 // remaining.
a61af66fc99e Initial load
duke
parents:
diff changeset
866 jvf = jvf_prev_prev;
a61af66fc99e Initial load
duke
parents:
diff changeset
867 for (; j < 0; j++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
868 jvf = jvf->java_sender();
a61af66fc99e Initial load
duke
parents:
diff changeset
869 }
a61af66fc99e Initial load
duke
parents:
diff changeset
870 }
a61af66fc99e Initial load
duke
parents:
diff changeset
871 }
a61af66fc99e Initial load
duke
parents:
diff changeset
872 }
a61af66fc99e Initial load
duke
parents:
diff changeset
873 for (; count < max_count && jvf != NULL; count++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
874 frame_buffer[count].method = jvf->method()->jmethod_id();
a61af66fc99e Initial load
duke
parents:
diff changeset
875 frame_buffer[count].location = (jvf->method()->is_native() ? -1 : jvf->bci());
a61af66fc99e Initial load
duke
parents:
diff changeset
876 jvf = jvf->java_sender();
a61af66fc99e Initial load
duke
parents:
diff changeset
877 }
a61af66fc99e Initial load
duke
parents:
diff changeset
878 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
879 if (start_depth != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
880 // no frames and there is a starting depth
a61af66fc99e Initial load
duke
parents:
diff changeset
881 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
a61af66fc99e Initial load
duke
parents:
diff changeset
882 }
a61af66fc99e Initial load
duke
parents:
diff changeset
883 }
a61af66fc99e Initial load
duke
parents:
diff changeset
884 *count_ptr = count;
a61af66fc99e Initial load
duke
parents:
diff changeset
885 return JVMTI_ERROR_NONE;
a61af66fc99e Initial load
duke
parents:
diff changeset
886 }
a61af66fc99e Initial load
duke
parents:
diff changeset
887
a61af66fc99e Initial load
duke
parents:
diff changeset
888 jvmtiError
a61af66fc99e Initial load
duke
parents:
diff changeset
889 JvmtiEnvBase::get_frame_count(JvmtiThreadState *state, jint *count_ptr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
890 assert((state != NULL),
a61af66fc99e Initial load
duke
parents:
diff changeset
891 "JavaThread should create JvmtiThreadState before calling this method");
a61af66fc99e Initial load
duke
parents:
diff changeset
892 *count_ptr = state->count_frames();
a61af66fc99e Initial load
duke
parents:
diff changeset
893 return JVMTI_ERROR_NONE;
a61af66fc99e Initial load
duke
parents:
diff changeset
894 }
a61af66fc99e Initial load
duke
parents:
diff changeset
895
a61af66fc99e Initial load
duke
parents:
diff changeset
896 jvmtiError
a61af66fc99e Initial load
duke
parents:
diff changeset
897 JvmtiEnvBase::get_frame_location(JavaThread *java_thread, jint depth,
a61af66fc99e Initial load
duke
parents:
diff changeset
898 jmethodID* method_ptr, jlocation* location_ptr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
899 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
900 uint32_t debug_bits = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
901 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
902 assert((SafepointSynchronize::is_at_safepoint() ||
a61af66fc99e Initial load
duke
parents:
diff changeset
903 is_thread_fully_suspended(java_thread, false, &debug_bits)),
a61af66fc99e Initial load
duke
parents:
diff changeset
904 "at safepoint or target thread is suspended");
a61af66fc99e Initial load
duke
parents:
diff changeset
905 Thread* current_thread = Thread::current();
a61af66fc99e Initial load
duke
parents:
diff changeset
906 ResourceMark rm(current_thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
907
a61af66fc99e Initial load
duke
parents:
diff changeset
908 vframe *vf = vframeFor(java_thread, depth);
a61af66fc99e Initial load
duke
parents:
diff changeset
909 if (vf == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
910 return JVMTI_ERROR_NO_MORE_FRAMES;
a61af66fc99e Initial load
duke
parents:
diff changeset
911 }
a61af66fc99e Initial load
duke
parents:
diff changeset
912
a61af66fc99e Initial load
duke
parents:
diff changeset
913 // vframeFor should return a java frame. If it doesn't
a61af66fc99e Initial load
duke
parents:
diff changeset
914 // it means we've got an internal error and we return the
a61af66fc99e Initial load
duke
parents:
diff changeset
915 // error in product mode. In debug mode we will instead
a61af66fc99e Initial load
duke
parents:
diff changeset
916 // attempt to cast the vframe to a javaVFrame and will
a61af66fc99e Initial load
duke
parents:
diff changeset
917 // cause an assertion/crash to allow further diagnosis.
a61af66fc99e Initial load
duke
parents:
diff changeset
918 #ifdef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
919 if (!vf->is_java_frame()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
920 return JVMTI_ERROR_INTERNAL;
a61af66fc99e Initial load
duke
parents:
diff changeset
921 }
a61af66fc99e Initial load
duke
parents:
diff changeset
922 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
923
a61af66fc99e Initial load
duke
parents:
diff changeset
924 HandleMark hm(current_thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
925 javaVFrame *jvf = javaVFrame::cast(vf);
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
926 Method* method = jvf->method();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
927 if (method->is_native()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
928 *location_ptr = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
929 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
930 *location_ptr = jvf->bci();
a61af66fc99e Initial load
duke
parents:
diff changeset
931 }
a61af66fc99e Initial load
duke
parents:
diff changeset
932 *method_ptr = method->jmethod_id();
a61af66fc99e Initial load
duke
parents:
diff changeset
933
a61af66fc99e Initial load
duke
parents:
diff changeset
934 return JVMTI_ERROR_NONE;
a61af66fc99e Initial load
duke
parents:
diff changeset
935 }
a61af66fc99e Initial load
duke
parents:
diff changeset
936
a61af66fc99e Initial load
duke
parents:
diff changeset
937
a61af66fc99e Initial load
duke
parents:
diff changeset
938 jvmtiError
a61af66fc99e Initial load
duke
parents:
diff changeset
939 JvmtiEnvBase::get_object_monitor_usage(JavaThread* calling_thread, jobject object, jvmtiMonitorUsage* info_ptr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
940 HandleMark hm;
a61af66fc99e Initial load
duke
parents:
diff changeset
941 Handle hobj;
a61af66fc99e Initial load
duke
parents:
diff changeset
942
a61af66fc99e Initial load
duke
parents:
diff changeset
943 bool at_safepoint = SafepointSynchronize::is_at_safepoint();
a61af66fc99e Initial load
duke
parents:
diff changeset
944
a61af66fc99e Initial load
duke
parents:
diff changeset
945 // Check arguments
a61af66fc99e Initial load
duke
parents:
diff changeset
946 {
a61af66fc99e Initial load
duke
parents:
diff changeset
947 oop mirror = JNIHandles::resolve_external_guard(object);
a61af66fc99e Initial load
duke
parents:
diff changeset
948 NULL_CHECK(mirror, JVMTI_ERROR_INVALID_OBJECT);
a61af66fc99e Initial load
duke
parents:
diff changeset
949 NULL_CHECK(info_ptr, JVMTI_ERROR_NULL_POINTER);
a61af66fc99e Initial load
duke
parents:
diff changeset
950
a61af66fc99e Initial load
duke
parents:
diff changeset
951 hobj = Handle(mirror);
a61af66fc99e Initial load
duke
parents:
diff changeset
952 }
a61af66fc99e Initial load
duke
parents:
diff changeset
953
a61af66fc99e Initial load
duke
parents:
diff changeset
954 JavaThread *owning_thread = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
955 ObjectMonitor *mon = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
956 jvmtiMonitorUsage ret = {
a61af66fc99e Initial load
duke
parents:
diff changeset
957 NULL, 0, 0, NULL, 0, NULL
a61af66fc99e Initial load
duke
parents:
diff changeset
958 };
a61af66fc99e Initial load
duke
parents:
diff changeset
959
a61af66fc99e Initial load
duke
parents:
diff changeset
960 uint32_t debug_bits = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
961 // first derive the object's owner and entry_count (if any)
a61af66fc99e Initial load
duke
parents:
diff changeset
962 {
a61af66fc99e Initial load
duke
parents:
diff changeset
963 // Revoke any biases before querying the mark word
a61af66fc99e Initial load
duke
parents:
diff changeset
964 if (SafepointSynchronize::is_at_safepoint()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
965 BiasedLocking::revoke_at_safepoint(hobj);
a61af66fc99e Initial load
duke
parents:
diff changeset
966 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
967 BiasedLocking::revoke_and_rebias(hobj, false, calling_thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
968 }
a61af66fc99e Initial load
duke
parents:
diff changeset
969
a61af66fc99e Initial load
duke
parents:
diff changeset
970 address owner = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
971 {
a61af66fc99e Initial load
duke
parents:
diff changeset
972 markOop mark = hobj()->mark();
a61af66fc99e Initial load
duke
parents:
diff changeset
973
a61af66fc99e Initial load
duke
parents:
diff changeset
974 if (!mark->has_monitor()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
975 // this object has a lightweight monitor
a61af66fc99e Initial load
duke
parents:
diff changeset
976
a61af66fc99e Initial load
duke
parents:
diff changeset
977 if (mark->has_locker()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
978 owner = (address)mark->locker(); // save the address of the Lock word
a61af66fc99e Initial load
duke
parents:
diff changeset
979 }
a61af66fc99e Initial load
duke
parents:
diff changeset
980 // implied else: no owner
a61af66fc99e Initial load
duke
parents:
diff changeset
981 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
982 // this object has a heavyweight monitor
a61af66fc99e Initial load
duke
parents:
diff changeset
983 mon = mark->monitor();
a61af66fc99e Initial load
duke
parents:
diff changeset
984
a61af66fc99e Initial load
duke
parents:
diff changeset
985 // The owner field of a heavyweight monitor may be NULL for no
a61af66fc99e Initial load
duke
parents:
diff changeset
986 // owner, a JavaThread * or it may still be the address of the
a61af66fc99e Initial load
duke
parents:
diff changeset
987 // Lock word in a JavaThread's stack. A monitor can be inflated
a61af66fc99e Initial load
duke
parents:
diff changeset
988 // by a non-owning JavaThread, but only the owning JavaThread
a61af66fc99e Initial load
duke
parents:
diff changeset
989 // can change the owner field from the Lock word to the
a61af66fc99e Initial load
duke
parents:
diff changeset
990 // JavaThread * and it may not have done that yet.
a61af66fc99e Initial load
duke
parents:
diff changeset
991 owner = (address)mon->owner();
a61af66fc99e Initial load
duke
parents:
diff changeset
992 }
a61af66fc99e Initial load
duke
parents:
diff changeset
993 }
a61af66fc99e Initial load
duke
parents:
diff changeset
994
a61af66fc99e Initial load
duke
parents:
diff changeset
995 if (owner != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
996 // This monitor is owned so we have to find the owning JavaThread.
a61af66fc99e Initial load
duke
parents:
diff changeset
997 // Since owning_thread_from_monitor_owner() grabs a lock, GC can
a61af66fc99e Initial load
duke
parents:
diff changeset
998 // move our object at this point. However, our owner value is safe
a61af66fc99e Initial load
duke
parents:
diff changeset
999 // since it is either the Lock word on a stack or a JavaThread *.
a61af66fc99e Initial load
duke
parents:
diff changeset
1000 owning_thread = Threads::owning_thread_from_monitor_owner(owner, !at_safepoint);
8673
5ee250974db9 8007476: assert(the_owner != NULL) failed: Did not find owning Java thread for lock word address
dcubed
parents: 7951
diff changeset
1001 // Cannot assume (owning_thread != NULL) here because this function
5ee250974db9 8007476: assert(the_owner != NULL) failed: Did not find owning Java thread for lock word address
dcubed
parents: 7951
diff changeset
1002 // may not have been called at a safepoint and the owning_thread
5ee250974db9 8007476: assert(the_owner != NULL) failed: Did not find owning Java thread for lock word address
dcubed
parents: 7951
diff changeset
1003 // might not be suspended.
5ee250974db9 8007476: assert(the_owner != NULL) failed: Did not find owning Java thread for lock word address
dcubed
parents: 7951
diff changeset
1004 if (owning_thread != NULL) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1005 // The monitor's owner either has to be the current thread, at safepoint
a61af66fc99e Initial load
duke
parents:
diff changeset
1006 // or it has to be suspended. Any of these conditions will prevent both
a61af66fc99e Initial load
duke
parents:
diff changeset
1007 // contending and waiting threads from modifying the state of
a61af66fc99e Initial load
duke
parents:
diff changeset
1008 // the monitor.
a61af66fc99e Initial load
duke
parents:
diff changeset
1009 if (!at_safepoint && !JvmtiEnv::is_thread_fully_suspended(owning_thread, true, &debug_bits)) {
8673
5ee250974db9 8007476: assert(the_owner != NULL) failed: Did not find owning Java thread for lock word address
dcubed
parents: 7951
diff changeset
1010 // Don't worry! This return of JVMTI_ERROR_THREAD_NOT_SUSPENDED
5ee250974db9 8007476: assert(the_owner != NULL) failed: Did not find owning Java thread for lock word address
dcubed
parents: 7951
diff changeset
1011 // will not make it back to the JVM/TI agent. The error code will
5ee250974db9 8007476: assert(the_owner != NULL) failed: Did not find owning Java thread for lock word address
dcubed
parents: 7951
diff changeset
1012 // get intercepted in JvmtiEnv::GetObjectMonitorUsage() which
5ee250974db9 8007476: assert(the_owner != NULL) failed: Did not find owning Java thread for lock word address
dcubed
parents: 7951
diff changeset
1013 // will retry the call via a VM_GetObjectMonitorUsage VM op.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1014 return JVMTI_ERROR_THREAD_NOT_SUSPENDED;
a61af66fc99e Initial load
duke
parents:
diff changeset
1015 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1016 HandleMark hm;
a61af66fc99e Initial load
duke
parents:
diff changeset
1017 Handle th(owning_thread->threadObj());
a61af66fc99e Initial load
duke
parents:
diff changeset
1018 ret.owner = (jthread)jni_reference(calling_thread, th);
a61af66fc99e Initial load
duke
parents:
diff changeset
1019 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1020 // implied else: no owner
a61af66fc99e Initial load
duke
parents:
diff changeset
1021 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1022
a61af66fc99e Initial load
duke
parents:
diff changeset
1023 if (owning_thread != NULL) { // monitor is owned
a61af66fc99e Initial load
duke
parents:
diff changeset
1024 if ((address)owning_thread == owner) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1025 // the owner field is the JavaThread *
a61af66fc99e Initial load
duke
parents:
diff changeset
1026 assert(mon != NULL,
a61af66fc99e Initial load
duke
parents:
diff changeset
1027 "must have heavyweight monitor with JavaThread * owner");
a61af66fc99e Initial load
duke
parents:
diff changeset
1028 ret.entry_count = mon->recursions() + 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
1029 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1030 // The owner field is the Lock word on the JavaThread's stack
a61af66fc99e Initial load
duke
parents:
diff changeset
1031 // so the recursions field is not valid. We have to count the
a61af66fc99e Initial load
duke
parents:
diff changeset
1032 // number of recursive monitor entries the hard way. We pass
a61af66fc99e Initial load
duke
parents:
diff changeset
1033 // a handle to survive any GCs along the way.
a61af66fc99e Initial load
duke
parents:
diff changeset
1034 ResourceMark rm;
a61af66fc99e Initial load
duke
parents:
diff changeset
1035 ret.entry_count = count_locked_objects(owning_thread, hobj);
a61af66fc99e Initial load
duke
parents:
diff changeset
1036 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1037 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1038 // implied else: entry_count == 0
a61af66fc99e Initial load
duke
parents:
diff changeset
1039 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1040
a61af66fc99e Initial load
duke
parents:
diff changeset
1041 int nWant,nWait;
a61af66fc99e Initial load
duke
parents:
diff changeset
1042 if (mon != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1043 // this object has a heavyweight monitor
a61af66fc99e Initial load
duke
parents:
diff changeset
1044 nWant = mon->contentions(); // # of threads contending for monitor
a61af66fc99e Initial load
duke
parents:
diff changeset
1045 nWait = mon->waiters(); // # of threads in Object.wait()
a61af66fc99e Initial load
duke
parents:
diff changeset
1046 ret.waiter_count = nWant + nWait;
a61af66fc99e Initial load
duke
parents:
diff changeset
1047 ret.notify_waiter_count = nWait;
a61af66fc99e Initial load
duke
parents:
diff changeset
1048 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1049 // this object has a lightweight monitor
a61af66fc99e Initial load
duke
parents:
diff changeset
1050 ret.waiter_count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1051 ret.notify_waiter_count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1052 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1053
a61af66fc99e Initial load
duke
parents:
diff changeset
1054 // Allocate memory for heavyweight and lightweight monitor.
a61af66fc99e Initial load
duke
parents:
diff changeset
1055 jvmtiError err;
a61af66fc99e Initial load
duke
parents:
diff changeset
1056 err = allocate(ret.waiter_count * sizeof(jthread *), (unsigned char**)&ret.waiters);
a61af66fc99e Initial load
duke
parents:
diff changeset
1057 if (err != JVMTI_ERROR_NONE) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1058 return err;
a61af66fc99e Initial load
duke
parents:
diff changeset
1059 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1060 err = allocate(ret.notify_waiter_count * sizeof(jthread *),
a61af66fc99e Initial load
duke
parents:
diff changeset
1061 (unsigned char**)&ret.notify_waiters);
a61af66fc99e Initial load
duke
parents:
diff changeset
1062 if (err != JVMTI_ERROR_NONE) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1063 deallocate((unsigned char*)ret.waiters);
a61af66fc99e Initial load
duke
parents:
diff changeset
1064 return err;
a61af66fc99e Initial load
duke
parents:
diff changeset
1065 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1066
a61af66fc99e Initial load
duke
parents:
diff changeset
1067 // now derive the rest of the fields
a61af66fc99e Initial load
duke
parents:
diff changeset
1068 if (mon != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1069 // this object has a heavyweight monitor
a61af66fc99e Initial load
duke
parents:
diff changeset
1070
a61af66fc99e Initial load
duke
parents:
diff changeset
1071 // Number of waiters may actually be less than the waiter count.
a61af66fc99e Initial load
duke
parents:
diff changeset
1072 // So NULL out memory so that unused memory will be NULL.
a61af66fc99e Initial load
duke
parents:
diff changeset
1073 memset(ret.waiters, 0, ret.waiter_count * sizeof(jthread *));
a61af66fc99e Initial load
duke
parents:
diff changeset
1074 memset(ret.notify_waiters, 0, ret.notify_waiter_count * sizeof(jthread *));
a61af66fc99e Initial load
duke
parents:
diff changeset
1075
a61af66fc99e Initial load
duke
parents:
diff changeset
1076 if (ret.waiter_count > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1077 // we have contending and/or waiting threads
a61af66fc99e Initial load
duke
parents:
diff changeset
1078 HandleMark hm;
a61af66fc99e Initial load
duke
parents:
diff changeset
1079 if (nWant > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1080 // we have contending threads
a61af66fc99e Initial load
duke
parents:
diff changeset
1081 ResourceMark rm;
a61af66fc99e Initial load
duke
parents:
diff changeset
1082 // get_pending_threads returns only java thread so we do not need to
a61af66fc99e Initial load
duke
parents:
diff changeset
1083 // check for non java threads.
a61af66fc99e Initial load
duke
parents:
diff changeset
1084 GrowableArray<JavaThread*>* wantList = Threads::get_pending_threads(
a61af66fc99e Initial load
duke
parents:
diff changeset
1085 nWant, (address)mon, !at_safepoint);
a61af66fc99e Initial load
duke
parents:
diff changeset
1086 if (wantList->length() < nWant) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1087 // robustness: the pending list has gotten smaller
a61af66fc99e Initial load
duke
parents:
diff changeset
1088 nWant = wantList->length();
a61af66fc99e Initial load
duke
parents:
diff changeset
1089 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1090 for (int i = 0; i < nWant; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1091 JavaThread *pending_thread = wantList->at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
1092 // If the monitor has no owner, then a non-suspended contending
a61af66fc99e Initial load
duke
parents:
diff changeset
1093 // thread could potentially change the state of the monitor by
a61af66fc99e Initial load
duke
parents:
diff changeset
1094 // entering it. The JVM/TI spec doesn't allow this.
a61af66fc99e Initial load
duke
parents:
diff changeset
1095 if (owning_thread == NULL && !at_safepoint &
a61af66fc99e Initial load
duke
parents:
diff changeset
1096 !JvmtiEnv::is_thread_fully_suspended(pending_thread, true, &debug_bits)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1097 if (ret.owner != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1098 destroy_jni_reference(calling_thread, ret.owner);
a61af66fc99e Initial load
duke
parents:
diff changeset
1099 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1100 for (int j = 0; j < i; j++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1101 destroy_jni_reference(calling_thread, ret.waiters[j]);
a61af66fc99e Initial load
duke
parents:
diff changeset
1102 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1103 deallocate((unsigned char*)ret.waiters);
a61af66fc99e Initial load
duke
parents:
diff changeset
1104 deallocate((unsigned char*)ret.notify_waiters);
a61af66fc99e Initial load
duke
parents:
diff changeset
1105 return JVMTI_ERROR_THREAD_NOT_SUSPENDED;
a61af66fc99e Initial load
duke
parents:
diff changeset
1106 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1107 Handle th(pending_thread->threadObj());
a61af66fc99e Initial load
duke
parents:
diff changeset
1108 ret.waiters[i] = (jthread)jni_reference(calling_thread, th);
a61af66fc99e Initial load
duke
parents:
diff changeset
1109 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1110 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1111 if (nWait > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1112 // we have threads in Object.wait()
a61af66fc99e Initial load
duke
parents:
diff changeset
1113 int offset = nWant; // add after any contending threads
a61af66fc99e Initial load
duke
parents:
diff changeset
1114 ObjectWaiter *waiter = mon->first_waiter();
a61af66fc99e Initial load
duke
parents:
diff changeset
1115 for (int i = 0, j = 0; i < nWait; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1116 if (waiter == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1117 // robustness: the waiting list has gotten smaller
a61af66fc99e Initial load
duke
parents:
diff changeset
1118 nWait = j;
a61af66fc99e Initial load
duke
parents:
diff changeset
1119 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1120 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1121 Thread *t = mon->thread_of_waiter(waiter);
a61af66fc99e Initial load
duke
parents:
diff changeset
1122 if (t != NULL && t->is_Java_thread()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1123 JavaThread *wjava_thread = (JavaThread *)t;
a61af66fc99e Initial load
duke
parents:
diff changeset
1124 // If the thread was found on the ObjectWaiter list, then
a61af66fc99e Initial load
duke
parents:
diff changeset
1125 // it has not been notified. This thread can't change the
a61af66fc99e Initial load
duke
parents:
diff changeset
1126 // state of the monitor so it doesn't need to be suspended.
a61af66fc99e Initial load
duke
parents:
diff changeset
1127 Handle th(wjava_thread->threadObj());
a61af66fc99e Initial load
duke
parents:
diff changeset
1128 ret.waiters[offset + j] = (jthread)jni_reference(calling_thread, th);
a61af66fc99e Initial load
duke
parents:
diff changeset
1129 ret.notify_waiters[j++] = (jthread)jni_reference(calling_thread, th);
a61af66fc99e Initial load
duke
parents:
diff changeset
1130 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1131 waiter = mon->next_waiter(waiter);
a61af66fc99e Initial load
duke
parents:
diff changeset
1132 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1133 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1134 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1135
a61af66fc99e Initial load
duke
parents:
diff changeset
1136 // Adjust count. nWant and nWait count values may be less than original.
a61af66fc99e Initial load
duke
parents:
diff changeset
1137 ret.waiter_count = nWant + nWait;
a61af66fc99e Initial load
duke
parents:
diff changeset
1138 ret.notify_waiter_count = nWait;
a61af66fc99e Initial load
duke
parents:
diff changeset
1139 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1140 // this object has a lightweight monitor and we have nothing more
a61af66fc99e Initial load
duke
parents:
diff changeset
1141 // to do here because the defaults are just fine.
a61af66fc99e Initial load
duke
parents:
diff changeset
1142 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1143
a61af66fc99e Initial load
duke
parents:
diff changeset
1144 // we don't update return parameter unless everything worked
a61af66fc99e Initial load
duke
parents:
diff changeset
1145 *info_ptr = ret;
a61af66fc99e Initial load
duke
parents:
diff changeset
1146
a61af66fc99e Initial load
duke
parents:
diff changeset
1147 return JVMTI_ERROR_NONE;
a61af66fc99e Initial load
duke
parents:
diff changeset
1148 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1149
a61af66fc99e Initial load
duke
parents:
diff changeset
1150 ResourceTracker::ResourceTracker(JvmtiEnv* env) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1151 _env = env;
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 3938
diff changeset
1152 _allocations = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<unsigned char*>(20, true);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1153 _failed = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1154 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1155 ResourceTracker::~ResourceTracker() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1156 if (_failed) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1157 for (int i=0; i<_allocations->length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1158 _env->deallocate(_allocations->at(i));
a61af66fc99e Initial load
duke
parents:
diff changeset
1159 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1160 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1161 delete _allocations;
a61af66fc99e Initial load
duke
parents:
diff changeset
1162 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1163
a61af66fc99e Initial load
duke
parents:
diff changeset
1164 jvmtiError ResourceTracker::allocate(jlong size, unsigned char** mem_ptr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1165 unsigned char *ptr;
a61af66fc99e Initial load
duke
parents:
diff changeset
1166 jvmtiError err = _env->allocate(size, &ptr);
a61af66fc99e Initial load
duke
parents:
diff changeset
1167 if (err == JVMTI_ERROR_NONE) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1168 _allocations->append(ptr);
a61af66fc99e Initial load
duke
parents:
diff changeset
1169 *mem_ptr = ptr;
a61af66fc99e Initial load
duke
parents:
diff changeset
1170 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1171 *mem_ptr = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1172 _failed = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
1173 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1174 return err;
a61af66fc99e Initial load
duke
parents:
diff changeset
1175 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1176
a61af66fc99e Initial load
duke
parents:
diff changeset
1177 unsigned char* ResourceTracker::allocate(jlong size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1178 unsigned char* ptr;
a61af66fc99e Initial load
duke
parents:
diff changeset
1179 allocate(size, &ptr);
a61af66fc99e Initial load
duke
parents:
diff changeset
1180 return ptr;
a61af66fc99e Initial load
duke
parents:
diff changeset
1181 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1182
a61af66fc99e Initial load
duke
parents:
diff changeset
1183 char* ResourceTracker::strdup(const char* str) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1184 char *dup_str = (char*)allocate(strlen(str)+1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1185 if (dup_str != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1186 strcpy(dup_str, str);
a61af66fc99e Initial load
duke
parents:
diff changeset
1187 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1188 return dup_str;
a61af66fc99e Initial load
duke
parents:
diff changeset
1189 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1190
a61af66fc99e Initial load
duke
parents:
diff changeset
1191 struct StackInfoNode {
a61af66fc99e Initial load
duke
parents:
diff changeset
1192 struct StackInfoNode *next;
a61af66fc99e Initial load
duke
parents:
diff changeset
1193 jvmtiStackInfo info;
a61af66fc99e Initial load
duke
parents:
diff changeset
1194 };
a61af66fc99e Initial load
duke
parents:
diff changeset
1195
a61af66fc99e Initial load
duke
parents:
diff changeset
1196 // Create a jvmtiStackInfo inside a linked list node and create a
a61af66fc99e Initial load
duke
parents:
diff changeset
1197 // buffer for the frame information, both allocated as resource objects.
a61af66fc99e Initial load
duke
parents:
diff changeset
1198 // Fill in both the jvmtiStackInfo and the jvmtiFrameInfo.
a61af66fc99e Initial load
duke
parents:
diff changeset
1199 // Note that either or both of thr and thread_oop
a61af66fc99e Initial load
duke
parents:
diff changeset
1200 // may be null if the thread is new or has exited.
a61af66fc99e Initial load
duke
parents:
diff changeset
1201 void
a61af66fc99e Initial load
duke
parents:
diff changeset
1202 VM_GetMultipleStackTraces::fill_frames(jthread jt, JavaThread *thr, oop thread_oop) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1203 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
a61af66fc99e Initial load
duke
parents:
diff changeset
1204
a61af66fc99e Initial load
duke
parents:
diff changeset
1205 jint state = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1206 struct StackInfoNode *node = NEW_RESOURCE_OBJ(struct StackInfoNode);
a61af66fc99e Initial load
duke
parents:
diff changeset
1207 jvmtiStackInfo *infop = &(node->info);
a61af66fc99e Initial load
duke
parents:
diff changeset
1208 node->next = head();
a61af66fc99e Initial load
duke
parents:
diff changeset
1209 set_head(node);
a61af66fc99e Initial load
duke
parents:
diff changeset
1210 infop->frame_count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1211 infop->thread = jt;
a61af66fc99e Initial load
duke
parents:
diff changeset
1212
a61af66fc99e Initial load
duke
parents:
diff changeset
1213 if (thread_oop != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1214 // get most state bits
a61af66fc99e Initial load
duke
parents:
diff changeset
1215 state = (jint)java_lang_Thread::get_thread_status(thread_oop);
a61af66fc99e Initial load
duke
parents:
diff changeset
1216 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1217
a61af66fc99e Initial load
duke
parents:
diff changeset
1218 if (thr != NULL) { // add more state bits if there is a JavaThead to query
a61af66fc99e Initial load
duke
parents:
diff changeset
1219 // same as is_being_ext_suspended() but without locking
a61af66fc99e Initial load
duke
parents:
diff changeset
1220 if (thr->is_ext_suspended() || thr->is_external_suspend()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1221 state |= JVMTI_THREAD_STATE_SUSPENDED;
a61af66fc99e Initial load
duke
parents:
diff changeset
1222 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1223 JavaThreadState jts = thr->thread_state();
a61af66fc99e Initial load
duke
parents:
diff changeset
1224 if (jts == _thread_in_native) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1225 state |= JVMTI_THREAD_STATE_IN_NATIVE;
a61af66fc99e Initial load
duke
parents:
diff changeset
1226 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1227 OSThread* osThread = thr->osthread();
a61af66fc99e Initial load
duke
parents:
diff changeset
1228 if (osThread != NULL && osThread->interrupted()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1229 state |= JVMTI_THREAD_STATE_INTERRUPTED;
a61af66fc99e Initial load
duke
parents:
diff changeset
1230 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1231 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1232 infop->state = state;
a61af66fc99e Initial load
duke
parents:
diff changeset
1233
a61af66fc99e Initial load
duke
parents:
diff changeset
1234 if (thr != NULL || (state & JVMTI_THREAD_STATE_ALIVE) != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1235 infop->frame_buffer = NEW_RESOURCE_ARRAY(jvmtiFrameInfo, max_frame_count());
a61af66fc99e Initial load
duke
parents:
diff changeset
1236 env()->get_stack_trace(thr, 0, max_frame_count(),
a61af66fc99e Initial load
duke
parents:
diff changeset
1237 infop->frame_buffer, &(infop->frame_count));
a61af66fc99e Initial load
duke
parents:
diff changeset
1238 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1239 infop->frame_buffer = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1240 infop->frame_count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1241 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1242 _frame_count_total += infop->frame_count;
a61af66fc99e Initial load
duke
parents:
diff changeset
1243 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1244
a61af66fc99e Initial load
duke
parents:
diff changeset
1245 // Based on the stack information in the linked list, allocate memory
a61af66fc99e Initial load
duke
parents:
diff changeset
1246 // block to return and fill it from the info in the linked list.
a61af66fc99e Initial load
duke
parents:
diff changeset
1247 void
a61af66fc99e Initial load
duke
parents:
diff changeset
1248 VM_GetMultipleStackTraces::allocate_and_fill_stacks(jint thread_count) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1249 // do I need to worry about alignment issues?
a61af66fc99e Initial load
duke
parents:
diff changeset
1250 jlong alloc_size = thread_count * sizeof(jvmtiStackInfo)
a61af66fc99e Initial load
duke
parents:
diff changeset
1251 + _frame_count_total * sizeof(jvmtiFrameInfo);
a61af66fc99e Initial load
duke
parents:
diff changeset
1252 env()->allocate(alloc_size, (unsigned char **)&_stack_info);
a61af66fc99e Initial load
duke
parents:
diff changeset
1253
a61af66fc99e Initial load
duke
parents:
diff changeset
1254 // pointers to move through the newly allocated space as it is filled in
a61af66fc99e Initial load
duke
parents:
diff changeset
1255 jvmtiStackInfo *si = _stack_info + thread_count; // bottom of stack info
a61af66fc99e Initial load
duke
parents:
diff changeset
1256 jvmtiFrameInfo *fi = (jvmtiFrameInfo *)si; // is the top of frame info
a61af66fc99e Initial load
duke
parents:
diff changeset
1257
a61af66fc99e Initial load
duke
parents:
diff changeset
1258 // copy information in resource area into allocated buffer
a61af66fc99e Initial load
duke
parents:
diff changeset
1259 // insert stack info backwards since linked list is backwards
a61af66fc99e Initial load
duke
parents:
diff changeset
1260 // insert frame info forwards
a61af66fc99e Initial load
duke
parents:
diff changeset
1261 // walk the StackInfoNodes
a61af66fc99e Initial load
duke
parents:
diff changeset
1262 for (struct StackInfoNode *sin = head(); sin != NULL; sin = sin->next) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1263 jint frame_count = sin->info.frame_count;
a61af66fc99e Initial load
duke
parents:
diff changeset
1264 size_t frames_size = frame_count * sizeof(jvmtiFrameInfo);
a61af66fc99e Initial load
duke
parents:
diff changeset
1265 --si;
a61af66fc99e Initial load
duke
parents:
diff changeset
1266 memcpy(si, &(sin->info), sizeof(jvmtiStackInfo));
a61af66fc99e Initial load
duke
parents:
diff changeset
1267 if (frames_size == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1268 si->frame_buffer = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1269 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1270 memcpy(fi, sin->info.frame_buffer, frames_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
1271 si->frame_buffer = fi; // point to the new allocated copy of the frames
a61af66fc99e Initial load
duke
parents:
diff changeset
1272 fi += frame_count;
a61af66fc99e Initial load
duke
parents:
diff changeset
1273 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1274 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1275 assert(si == _stack_info, "the last copied stack info must be the first record");
a61af66fc99e Initial load
duke
parents:
diff changeset
1276 assert((unsigned char *)fi == ((unsigned char *)_stack_info) + alloc_size,
a61af66fc99e Initial load
duke
parents:
diff changeset
1277 "the last copied frame info must be the last record");
a61af66fc99e Initial load
duke
parents:
diff changeset
1278 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1279
a61af66fc99e Initial load
duke
parents:
diff changeset
1280
a61af66fc99e Initial load
duke
parents:
diff changeset
1281 void
a61af66fc99e Initial load
duke
parents:
diff changeset
1282 VM_GetThreadListStackTraces::doit() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1283 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
a61af66fc99e Initial load
duke
parents:
diff changeset
1284
a61af66fc99e Initial load
duke
parents:
diff changeset
1285 ResourceMark rm;
a61af66fc99e Initial load
duke
parents:
diff changeset
1286 for (int i = 0; i < _thread_count; ++i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1287 jthread jt = _thread_list[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
1288 oop thread_oop = JNIHandles::resolve_external_guard(jt);
1142
4ce7240d622c 6914300: ciEnv should export all well known classes
never
parents: 844
diff changeset
1289 if (thread_oop == NULL || !thread_oop->is_a(SystemDictionary::Thread_klass())) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1290 set_result(JVMTI_ERROR_INVALID_THREAD);
a61af66fc99e Initial load
duke
parents:
diff changeset
1291 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1292 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1293 fill_frames(jt, java_lang_Thread::thread(thread_oop), thread_oop);
a61af66fc99e Initial load
duke
parents:
diff changeset
1294 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1295 allocate_and_fill_stacks(_thread_count);
a61af66fc99e Initial load
duke
parents:
diff changeset
1296 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1297
a61af66fc99e Initial load
duke
parents:
diff changeset
1298 void
a61af66fc99e Initial load
duke
parents:
diff changeset
1299 VM_GetAllStackTraces::doit() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1300 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
a61af66fc99e Initial load
duke
parents:
diff changeset
1301
a61af66fc99e Initial load
duke
parents:
diff changeset
1302 ResourceMark rm;
a61af66fc99e Initial load
duke
parents:
diff changeset
1303 _final_thread_count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1304 for (JavaThread *jt = Threads::first(); jt != NULL; jt = jt->next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1305 oop thread_oop = jt->threadObj();
a61af66fc99e Initial load
duke
parents:
diff changeset
1306 if (thread_oop != NULL &&
a61af66fc99e Initial load
duke
parents:
diff changeset
1307 !jt->is_exiting() &&
a61af66fc99e Initial load
duke
parents:
diff changeset
1308 java_lang_Thread::is_alive(thread_oop) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
1309 !jt->is_hidden_from_external_view()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1310 ++_final_thread_count;
a61af66fc99e Initial load
duke
parents:
diff changeset
1311 // Handle block of the calling thread is used to create local refs.
a61af66fc99e Initial load
duke
parents:
diff changeset
1312 fill_frames((jthread)JNIHandles::make_local(_calling_thread, thread_oop),
a61af66fc99e Initial load
duke
parents:
diff changeset
1313 jt, thread_oop);
a61af66fc99e Initial load
duke
parents:
diff changeset
1314 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1315 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1316 allocate_and_fill_stacks(_final_thread_count);
a61af66fc99e Initial load
duke
parents:
diff changeset
1317 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1318
a61af66fc99e Initial load
duke
parents:
diff changeset
1319 // Verifies that the top frame is a java frame in an expected state.
a61af66fc99e Initial load
duke
parents:
diff changeset
1320 // Deoptimizes frame if needed.
a61af66fc99e Initial load
duke
parents:
diff changeset
1321 // Checks that the frame method signature matches the return type (tos).
a61af66fc99e Initial load
duke
parents:
diff changeset
1322 // HandleMark must be defined in the caller only.
a61af66fc99e Initial load
duke
parents:
diff changeset
1323 // It is to keep a ret_ob_h handle alive after return to the caller.
a61af66fc99e Initial load
duke
parents:
diff changeset
1324 jvmtiError
a61af66fc99e Initial load
duke
parents:
diff changeset
1325 JvmtiEnvBase::check_top_frame(JavaThread* current_thread, JavaThread* java_thread,
a61af66fc99e Initial load
duke
parents:
diff changeset
1326 jvalue value, TosState tos, Handle* ret_ob_h) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1327 ResourceMark rm(current_thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
1328
a61af66fc99e Initial load
duke
parents:
diff changeset
1329 vframe *vf = vframeFor(java_thread, 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
1330 NULL_CHECK(vf, JVMTI_ERROR_NO_MORE_FRAMES);
a61af66fc99e Initial load
duke
parents:
diff changeset
1331
a61af66fc99e Initial load
duke
parents:
diff changeset
1332 javaVFrame *jvf = (javaVFrame*) vf;
a61af66fc99e Initial load
duke
parents:
diff changeset
1333 if (!vf->is_java_frame() || jvf->method()->is_native()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1334 return JVMTI_ERROR_OPAQUE_FRAME;
a61af66fc99e Initial load
duke
parents:
diff changeset
1335 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1336
a61af66fc99e Initial load
duke
parents:
diff changeset
1337 // If the frame is a compiled one, need to deoptimize it.
a61af66fc99e Initial load
duke
parents:
diff changeset
1338 if (vf->is_compiled_frame()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1339 if (!vf->fr().can_be_deoptimized()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1340 return JVMTI_ERROR_OPAQUE_FRAME;
a61af66fc99e Initial load
duke
parents:
diff changeset
1341 }
1905
ce6848d0666d 6968367: can_post_on_exceptions is still using VM_DeoptimizeFrame in some places
never
parents: 1552
diff changeset
1342 Deoptimization::deoptimize_frame(java_thread, jvf->fr().id());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1343 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1344
a61af66fc99e Initial load
duke
parents:
diff changeset
1345 // Get information about method return type
2177
3582bf76420e 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 1988
diff changeset
1346 Symbol* signature = jvf->method()->signature();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1347
a61af66fc99e Initial load
duke
parents:
diff changeset
1348 ResultTypeFinder rtf(signature);
a61af66fc99e Initial load
duke
parents:
diff changeset
1349 TosState fr_tos = as_TosState(rtf.type());
a61af66fc99e Initial load
duke
parents:
diff changeset
1350 if (fr_tos != tos) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1351 if (tos != itos || (fr_tos != btos && fr_tos != ctos && fr_tos != stos)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1352 return JVMTI_ERROR_TYPE_MISMATCH;
a61af66fc99e Initial load
duke
parents:
diff changeset
1353 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1354 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1355
a61af66fc99e Initial load
duke
parents:
diff changeset
1356 // Check that the jobject class matches the return type signature.
a61af66fc99e Initial load
duke
parents:
diff changeset
1357 jobject jobj = value.l;
a61af66fc99e Initial load
duke
parents:
diff changeset
1358 if (tos == atos && jobj != NULL) { // NULL reference is allowed
a61af66fc99e Initial load
duke
parents:
diff changeset
1359 Handle ob_h = Handle(current_thread, JNIHandles::resolve_external_guard(jobj));
a61af66fc99e Initial load
duke
parents:
diff changeset
1360 NULL_CHECK(ob_h, JVMTI_ERROR_INVALID_OBJECT);
a61af66fc99e Initial load
duke
parents:
diff changeset
1361 KlassHandle ob_kh = KlassHandle(current_thread, ob_h()->klass());
a61af66fc99e Initial load
duke
parents:
diff changeset
1362 NULL_CHECK(ob_kh, JVMTI_ERROR_INVALID_OBJECT);
a61af66fc99e Initial load
duke
parents:
diff changeset
1363
a61af66fc99e Initial load
duke
parents:
diff changeset
1364 // Method return type signature.
a61af66fc99e Initial load
duke
parents:
diff changeset
1365 char* ty_sign = 1 + strchr(signature->as_C_string(), ')');
a61af66fc99e Initial load
duke
parents:
diff changeset
1366
6983
070d523b96a7 8001471: Klass::cast() does nothing
hseigel
parents: 6725
diff changeset
1367 if (!VM_GetOrSetLocal::is_assignable(ty_sign, ob_kh(), current_thread)) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1368 return JVMTI_ERROR_TYPE_MISMATCH;
a61af66fc99e Initial load
duke
parents:
diff changeset
1369 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1370 *ret_ob_h = ob_h;
a61af66fc99e Initial load
duke
parents:
diff changeset
1371 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1372 return JVMTI_ERROR_NONE;
a61af66fc99e Initial load
duke
parents:
diff changeset
1373 } /* end check_top_frame */
a61af66fc99e Initial load
duke
parents:
diff changeset
1374
a61af66fc99e Initial load
duke
parents:
diff changeset
1375
a61af66fc99e Initial load
duke
parents:
diff changeset
1376 // ForceEarlyReturn<type> follows the PopFrame approach in many aspects.
a61af66fc99e Initial load
duke
parents:
diff changeset
1377 // Main difference is on the last stage in the interpreter.
a61af66fc99e Initial load
duke
parents:
diff changeset
1378 // The PopFrame stops method execution to continue execution
a61af66fc99e Initial load
duke
parents:
diff changeset
1379 // from the same method call instruction.
a61af66fc99e Initial load
duke
parents:
diff changeset
1380 // The ForceEarlyReturn forces return from method so the execution
a61af66fc99e Initial load
duke
parents:
diff changeset
1381 // continues at the bytecode following the method call.
a61af66fc99e Initial load
duke
parents:
diff changeset
1382
a61af66fc99e Initial load
duke
parents:
diff changeset
1383 // Threads_lock NOT held, java_thread not protected by lock
a61af66fc99e Initial load
duke
parents:
diff changeset
1384 // java_thread - pre-checked
a61af66fc99e Initial load
duke
parents:
diff changeset
1385
a61af66fc99e Initial load
duke
parents:
diff changeset
1386 jvmtiError
a61af66fc99e Initial load
duke
parents:
diff changeset
1387 JvmtiEnvBase::force_early_return(JavaThread* java_thread, jvalue value, TosState tos) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1388 JavaThread* current_thread = JavaThread::current();
a61af66fc99e Initial load
duke
parents:
diff changeset
1389 HandleMark hm(current_thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
1390 uint32_t debug_bits = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1391
609
ea20d7ce26b0 6800721: 3/4 JavaThread::jvmti_thread_state() and JvmtiThreadState::state_for() robustness
dcubed
parents: 470
diff changeset
1392 // retrieve or create the state
ea20d7ce26b0 6800721: 3/4 JavaThread::jvmti_thread_state() and JvmtiThreadState::state_for() robustness
dcubed
parents: 470
diff changeset
1393 JvmtiThreadState* state = JvmtiThreadState::state_for(java_thread);
ea20d7ce26b0 6800721: 3/4 JavaThread::jvmti_thread_state() and JvmtiThreadState::state_for() robustness
dcubed
parents: 470
diff changeset
1394 if (state == NULL) {
ea20d7ce26b0 6800721: 3/4 JavaThread::jvmti_thread_state() and JvmtiThreadState::state_for() robustness
dcubed
parents: 470
diff changeset
1395 return JVMTI_ERROR_THREAD_NOT_ALIVE;
ea20d7ce26b0 6800721: 3/4 JavaThread::jvmti_thread_state() and JvmtiThreadState::state_for() robustness
dcubed
parents: 470
diff changeset
1396 }
ea20d7ce26b0 6800721: 3/4 JavaThread::jvmti_thread_state() and JvmtiThreadState::state_for() robustness
dcubed
parents: 470
diff changeset
1397
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1398 // Check if java_thread is fully suspended
a61af66fc99e Initial load
duke
parents:
diff changeset
1399 if (!is_thread_fully_suspended(java_thread,
a61af66fc99e Initial load
duke
parents:
diff changeset
1400 true /* wait for suspend completion */,
a61af66fc99e Initial load
duke
parents:
diff changeset
1401 &debug_bits)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1402 return JVMTI_ERROR_THREAD_NOT_SUSPENDED;
a61af66fc99e Initial load
duke
parents:
diff changeset
1403 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1404
a61af66fc99e Initial load
duke
parents:
diff changeset
1405 // Check to see if a ForceEarlyReturn was already in progress
a61af66fc99e Initial load
duke
parents:
diff changeset
1406 if (state->is_earlyret_pending()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1407 // Probably possible for JVMTI clients to trigger this, but the
a61af66fc99e Initial load
duke
parents:
diff changeset
1408 // JPDA backend shouldn't allow this to happen
a61af66fc99e Initial load
duke
parents:
diff changeset
1409 return JVMTI_ERROR_INTERNAL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1410 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1411 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1412 // The same as for PopFrame. Workaround bug:
a61af66fc99e Initial load
duke
parents:
diff changeset
1413 // 4812902: popFrame hangs if the method is waiting at a synchronize
a61af66fc99e Initial load
duke
parents:
diff changeset
1414 // Catch this condition and return an error to avoid hanging.
a61af66fc99e Initial load
duke
parents:
diff changeset
1415 // Now JVMTI spec allows an implementation to bail out with an opaque
a61af66fc99e Initial load
duke
parents:
diff changeset
1416 // frame error.
a61af66fc99e Initial load
duke
parents:
diff changeset
1417 OSThread* osThread = java_thread->osthread();
a61af66fc99e Initial load
duke
parents:
diff changeset
1418 if (osThread->get_state() == MONITOR_WAIT) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1419 return JVMTI_ERROR_OPAQUE_FRAME;
a61af66fc99e Initial load
duke
parents:
diff changeset
1420 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1421 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1422 Handle ret_ob_h = Handle();
a61af66fc99e Initial load
duke
parents:
diff changeset
1423 jvmtiError err = check_top_frame(current_thread, java_thread, value, tos, &ret_ob_h);
a61af66fc99e Initial load
duke
parents:
diff changeset
1424 if (err != JVMTI_ERROR_NONE) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1425 return err;
a61af66fc99e Initial load
duke
parents:
diff changeset
1426 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1427 assert(tos != atos || value.l == NULL || ret_ob_h() != NULL,
a61af66fc99e Initial load
duke
parents:
diff changeset
1428 "return object oop must not be NULL if jobject is not NULL");
a61af66fc99e Initial load
duke
parents:
diff changeset
1429
a61af66fc99e Initial load
duke
parents:
diff changeset
1430 // Update the thread state to reflect that the top frame must be
a61af66fc99e Initial load
duke
parents:
diff changeset
1431 // forced to return.
a61af66fc99e Initial load
duke
parents:
diff changeset
1432 // The current frame will be returned later when the suspended
a61af66fc99e Initial load
duke
parents:
diff changeset
1433 // thread is resumed and right before returning from VM to Java.
a61af66fc99e Initial load
duke
parents:
diff changeset
1434 // (see call_VM_base() in assembler_<cpu>.cpp).
a61af66fc99e Initial load
duke
parents:
diff changeset
1435
a61af66fc99e Initial load
duke
parents:
diff changeset
1436 state->set_earlyret_pending();
a61af66fc99e Initial load
duke
parents:
diff changeset
1437 state->set_earlyret_oop(ret_ob_h());
a61af66fc99e Initial load
duke
parents:
diff changeset
1438 state->set_earlyret_value(value, tos);
a61af66fc99e Initial load
duke
parents:
diff changeset
1439
a61af66fc99e Initial load
duke
parents:
diff changeset
1440 // Set pending step flag for this early return.
a61af66fc99e Initial load
duke
parents:
diff changeset
1441 // It is cleared when next step event is posted.
a61af66fc99e Initial load
duke
parents:
diff changeset
1442 state->set_pending_step_for_earlyret();
a61af66fc99e Initial load
duke
parents:
diff changeset
1443
a61af66fc99e Initial load
duke
parents:
diff changeset
1444 return JVMTI_ERROR_NONE;
a61af66fc99e Initial load
duke
parents:
diff changeset
1445 } /* end force_early_return */
a61af66fc99e Initial load
duke
parents:
diff changeset
1446
a61af66fc99e Initial load
duke
parents:
diff changeset
1447 void
a61af66fc99e Initial load
duke
parents:
diff changeset
1448 JvmtiMonitorClosure::do_monitor(ObjectMonitor* mon) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1449 if ( _error != JVMTI_ERROR_NONE) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1450 // Error occurred in previous iteration so no need to add
a61af66fc99e Initial load
duke
parents:
diff changeset
1451 // to the list.
a61af66fc99e Initial load
duke
parents:
diff changeset
1452 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1453 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1454 if (mon->owner() == _java_thread ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1455 // Filter out on stack monitors collected during stack walk.
a61af66fc99e Initial load
duke
parents:
diff changeset
1456 oop obj = (oop)mon->object();
a61af66fc99e Initial load
duke
parents:
diff changeset
1457 bool found = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1458 for (int j = 0; j < _owned_monitors_list->length(); j++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1459 jobject jobj = ((jvmtiMonitorStackDepthInfo*)_owned_monitors_list->at(j))->monitor;
a61af66fc99e Initial load
duke
parents:
diff changeset
1460 oop check = JNIHandles::resolve(jobj);
a61af66fc99e Initial load
duke
parents:
diff changeset
1461 if (check == obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1462 // On stack monitor already collected during the stack walk.
a61af66fc99e Initial load
duke
parents:
diff changeset
1463 found = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
1464 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1465 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1466 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1467 if (found == false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1468 // This is off stack monitor (e.g. acquired via jni MonitorEnter).
a61af66fc99e Initial load
duke
parents:
diff changeset
1469 jvmtiError err;
a61af66fc99e Initial load
duke
parents:
diff changeset
1470 jvmtiMonitorStackDepthInfo *jmsdi;
a61af66fc99e Initial load
duke
parents:
diff changeset
1471 err = _env->allocate(sizeof(jvmtiMonitorStackDepthInfo), (unsigned char **)&jmsdi);
a61af66fc99e Initial load
duke
parents:
diff changeset
1472 if (err != JVMTI_ERROR_NONE) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1473 _error = err;
a61af66fc99e Initial load
duke
parents:
diff changeset
1474 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1475 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1476 Handle hobj(obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
1477 jmsdi->monitor = _env->jni_reference(_calling_thread, hobj);
a61af66fc99e Initial load
duke
parents:
diff changeset
1478 // stack depth is unknown for this monitor.
a61af66fc99e Initial load
duke
parents:
diff changeset
1479 jmsdi->stack_depth = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
1480 _owned_monitors_list->append(jmsdi);
a61af66fc99e Initial load
duke
parents:
diff changeset
1481 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1482 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1483 }