| File: | jdk/src/hotspot/share/prims/jvmtiEnvBase.hpp |
| Warning: | line 195, column 16 Dereference of null pointer (loaded from variable 'mem_ptr') |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* | ||||||
| 2 | * Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved. | ||||||
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||||||
| 4 | * | ||||||
| 5 | * This code is free software; you can redistribute it and/or modify it | ||||||
| 6 | * under the terms of the GNU General Public License version 2 only, as | ||||||
| 7 | * published by the Free Software Foundation. | ||||||
| 8 | * | ||||||
| 9 | * This code is distributed in the hope that it will be useful, but WITHOUT | ||||||
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||||||
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||||||
| 12 | * version 2 for more details (a copy is included in the LICENSE file that | ||||||
| 13 | * accompanied this code). | ||||||
| 14 | * | ||||||
| 15 | * You should have received a copy of the GNU General Public License version | ||||||
| 16 | * 2 along with this work; if not, write to the Free Software Foundation, | ||||||
| 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||||||
| 18 | * | ||||||
| 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||||||
| 20 | * or visit www.oracle.com if you need additional information or have any | ||||||
| 21 | * questions. | ||||||
| 22 | * | ||||||
| 23 | */ | ||||||
| 24 | |||||||
| 25 | #include "precompiled.hpp" | ||||||
| 26 | #include "classfile/classLoaderExt.hpp" | ||||||
| 27 | #include "classfile/javaClasses.inline.hpp" | ||||||
| 28 | #include "classfile/stringTable.hpp" | ||||||
| 29 | #include "classfile/modules.hpp" | ||||||
| 30 | #include "classfile/systemDictionary.hpp" | ||||||
| 31 | #include "classfile/vmClasses.hpp" | ||||||
| 32 | #include "classfile/vmSymbols.hpp" | ||||||
| 33 | #include "gc/shared/collectedHeap.hpp" | ||||||
| 34 | #include "interpreter/bytecodeStream.hpp" | ||||||
| 35 | #include "interpreter/interpreter.hpp" | ||||||
| 36 | #include "jfr/jfrEvents.hpp" | ||||||
| 37 | #include "jvmtifiles/jvmtiEnv.hpp" | ||||||
| 38 | #include "logging/log.hpp" | ||||||
| 39 | #include "logging/logConfiguration.hpp" | ||||||
| 40 | #include "memory/resourceArea.hpp" | ||||||
| 41 | #include "memory/universe.hpp" | ||||||
| 42 | #include "oops/instanceKlass.hpp" | ||||||
| 43 | #include "oops/klass.inline.hpp" | ||||||
| 44 | #include "oops/objArrayOop.inline.hpp" | ||||||
| 45 | #include "oops/oop.inline.hpp" | ||||||
| 46 | #include "prims/jniCheck.hpp" | ||||||
| 47 | #include "prims/jvm_misc.hpp" | ||||||
| 48 | #include "prims/jvmtiAgentThread.hpp" | ||||||
| 49 | #include "prims/jvmtiClassFileReconstituter.hpp" | ||||||
| 50 | #include "prims/jvmtiCodeBlobEvents.hpp" | ||||||
| 51 | #include "prims/jvmtiExtensions.hpp" | ||||||
| 52 | #include "prims/jvmtiGetLoadedClasses.hpp" | ||||||
| 53 | #include "prims/jvmtiImpl.hpp" | ||||||
| 54 | #include "prims/jvmtiManageCapabilities.hpp" | ||||||
| 55 | #include "prims/jvmtiRawMonitor.hpp" | ||||||
| 56 | #include "prims/jvmtiRedefineClasses.hpp" | ||||||
| 57 | #include "prims/jvmtiTagMap.hpp" | ||||||
| 58 | #include "prims/jvmtiThreadState.inline.hpp" | ||||||
| 59 | #include "prims/jvmtiUtil.hpp" | ||||||
| 60 | #include "runtime/arguments.hpp" | ||||||
| 61 | #include "runtime/deoptimization.hpp" | ||||||
| 62 | #include "runtime/fieldDescriptor.inline.hpp" | ||||||
| 63 | #include "runtime/handles.inline.hpp" | ||||||
| 64 | #include "runtime/interfaceSupport.inline.hpp" | ||||||
| 65 | #include "runtime/javaCalls.hpp" | ||||||
| 66 | #include "runtime/jfieldIDWorkaround.hpp" | ||||||
| 67 | #include "runtime/jniHandles.inline.hpp" | ||||||
| 68 | #include "runtime/objectMonitor.inline.hpp" | ||||||
| 69 | #include "runtime/osThread.hpp" | ||||||
| 70 | #include "runtime/reflectionUtils.hpp" | ||||||
| 71 | #include "runtime/signature.hpp" | ||||||
| 72 | #include "runtime/thread.inline.hpp" | ||||||
| 73 | #include "runtime/threadHeapSampler.hpp" | ||||||
| 74 | #include "runtime/threadSMR.hpp" | ||||||
| 75 | #include "runtime/timerTrace.hpp" | ||||||
| 76 | #include "runtime/vframe.inline.hpp" | ||||||
| 77 | #include "runtime/vmThread.hpp" | ||||||
| 78 | #include "services/threadService.hpp" | ||||||
| 79 | #include "utilities/exceptions.hpp" | ||||||
| 80 | #include "utilities/preserveException.hpp" | ||||||
| 81 | #include "utilities/utf8.hpp" | ||||||
| 82 | |||||||
| 83 | |||||||
| 84 | #define FIXLATER0 0 // REMOVE this when completed. | ||||||
| 85 | |||||||
| 86 | // FIXLATER: hook into JvmtiTrace | ||||||
| 87 | #define TraceJVMTICallsfalse false | ||||||
| 88 | |||||||
| 89 | JvmtiEnv::JvmtiEnv(jint version) : JvmtiEnvBase(version) { | ||||||
| 90 | } | ||||||
| 91 | |||||||
| 92 | JvmtiEnv::~JvmtiEnv() { | ||||||
| 93 | } | ||||||
| 94 | |||||||
| 95 | JvmtiEnv* | ||||||
| 96 | JvmtiEnv::create_a_jvmti(jint version) { | ||||||
| 97 | return new JvmtiEnv(version); | ||||||
| 98 | } | ||||||
| 99 | |||||||
| 100 | // VM operation class to copy jni function table at safepoint. | ||||||
| 101 | // More than one java threads or jvmti agents may be reading/ | ||||||
| 102 | // modifying jni function tables. To reduce the risk of bad | ||||||
| 103 | // interaction b/w these threads it is copied at safepoint. | ||||||
| 104 | class VM_JNIFunctionTableCopier : public VM_Operation { | ||||||
| 105 | private: | ||||||
| 106 | const struct JNINativeInterface_ *_function_table; | ||||||
| 107 | public: | ||||||
| 108 | VM_JNIFunctionTableCopier(const struct JNINativeInterface_ *func_tbl) { | ||||||
| 109 | _function_table = func_tbl; | ||||||
| 110 | }; | ||||||
| 111 | |||||||
| 112 | VMOp_Type type() const { return VMOp_JNIFunctionTableCopier; } | ||||||
| 113 | void doit() { | ||||||
| 114 | copy_jni_function_table(_function_table); | ||||||
| 115 | }; | ||||||
| 116 | }; | ||||||
| 117 | |||||||
| 118 | // | ||||||
| 119 | // Do not change the "prefix" marker below, everything above it is copied | ||||||
| 120 | // unchanged into the filled stub, everything below is controlled by the | ||||||
| 121 | // stub filler (only method bodies are carried forward, and then only for | ||||||
| 122 | // functionality still in the spec). | ||||||
| 123 | // | ||||||
| 124 | // end file prefix | ||||||
| 125 | |||||||
| 126 | // | ||||||
| 127 | // Memory Management functions | ||||||
| 128 | // | ||||||
| 129 | |||||||
| 130 | // mem_ptr - pre-checked for NULL | ||||||
| 131 | jvmtiError | ||||||
| 132 | JvmtiEnv::Allocate(jlong size, unsigned char** mem_ptr) { | ||||||
| 133 | return allocate(size, mem_ptr); | ||||||
| 134 | } /* end Allocate */ | ||||||
| 135 | |||||||
| 136 | |||||||
| 137 | // mem - NULL is a valid value, must be checked | ||||||
| 138 | jvmtiError | ||||||
| 139 | JvmtiEnv::Deallocate(unsigned char* mem) { | ||||||
| 140 | return deallocate(mem); | ||||||
| 141 | } /* end Deallocate */ | ||||||
| 142 | |||||||
| 143 | // java_thread - protected by ThreadsListHandle and pre-checked | ||||||
| 144 | // data - NULL is a valid value, must be checked | ||||||
| 145 | jvmtiError | ||||||
| 146 | JvmtiEnv::SetThreadLocalStorage(JavaThread* java_thread, const void* data) { | ||||||
| 147 | JvmtiThreadState* state = java_thread->jvmti_thread_state(); | ||||||
| 148 | if (state == NULL__null) { | ||||||
| 149 | if (data == NULL__null) { | ||||||
| 150 | // leaving state unset same as data set to NULL | ||||||
| 151 | return JVMTI_ERROR_NONE; | ||||||
| 152 | } | ||||||
| 153 | // otherwise, create the state | ||||||
| 154 | state = JvmtiThreadState::state_for(java_thread); | ||||||
| 155 | if (state == NULL__null) { | ||||||
| 156 | return JVMTI_ERROR_THREAD_NOT_ALIVE; | ||||||
| 157 | } | ||||||
| 158 | } | ||||||
| 159 | state->env_thread_state(this)->set_agent_thread_local_storage_data((void*)data); | ||||||
| 160 | return JVMTI_ERROR_NONE; | ||||||
| 161 | } /* end SetThreadLocalStorage */ | ||||||
| 162 | |||||||
| 163 | |||||||
| 164 | // thread - NOT protected by ThreadsListHandle and NOT pre-checked | ||||||
| 165 | // data_ptr - pre-checked for NULL | ||||||
| 166 | jvmtiError | ||||||
| 167 | JvmtiEnv::GetThreadLocalStorage(jthread thread, void** data_ptr) { | ||||||
| 168 | JavaThread* current_thread = JavaThread::current(); | ||||||
| 169 | if (thread == NULL__null) { | ||||||
| 170 | JvmtiThreadState* state = current_thread->jvmti_thread_state(); | ||||||
| 171 | *data_ptr = (state == NULL__null) ? NULL__null : | ||||||
| 172 | state->env_thread_state(this)->get_agent_thread_local_storage_data(); | ||||||
| 173 | } else { | ||||||
| 174 | // jvmti_GetThreadLocalStorage is "in native" and doesn't transition | ||||||
| 175 | // the thread to _thread_in_vm. However, when the TLS for a thread | ||||||
| 176 | // other than the current thread is required we need to transition | ||||||
| 177 | // from native so as to resolve the jthread. | ||||||
| 178 | |||||||
| 179 | MACOS_AARCH64_ONLY(ThreadWXEnable __wx(WXWrite, current_thread)); | ||||||
| 180 | ThreadInVMfromNative __tiv(current_thread); | ||||||
| 181 | VM_ENTRY_BASE(jvmtiError, JvmtiEnv::GetThreadLocalStorage , current_thread)HandleMarkCleaner __hm(current_thread); JavaThread* __the_thread__ = current_thread; os::verify_stack_alignment(); | ||||||
| 182 | debug_only(VMNativeEntryWrapper __vew;)VMNativeEntryWrapper __vew; | ||||||
| 183 | |||||||
| 184 | JavaThread* java_thread = NULL__null; | ||||||
| 185 | ThreadsListHandle tlh(current_thread); | ||||||
| 186 | jvmtiError err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL__null); | ||||||
| 187 | if (err != JVMTI_ERROR_NONE) { | ||||||
| 188 | return err; | ||||||
| 189 | } | ||||||
| 190 | |||||||
| 191 | JvmtiThreadState* state = java_thread->jvmti_thread_state(); | ||||||
| 192 | *data_ptr = (state == NULL__null) ? NULL__null : | ||||||
| 193 | state->env_thread_state(this)->get_agent_thread_local_storage_data(); | ||||||
| 194 | } | ||||||
| 195 | return JVMTI_ERROR_NONE; | ||||||
| 196 | } /* end GetThreadLocalStorage */ | ||||||
| 197 | |||||||
| 198 | // | ||||||
| 199 | // Module functions | ||||||
| 200 | // | ||||||
| 201 | |||||||
| 202 | // module_count_ptr - pre-checked for NULL | ||||||
| 203 | // modules_ptr - pre-checked for NULL | ||||||
| 204 | jvmtiError | ||||||
| 205 | JvmtiEnv::GetAllModules(jint* module_count_ptr, jobject** modules_ptr) { | ||||||
| 206 | JvmtiModuleClosure jmc; | ||||||
| 207 | |||||||
| 208 | return jmc.get_all_modules(this, module_count_ptr, modules_ptr); | ||||||
| 209 | } /* end GetAllModules */ | ||||||
| 210 | |||||||
| 211 | |||||||
| 212 | // class_loader - NULL is a valid value, must be pre-checked | ||||||
| 213 | // package_name - pre-checked for NULL | ||||||
| 214 | // module_ptr - pre-checked for NULL | ||||||
| 215 | jvmtiError | ||||||
| 216 | JvmtiEnv::GetNamedModule(jobject class_loader, const char* package_name, jobject* module_ptr) { | ||||||
| 217 | JavaThread* THREAD__the_thread__ = JavaThread::current(); // For exception macros. | ||||||
| 218 | ResourceMark rm(THREAD__the_thread__); | ||||||
| 219 | Handle h_loader (THREAD__the_thread__, JNIHandles::resolve(class_loader)); | ||||||
| 220 | // Check that loader is a subclass of java.lang.ClassLoader. | ||||||
| 221 | if (h_loader.not_null() && !java_lang_ClassLoader::is_subclass(h_loader->klass())) { | ||||||
| 222 | return JVMTI_ERROR_ILLEGAL_ARGUMENT; | ||||||
| 223 | } | ||||||
| 224 | oop module = Modules::get_named_module(h_loader, package_name); | ||||||
| 225 | *module_ptr = module != NULL__null ? JNIHandles::make_local(THREAD__the_thread__, module) : NULL__null; | ||||||
| 226 | return JVMTI_ERROR_NONE; | ||||||
| 227 | } /* end GetNamedModule */ | ||||||
| 228 | |||||||
| 229 | |||||||
| 230 | // module - pre-checked for NULL | ||||||
| 231 | // to_module - pre-checked for NULL | ||||||
| 232 | jvmtiError | ||||||
| 233 | JvmtiEnv::AddModuleReads(jobject module, jobject to_module) { | ||||||
| 234 | JavaThread* THREAD__the_thread__ = JavaThread::current(); // For exception macros. | ||||||
| 235 | |||||||
| 236 | // check module | ||||||
| 237 | Handle h_module(THREAD__the_thread__, JNIHandles::resolve(module)); | ||||||
| 238 | if (!java_lang_Module::is_instance(h_module())) { | ||||||
| 239 | return JVMTI_ERROR_INVALID_MODULE; | ||||||
| 240 | } | ||||||
| 241 | // check to_module | ||||||
| 242 | Handle h_to_module(THREAD__the_thread__, JNIHandles::resolve(to_module)); | ||||||
| 243 | if (!java_lang_Module::is_instance(h_to_module())) { | ||||||
| 244 | return JVMTI_ERROR_INVALID_MODULE; | ||||||
| 245 | } | ||||||
| 246 | return JvmtiExport::add_module_reads(h_module, h_to_module, THREAD__the_thread__); | ||||||
| 247 | } /* end AddModuleReads */ | ||||||
| 248 | |||||||
| 249 | |||||||
| 250 | // module - pre-checked for NULL | ||||||
| 251 | // pkg_name - pre-checked for NULL | ||||||
| 252 | // to_module - pre-checked for NULL | ||||||
| 253 | jvmtiError | ||||||
| 254 | JvmtiEnv::AddModuleExports(jobject module, const char* pkg_name, jobject to_module) { | ||||||
| 255 | JavaThread* THREAD__the_thread__ = JavaThread::current(); // For exception macros. | ||||||
| 256 | Handle h_pkg = java_lang_String::create_from_str(pkg_name, THREAD__the_thread__); | ||||||
| 257 | |||||||
| 258 | // check module | ||||||
| 259 | Handle h_module(THREAD__the_thread__, JNIHandles::resolve(module)); | ||||||
| 260 | if (!java_lang_Module::is_instance(h_module())) { | ||||||
| 261 | return JVMTI_ERROR_INVALID_MODULE; | ||||||
| 262 | } | ||||||
| 263 | // check to_module | ||||||
| 264 | Handle h_to_module(THREAD__the_thread__, JNIHandles::resolve(to_module)); | ||||||
| 265 | if (!java_lang_Module::is_instance(h_to_module())) { | ||||||
| 266 | return JVMTI_ERROR_INVALID_MODULE; | ||||||
| 267 | } | ||||||
| 268 | return JvmtiExport::add_module_exports(h_module, h_pkg, h_to_module, THREAD__the_thread__); | ||||||
| 269 | } /* end AddModuleExports */ | ||||||
| 270 | |||||||
| 271 | |||||||
| 272 | // module - pre-checked for NULL | ||||||
| 273 | // pkg_name - pre-checked for NULL | ||||||
| 274 | // to_module - pre-checked for NULL | ||||||
| 275 | jvmtiError | ||||||
| 276 | JvmtiEnv::AddModuleOpens(jobject module, const char* pkg_name, jobject to_module) { | ||||||
| 277 | JavaThread* THREAD__the_thread__ = JavaThread::current(); // For exception macros. | ||||||
| 278 | Handle h_pkg = java_lang_String::create_from_str(pkg_name, THREAD__the_thread__); | ||||||
| 279 | |||||||
| 280 | // check module | ||||||
| 281 | Handle h_module(THREAD__the_thread__, JNIHandles::resolve(module)); | ||||||
| 282 | if (!java_lang_Module::is_instance(h_module())) { | ||||||
| 283 | return JVMTI_ERROR_INVALID_MODULE; | ||||||
| 284 | } | ||||||
| 285 | // check to_module | ||||||
| 286 | Handle h_to_module(THREAD__the_thread__, JNIHandles::resolve(to_module)); | ||||||
| 287 | if (!java_lang_Module::is_instance(h_to_module())) { | ||||||
| 288 | return JVMTI_ERROR_INVALID_MODULE; | ||||||
| 289 | } | ||||||
| 290 | return JvmtiExport::add_module_opens(h_module, h_pkg, h_to_module, THREAD__the_thread__); | ||||||
| 291 | } /* end AddModuleOpens */ | ||||||
| 292 | |||||||
| 293 | |||||||
| 294 | // module - pre-checked for NULL | ||||||
| 295 | // service - pre-checked for NULL | ||||||
| 296 | jvmtiError | ||||||
| 297 | JvmtiEnv::AddModuleUses(jobject module, jclass service) { | ||||||
| 298 | JavaThread* THREAD__the_thread__ = JavaThread::current(); // For exception macros. | ||||||
| 299 | |||||||
| 300 | // check module | ||||||
| 301 | Handle h_module(THREAD__the_thread__, JNIHandles::resolve(module)); | ||||||
| 302 | if (!java_lang_Module::is_instance(h_module())) { | ||||||
| 303 | return JVMTI_ERROR_INVALID_MODULE; | ||||||
| 304 | } | ||||||
| 305 | // check service | ||||||
| 306 | Handle h_service(THREAD__the_thread__, JNIHandles::resolve_external_guard(service)); | ||||||
| 307 | if (!java_lang_Class::is_instance(h_service()) || | ||||||
| 308 | java_lang_Class::is_primitive(h_service())) { | ||||||
| 309 | return JVMTI_ERROR_INVALID_CLASS; | ||||||
| 310 | } | ||||||
| 311 | return JvmtiExport::add_module_uses(h_module, h_service, THREAD__the_thread__); | ||||||
| 312 | } /* end AddModuleUses */ | ||||||
| 313 | |||||||
| 314 | |||||||
| 315 | // module - pre-checked for NULL | ||||||
| 316 | // service - pre-checked for NULL | ||||||
| 317 | // impl_class - pre-checked for NULL | ||||||
| 318 | jvmtiError | ||||||
| 319 | JvmtiEnv::AddModuleProvides(jobject module, jclass service, jclass impl_class) { | ||||||
| 320 | JavaThread* THREAD__the_thread__ = JavaThread::current(); // For exception macros. | ||||||
| 321 | |||||||
| 322 | // check module | ||||||
| 323 | Handle h_module(THREAD__the_thread__, JNIHandles::resolve(module)); | ||||||
| 324 | if (!java_lang_Module::is_instance(h_module())) { | ||||||
| 325 | return JVMTI_ERROR_INVALID_MODULE; | ||||||
| 326 | } | ||||||
| 327 | // check service | ||||||
| 328 | Handle h_service(THREAD__the_thread__, JNIHandles::resolve_external_guard(service)); | ||||||
| 329 | if (!java_lang_Class::is_instance(h_service()) || | ||||||
| 330 | java_lang_Class::is_primitive(h_service())) { | ||||||
| 331 | return JVMTI_ERROR_INVALID_CLASS; | ||||||
| 332 | } | ||||||
| 333 | // check impl_class | ||||||
| 334 | Handle h_impl_class(THREAD__the_thread__, JNIHandles::resolve_external_guard(impl_class)); | ||||||
| 335 | if (!java_lang_Class::is_instance(h_impl_class()) || | ||||||
| 336 | java_lang_Class::is_primitive(h_impl_class())) { | ||||||
| 337 | return JVMTI_ERROR_INVALID_CLASS; | ||||||
| 338 | } | ||||||
| 339 | return JvmtiExport::add_module_provides(h_module, h_service, h_impl_class, THREAD__the_thread__); | ||||||
| 340 | } /* end AddModuleProvides */ | ||||||
| 341 | |||||||
| 342 | // module - pre-checked for NULL | ||||||
| 343 | // is_modifiable_class_ptr - pre-checked for NULL | ||||||
| 344 | jvmtiError | ||||||
| 345 | JvmtiEnv::IsModifiableModule(jobject module, jboolean* is_modifiable_module_ptr) { | ||||||
| 346 | JavaThread* current = JavaThread::current(); | ||||||
| 347 | |||||||
| 348 | // check module | ||||||
| 349 | Handle h_module(current, JNIHandles::resolve(module)); | ||||||
| 350 | if (!java_lang_Module::is_instance(h_module())) { | ||||||
| 351 | return JVMTI_ERROR_INVALID_MODULE; | ||||||
| 352 | } | ||||||
| 353 | |||||||
| 354 | *is_modifiable_module_ptr = JNI_TRUE1; | ||||||
| 355 | return JVMTI_ERROR_NONE; | ||||||
| 356 | } /* end IsModifiableModule */ | ||||||
| 357 | |||||||
| 358 | |||||||
| 359 | // | ||||||
| 360 | // Class functions | ||||||
| 361 | // | ||||||
| 362 | |||||||
| 363 | // class_count_ptr - pre-checked for NULL | ||||||
| 364 | // classes_ptr - pre-checked for NULL | ||||||
| 365 | jvmtiError | ||||||
| 366 | JvmtiEnv::GetLoadedClasses(jint* class_count_ptr, jclass** classes_ptr) { | ||||||
| 367 | return JvmtiGetLoadedClasses::getLoadedClasses(this, class_count_ptr, classes_ptr); | ||||||
| 368 | } /* end GetLoadedClasses */ | ||||||
| 369 | |||||||
| 370 | |||||||
| 371 | // initiating_loader - NULL is a valid value, must be checked | ||||||
| 372 | // class_count_ptr - pre-checked for NULL | ||||||
| 373 | // classes_ptr - pre-checked for NULL | ||||||
| 374 | jvmtiError | ||||||
| 375 | JvmtiEnv::GetClassLoaderClasses(jobject initiating_loader, jint* class_count_ptr, jclass** classes_ptr) { | ||||||
| 376 | return JvmtiGetLoadedClasses::getClassLoaderClasses(this, initiating_loader, | ||||||
| 377 | class_count_ptr, classes_ptr); | ||||||
| 378 | } /* end GetClassLoaderClasses */ | ||||||
| 379 | |||||||
| 380 | // k_mirror - may be primitive, this must be checked | ||||||
| 381 | // is_modifiable_class_ptr - pre-checked for NULL | ||||||
| 382 | jvmtiError | ||||||
| 383 | JvmtiEnv::IsModifiableClass(oop k_mirror, jboolean* is_modifiable_class_ptr) { | ||||||
| 384 | *is_modifiable_class_ptr = VM_RedefineClasses::is_modifiable_class(k_mirror)? | ||||||
| 385 | JNI_TRUE1 : JNI_FALSE0; | ||||||
| 386 | return JVMTI_ERROR_NONE; | ||||||
| 387 | } /* end IsModifiableClass */ | ||||||
| 388 | |||||||
| 389 | // class_count - pre-checked to be greater than or equal to 0 | ||||||
| 390 | // classes - pre-checked for NULL | ||||||
| 391 | jvmtiError | ||||||
| 392 | JvmtiEnv::RetransformClasses(jint class_count, const jclass* classes) { | ||||||
| 393 | //TODO: add locking | ||||||
| 394 | |||||||
| 395 | int index; | ||||||
| 396 | JavaThread* current_thread = JavaThread::current(); | ||||||
| 397 | ResourceMark rm(current_thread); | ||||||
| 398 | |||||||
| 399 | jvmtiClassDefinition* class_definitions = | ||||||
| 400 | NEW_RESOURCE_ARRAY(jvmtiClassDefinition, class_count)(jvmtiClassDefinition*) resource_allocate_bytes((class_count) * sizeof(jvmtiClassDefinition)); | ||||||
| 401 | NULL_CHECK(class_definitions, JVMTI_ERROR_OUT_OF_MEMORY)if ((class_definitions) == __null) { return (JVMTI_ERROR_OUT_OF_MEMORY ); }; | ||||||
| 402 | |||||||
| 403 | for (index = 0; index < class_count; index++) { | ||||||
| 404 | HandleMark hm(current_thread); | ||||||
| 405 | |||||||
| 406 | jclass jcls = classes[index]; | ||||||
| 407 | oop k_mirror = JNIHandles::resolve_external_guard(jcls); | ||||||
| 408 | if (k_mirror == NULL__null) { | ||||||
| 409 | return JVMTI_ERROR_INVALID_CLASS; | ||||||
| 410 | } | ||||||
| 411 | if (!k_mirror->is_a(vmClasses::Class_klass())) { | ||||||
| 412 | return JVMTI_ERROR_INVALID_CLASS; | ||||||
| 413 | } | ||||||
| 414 | |||||||
| 415 | if (!VM_RedefineClasses::is_modifiable_class(k_mirror)) { | ||||||
| 416 | return JVMTI_ERROR_UNMODIFIABLE_CLASS; | ||||||
| 417 | } | ||||||
| 418 | |||||||
| 419 | Klass* klass = java_lang_Class::as_Klass(k_mirror); | ||||||
| 420 | |||||||
| 421 | jint status = klass->jvmti_class_status(); | ||||||
| 422 | if (status & (JVMTI_CLASS_STATUS_ERROR)) { | ||||||
| 423 | return JVMTI_ERROR_INVALID_CLASS; | ||||||
| 424 | } | ||||||
| 425 | |||||||
| 426 | InstanceKlass* ik = InstanceKlass::cast(klass); | ||||||
| 427 | if (ik->get_cached_class_file_bytes() == NULL__null) { | ||||||
| 428 | // Not cached, we need to reconstitute the class file from the | ||||||
| 429 | // VM representation. We don't attach the reconstituted class | ||||||
| 430 | // bytes to the InstanceKlass here because they have not been | ||||||
| 431 | // validated and we're not at a safepoint. | ||||||
| 432 | JvmtiClassFileReconstituter reconstituter(ik); | ||||||
| 433 | if (reconstituter.get_error() != JVMTI_ERROR_NONE) { | ||||||
| 434 | return reconstituter.get_error(); | ||||||
| 435 | } | ||||||
| 436 | |||||||
| 437 | class_definitions[index].class_byte_count = (jint)reconstituter.class_file_size(); | ||||||
| 438 | class_definitions[index].class_bytes = (unsigned char*) | ||||||
| 439 | reconstituter.class_file_bytes(); | ||||||
| 440 | } else { | ||||||
| 441 | // it is cached, get it from the cache | ||||||
| 442 | class_definitions[index].class_byte_count = ik->get_cached_class_file_len(); | ||||||
| 443 | class_definitions[index].class_bytes = ik->get_cached_class_file_bytes(); | ||||||
| 444 | } | ||||||
| 445 | class_definitions[index].klass = jcls; | ||||||
| 446 | } | ||||||
| 447 | EventRetransformClasses event; | ||||||
| 448 | VM_RedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_retransform); | ||||||
| 449 | VMThread::execute(&op); | ||||||
| 450 | jvmtiError error = op.check_error(); | ||||||
| 451 | if (error == JVMTI_ERROR_NONE) { | ||||||
| 452 | event.set_classCount(class_count); | ||||||
| 453 | event.set_redefinitionId(op.id()); | ||||||
| 454 | event.commit(); | ||||||
| 455 | } | ||||||
| 456 | return error; | ||||||
| 457 | } /* end RetransformClasses */ | ||||||
| 458 | |||||||
| 459 | |||||||
| 460 | // class_count - pre-checked to be greater than or equal to 0 | ||||||
| 461 | // class_definitions - pre-checked for NULL | ||||||
| 462 | jvmtiError | ||||||
| 463 | JvmtiEnv::RedefineClasses(jint class_count, const jvmtiClassDefinition* class_definitions) { | ||||||
| 464 | //TODO: add locking | ||||||
| 465 | EventRedefineClasses event; | ||||||
| 466 | VM_RedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_redefine); | ||||||
| 467 | VMThread::execute(&op); | ||||||
| 468 | jvmtiError error = op.check_error(); | ||||||
| 469 | if (error == JVMTI_ERROR_NONE) { | ||||||
| 470 | event.set_classCount(class_count); | ||||||
| 471 | event.set_redefinitionId(op.id()); | ||||||
| 472 | event.commit(); | ||||||
| 473 | } | ||||||
| 474 | return error; | ||||||
| 475 | } /* end RedefineClasses */ | ||||||
| 476 | |||||||
| 477 | |||||||
| 478 | // | ||||||
| 479 | // Object functions | ||||||
| 480 | // | ||||||
| 481 | |||||||
| 482 | // size_ptr - pre-checked for NULL | ||||||
| 483 | jvmtiError | ||||||
| 484 | JvmtiEnv::GetObjectSize(jobject object, jlong* size_ptr) { | ||||||
| 485 | oop mirror = JNIHandles::resolve_external_guard(object); | ||||||
| 486 | NULL_CHECK(mirror, JVMTI_ERROR_INVALID_OBJECT)if ((mirror) == __null) { return (JVMTI_ERROR_INVALID_OBJECT) ; }; | ||||||
| 487 | *size_ptr = (jlong)mirror->size() * wordSize; | ||||||
| 488 | return JVMTI_ERROR_NONE; | ||||||
| 489 | } /* end GetObjectSize */ | ||||||
| 490 | |||||||
| 491 | // | ||||||
| 492 | // Method functions | ||||||
| 493 | // | ||||||
| 494 | |||||||
| 495 | // prefix - NULL is a valid value, must be checked | ||||||
| 496 | jvmtiError | ||||||
| 497 | JvmtiEnv::SetNativeMethodPrefix(const char* prefix) { | ||||||
| 498 | return prefix == NULL__null? | ||||||
| 499 | SetNativeMethodPrefixes(0, NULL__null) : | ||||||
| 500 | SetNativeMethodPrefixes(1, (char**)&prefix); | ||||||
| 501 | } /* end SetNativeMethodPrefix */ | ||||||
| 502 | |||||||
| 503 | |||||||
| 504 | // prefix_count - pre-checked to be greater than or equal to 0 | ||||||
| 505 | // prefixes - pre-checked for NULL | ||||||
| 506 | jvmtiError | ||||||
| 507 | JvmtiEnv::SetNativeMethodPrefixes(jint prefix_count, char** prefixes) { | ||||||
| 508 | // Have to grab JVMTI thread state lock to be sure that some thread | ||||||
| 509 | // isn't accessing the prefixes at the same time we are setting them. | ||||||
| 510 | // No locks during VM bring-up. | ||||||
| 511 | if (Threads::number_of_threads() == 0) { | ||||||
| 512 | return set_native_method_prefixes(prefix_count, prefixes); | ||||||
| 513 | } else { | ||||||
| 514 | MutexLocker mu(JvmtiThreadState_lock); | ||||||
| 515 | return set_native_method_prefixes(prefix_count, prefixes); | ||||||
| 516 | } | ||||||
| 517 | } /* end SetNativeMethodPrefixes */ | ||||||
| 518 | |||||||
| 519 | // | ||||||
| 520 | // Event Management functions | ||||||
| 521 | // | ||||||
| 522 | |||||||
| 523 | // callbacks - NULL is a valid value, must be checked | ||||||
| 524 | // size_of_callbacks - pre-checked to be greater than or equal to 0 | ||||||
| 525 | jvmtiError | ||||||
| 526 | JvmtiEnv::SetEventCallbacks(const jvmtiEventCallbacks* callbacks, jint size_of_callbacks) { | ||||||
| 527 | JvmtiEventController::set_event_callbacks(this, callbacks, size_of_callbacks); | ||||||
| 528 | return JVMTI_ERROR_NONE; | ||||||
| 529 | } /* end SetEventCallbacks */ | ||||||
| 530 | |||||||
| 531 | |||||||
| 532 | // event_thread - NULL is a valid value, must be checked | ||||||
| 533 | jvmtiError | ||||||
| 534 | JvmtiEnv::SetEventNotificationMode(jvmtiEventMode mode, jvmtiEvent event_type, jthread event_thread, ...) { | ||||||
| 535 | if (event_thread == NULL__null) { | ||||||
| 536 | // Can be called at Agent_OnLoad() time with event_thread == NULL | ||||||
| 537 | // when Thread::current() does not work yet so we cannot create a | ||||||
| 538 | // ThreadsListHandle that is common to both thread-specific and | ||||||
| 539 | // global code paths. | ||||||
| 540 | |||||||
| 541 | // event_type must be valid | ||||||
| 542 | if (!JvmtiEventController::is_valid_event_type(event_type)) { | ||||||
| 543 | return JVMTI_ERROR_INVALID_EVENT_TYPE; | ||||||
| 544 | } | ||||||
| 545 | |||||||
| 546 | bool enabled = (mode == JVMTI_ENABLE); | ||||||
| 547 | |||||||
| 548 | // assure that needed capabilities are present | ||||||
| 549 | if (enabled && !JvmtiUtil::has_event_capability(event_type, get_capabilities())) { | ||||||
| 550 | return JVMTI_ERROR_MUST_POSSESS_CAPABILITY; | ||||||
| 551 | } | ||||||
| 552 | |||||||
| 553 | if (event_type == JVMTI_EVENT_CLASS_FILE_LOAD_HOOK && enabled) { | ||||||
| 554 | record_class_file_load_hook_enabled(); | ||||||
| 555 | } | ||||||
| 556 | |||||||
| 557 | JvmtiEventController::set_user_enabled(this, (JavaThread*) NULL__null, event_type, enabled); | ||||||
| 558 | } else { | ||||||
| 559 | // We have a specified event_thread. | ||||||
| 560 | JavaThread* java_thread = NULL__null; | ||||||
| 561 | ThreadsListHandle tlh; | ||||||
| 562 | jvmtiError err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), event_thread, &java_thread, NULL__null); | ||||||
| 563 | if (err != JVMTI_ERROR_NONE) { | ||||||
| 564 | return err; | ||||||
| 565 | } | ||||||
| 566 | |||||||
| 567 | // event_type must be valid | ||||||
| 568 | if (!JvmtiEventController::is_valid_event_type(event_type)) { | ||||||
| 569 | return JVMTI_ERROR_INVALID_EVENT_TYPE; | ||||||
| 570 | } | ||||||
| 571 | |||||||
| 572 | // global events cannot be controlled at thread level. | ||||||
| 573 | if (JvmtiEventController::is_global_event(event_type)) { | ||||||
| 574 | return JVMTI_ERROR_ILLEGAL_ARGUMENT; | ||||||
| 575 | } | ||||||
| 576 | |||||||
| 577 | bool enabled = (mode == JVMTI_ENABLE); | ||||||
| 578 | |||||||
| 579 | // assure that needed capabilities are present | ||||||
| 580 | if (enabled && !JvmtiUtil::has_event_capability(event_type, get_capabilities())) { | ||||||
| 581 | return JVMTI_ERROR_MUST_POSSESS_CAPABILITY; | ||||||
| 582 | } | ||||||
| 583 | |||||||
| 584 | if (event_type == JVMTI_EVENT_CLASS_FILE_LOAD_HOOK && enabled) { | ||||||
| 585 | record_class_file_load_hook_enabled(); | ||||||
| 586 | } | ||||||
| 587 | JvmtiEventController::set_user_enabled(this, java_thread, event_type, enabled); | ||||||
| 588 | } | ||||||
| 589 | |||||||
| 590 | return JVMTI_ERROR_NONE; | ||||||
| 591 | } /* end SetEventNotificationMode */ | ||||||
| 592 | |||||||
| 593 | // | ||||||
| 594 | // Capability functions | ||||||
| 595 | // | ||||||
| 596 | |||||||
| 597 | // capabilities_ptr - pre-checked for NULL | ||||||
| 598 | jvmtiError | ||||||
| 599 | JvmtiEnv::GetPotentialCapabilities(jvmtiCapabilities* capabilities_ptr) { | ||||||
| 600 | JvmtiManageCapabilities::get_potential_capabilities(get_capabilities(), | ||||||
| 601 | get_prohibited_capabilities(), | ||||||
| 602 | capabilities_ptr); | ||||||
| 603 | return JVMTI_ERROR_NONE; | ||||||
| 604 | } /* end GetPotentialCapabilities */ | ||||||
| 605 | |||||||
| 606 | |||||||
| 607 | // capabilities_ptr - pre-checked for NULL | ||||||
| 608 | jvmtiError | ||||||
| 609 | JvmtiEnv::AddCapabilities(const jvmtiCapabilities* capabilities_ptr) { | ||||||
| 610 | return JvmtiManageCapabilities::add_capabilities(get_capabilities(), | ||||||
| 611 | get_prohibited_capabilities(), | ||||||
| 612 | capabilities_ptr, | ||||||
| 613 | get_capabilities()); | ||||||
| 614 | } /* end AddCapabilities */ | ||||||
| 615 | |||||||
| 616 | |||||||
| 617 | // capabilities_ptr - pre-checked for NULL | ||||||
| 618 | jvmtiError | ||||||
| 619 | JvmtiEnv::RelinquishCapabilities(const jvmtiCapabilities* capabilities_ptr) { | ||||||
| 620 | JvmtiManageCapabilities::relinquish_capabilities(get_capabilities(), capabilities_ptr, get_capabilities()); | ||||||
| 621 | return JVMTI_ERROR_NONE; | ||||||
| 622 | } /* end RelinquishCapabilities */ | ||||||
| 623 | |||||||
| 624 | |||||||
| 625 | // capabilities_ptr - pre-checked for NULL | ||||||
| 626 | jvmtiError | ||||||
| 627 | JvmtiEnv::GetCapabilities(jvmtiCapabilities* capabilities_ptr) { | ||||||
| 628 | JvmtiManageCapabilities::copy_capabilities(get_capabilities(), capabilities_ptr); | ||||||
| 629 | return JVMTI_ERROR_NONE; | ||||||
| 630 | } /* end GetCapabilities */ | ||||||
| 631 | |||||||
| 632 | // | ||||||
| 633 | // Class Loader Search functions | ||||||
| 634 | // | ||||||
| 635 | |||||||
| 636 | // segment - pre-checked for NULL | ||||||
| 637 | jvmtiError | ||||||
| 638 | JvmtiEnv::AddToBootstrapClassLoaderSearch(const char* segment) { | ||||||
| 639 | jvmtiPhase phase = get_phase(); | ||||||
| 640 | if (phase == JVMTI_PHASE_ONLOAD) { | ||||||
| 641 | Arguments::append_sysclasspath(segment); | ||||||
| 642 | return JVMTI_ERROR_NONE; | ||||||
| 643 | } else if (use_version_1_0_semantics()) { | ||||||
| 644 | // This JvmtiEnv requested version 1.0 semantics and this function | ||||||
| 645 | // is only allowed in the ONLOAD phase in version 1.0 so we need to | ||||||
| 646 | // return an error here. | ||||||
| 647 | return JVMTI_ERROR_WRONG_PHASE; | ||||||
| 648 | } else if (phase == JVMTI_PHASE_LIVE) { | ||||||
| 649 | // The phase is checked by the wrapper that called this function, | ||||||
| 650 | // but this thread could be racing with the thread that is | ||||||
| 651 | // terminating the VM so we check one more time. | ||||||
| 652 | |||||||
| 653 | // create the zip entry | ||||||
| 654 | ClassPathZipEntry* zip_entry = ClassLoader::create_class_path_zip_entry(segment, true); | ||||||
| 655 | if (zip_entry == NULL__null) { | ||||||
| 656 | return JVMTI_ERROR_ILLEGAL_ARGUMENT; | ||||||
| 657 | } | ||||||
| 658 | |||||||
| 659 | // add the jar file to the bootclasspath | ||||||
| 660 | log_info(class, load)(!(LogImpl<(LogTag::_class), (LogTag::_load), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::is_level(LogLevel::Info))) ? (void)0 : LogImpl<(LogTag ::_class), (LogTag::_load), (LogTag::__NO_TAG), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG)>::write<LogLevel ::Info>("opened: %s", zip_entry->name()); | ||||||
| 661 | #if INCLUDE_CDS1 | ||||||
| 662 | ClassLoaderExt::append_boot_classpath(zip_entry); | ||||||
| 663 | #else | ||||||
| 664 | ClassLoader::add_to_boot_append_entries(zip_entry); | ||||||
| 665 | #endif | ||||||
| 666 | return JVMTI_ERROR_NONE; | ||||||
| 667 | } else { | ||||||
| 668 | return JVMTI_ERROR_WRONG_PHASE; | ||||||
| 669 | } | ||||||
| 670 | |||||||
| 671 | } /* end AddToBootstrapClassLoaderSearch */ | ||||||
| 672 | |||||||
| 673 | |||||||
| 674 | // segment - pre-checked for NULL | ||||||
| 675 | jvmtiError | ||||||
| 676 | JvmtiEnv::AddToSystemClassLoaderSearch(const char* segment) { | ||||||
| 677 | jvmtiPhase phase = get_phase(); | ||||||
| 678 | |||||||
| 679 | if (phase == JVMTI_PHASE_ONLOAD) { | ||||||
| 680 | for (SystemProperty* p = Arguments::system_properties(); p != NULL__null; p = p->next()) { | ||||||
| 681 | if (strcmp("java.class.path", p->key()) == 0) { | ||||||
| 682 | p->append_value(segment); | ||||||
| 683 | break; | ||||||
| 684 | } | ||||||
| 685 | } | ||||||
| 686 | return JVMTI_ERROR_NONE; | ||||||
| 687 | } else if (phase == JVMTI_PHASE_LIVE) { | ||||||
| 688 | // The phase is checked by the wrapper that called this function, | ||||||
| 689 | // but this thread could be racing with the thread that is | ||||||
| 690 | // terminating the VM so we check one more time. | ||||||
| 691 | JavaThread* THREAD__the_thread__ = JavaThread::current(); // For exception macros. | ||||||
| 692 | HandleMark hm(THREAD__the_thread__); | ||||||
| 693 | |||||||
| 694 | // create the zip entry (which will open the zip file and hence | ||||||
| 695 | // check that the segment is indeed a zip file). | ||||||
| 696 | ClassPathZipEntry* zip_entry = ClassLoader::create_class_path_zip_entry(segment, false); | ||||||
| 697 | if (zip_entry == NULL__null) { | ||||||
| 698 | return JVMTI_ERROR_ILLEGAL_ARGUMENT; | ||||||
| 699 | } | ||||||
| 700 | delete zip_entry; // no longer needed | ||||||
| 701 | |||||||
| 702 | // lock the loader | ||||||
| 703 | Handle loader = Handle(THREAD__the_thread__, SystemDictionary::java_system_loader()); | ||||||
| 704 | ObjectLocker ol(loader, THREAD__the_thread__); | ||||||
| 705 | |||||||
| 706 | // need the path as java.lang.String | ||||||
| 707 | Handle path = java_lang_String::create_from_platform_dependent_str(segment, THREAD__the_thread__); | ||||||
| 708 | if (HAS_PENDING_EXCEPTION(((ThreadShadow*)__the_thread__)->has_pending_exception())) { | ||||||
| 709 | CLEAR_PENDING_EXCEPTION(((ThreadShadow*)__the_thread__)->clear_pending_exception( )); | ||||||
| 710 | return JVMTI_ERROR_INTERNAL; | ||||||
| 711 | } | ||||||
| 712 | |||||||
| 713 | // Invoke the appendToClassPathForInstrumentation method - if the method | ||||||
| 714 | // is not found it means the loader doesn't support adding to the class path | ||||||
| 715 | // in the live phase. | ||||||
| 716 | { | ||||||
| 717 | JavaValue res(T_VOID); | ||||||
| 718 | JavaCalls::call_special(&res, | ||||||
| 719 | loader, | ||||||
| 720 | loader->klass(), | ||||||
| 721 | vmSymbols::appendToClassPathForInstrumentation_name(), | ||||||
| 722 | vmSymbols::appendToClassPathForInstrumentation_signature(), | ||||||
| 723 | path, | ||||||
| 724 | THREAD__the_thread__); | ||||||
| 725 | if (HAS_PENDING_EXCEPTION(((ThreadShadow*)__the_thread__)->has_pending_exception())) { | ||||||
| 726 | Symbol* ex_name = PENDING_EXCEPTION(((ThreadShadow*)__the_thread__)->pending_exception())->klass()->name(); | ||||||
| 727 | CLEAR_PENDING_EXCEPTION(((ThreadShadow*)__the_thread__)->clear_pending_exception( )); | ||||||
| 728 | |||||||
| 729 | if (ex_name == vmSymbols::java_lang_NoSuchMethodError()) { | ||||||
| 730 | return JVMTI_ERROR_CLASS_LOADER_UNSUPPORTED; | ||||||
| 731 | } else { | ||||||
| 732 | return JVMTI_ERROR_INTERNAL; | ||||||
| 733 | } | ||||||
| 734 | } | ||||||
| 735 | } | ||||||
| 736 | |||||||
| 737 | return JVMTI_ERROR_NONE; | ||||||
| 738 | } else { | ||||||
| 739 | return JVMTI_ERROR_WRONG_PHASE; | ||||||
| 740 | } | ||||||
| 741 | } /* end AddToSystemClassLoaderSearch */ | ||||||
| 742 | |||||||
| 743 | // | ||||||
| 744 | // General functions | ||||||
| 745 | // | ||||||
| 746 | |||||||
| 747 | // phase_ptr - pre-checked for NULL | ||||||
| 748 | jvmtiError | ||||||
| 749 | JvmtiEnv::GetPhase(jvmtiPhase* phase_ptr) { | ||||||
| 750 | *phase_ptr = phase(); | ||||||
| 751 | return JVMTI_ERROR_NONE; | ||||||
| 752 | } /* end GetPhase */ | ||||||
| 753 | |||||||
| 754 | |||||||
| 755 | jvmtiError | ||||||
| 756 | JvmtiEnv::DisposeEnvironment() { | ||||||
| 757 | dispose(); | ||||||
| 758 | return JVMTI_ERROR_NONE; | ||||||
| 759 | } /* end DisposeEnvironment */ | ||||||
| 760 | |||||||
| 761 | |||||||
| 762 | // data - NULL is a valid value, must be checked | ||||||
| 763 | jvmtiError | ||||||
| 764 | JvmtiEnv::SetEnvironmentLocalStorage(const void* data) { | ||||||
| 765 | set_env_local_storage(data); | ||||||
| 766 | return JVMTI_ERROR_NONE; | ||||||
| 767 | } /* end SetEnvironmentLocalStorage */ | ||||||
| 768 | |||||||
| 769 | |||||||
| 770 | // data_ptr - pre-checked for NULL | ||||||
| 771 | jvmtiError | ||||||
| 772 | JvmtiEnv::GetEnvironmentLocalStorage(void** data_ptr) { | ||||||
| 773 | *data_ptr = (void*)get_env_local_storage(); | ||||||
| 774 | return JVMTI_ERROR_NONE; | ||||||
| 775 | } /* end GetEnvironmentLocalStorage */ | ||||||
| 776 | |||||||
| 777 | // version_ptr - pre-checked for NULL | ||||||
| 778 | jvmtiError | ||||||
| 779 | JvmtiEnv::GetVersionNumber(jint* version_ptr) { | ||||||
| 780 | *version_ptr = JVMTI_VERSION; | ||||||
| 781 | return JVMTI_ERROR_NONE; | ||||||
| 782 | } /* end GetVersionNumber */ | ||||||
| 783 | |||||||
| 784 | |||||||
| 785 | // name_ptr - pre-checked for NULL | ||||||
| 786 | jvmtiError | ||||||
| 787 | JvmtiEnv::GetErrorName(jvmtiError error, char** name_ptr) { | ||||||
| 788 | if (error < JVMTI_ERROR_NONE || error > JVMTI_ERROR_MAX) { | ||||||
| 789 | return JVMTI_ERROR_ILLEGAL_ARGUMENT; | ||||||
| 790 | } | ||||||
| 791 | const char *name = JvmtiUtil::error_name(error); | ||||||
| 792 | if (name == NULL__null) { | ||||||
| 793 | return JVMTI_ERROR_ILLEGAL_ARGUMENT; | ||||||
| 794 | } | ||||||
| 795 | size_t len = strlen(name) + 1; | ||||||
| 796 | jvmtiError err = allocate(len, (unsigned char**)name_ptr); | ||||||
| 797 | if (err == JVMTI_ERROR_NONE) { | ||||||
| 798 | memcpy(*name_ptr, name, len); | ||||||
| 799 | } | ||||||
| 800 | return err; | ||||||
| 801 | } /* end GetErrorName */ | ||||||
| 802 | |||||||
| 803 | |||||||
| 804 | jvmtiError | ||||||
| 805 | JvmtiEnv::SetVerboseFlag(jvmtiVerboseFlag flag, jboolean value) { | ||||||
| 806 | LogLevelType level = value == 0 ? LogLevel::Off : LogLevel::Info; | ||||||
| 807 | switch (flag) { | ||||||
| 808 | case JVMTI_VERBOSE_OTHER: | ||||||
| 809 | // ignore | ||||||
| 810 | break; | ||||||
| 811 | case JVMTI_VERBOSE_CLASS: | ||||||
| 812 | LogConfiguration::configure_stdout(level, false, LOG_TAGS(class, unload)(LogTag::_class), (LogTag::_unload), (LogTag::__NO_TAG), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG)); | ||||||
| 813 | LogConfiguration::configure_stdout(level, false, LOG_TAGS(class, load)(LogTag::_class), (LogTag::_load), (LogTag::__NO_TAG), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG)); | ||||||
| 814 | break; | ||||||
| 815 | case JVMTI_VERBOSE_GC: | ||||||
| 816 | LogConfiguration::configure_stdout(level, true, LOG_TAGS(gc)(LogTag::_gc), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG)); | ||||||
| 817 | break; | ||||||
| 818 | case JVMTI_VERBOSE_JNI: | ||||||
| 819 | level = value == 0 ? LogLevel::Off : LogLevel::Debug; | ||||||
| 820 | LogConfiguration::configure_stdout(level, true, LOG_TAGS(jni, resolve)(LogTag::_jni), (LogTag::_resolve), (LogTag::__NO_TAG), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG)); | ||||||
| 821 | break; | ||||||
| 822 | default: | ||||||
| 823 | return JVMTI_ERROR_ILLEGAL_ARGUMENT; | ||||||
| 824 | }; | ||||||
| 825 | return JVMTI_ERROR_NONE; | ||||||
| 826 | } /* end SetVerboseFlag */ | ||||||
| 827 | |||||||
| 828 | |||||||
| 829 | // format_ptr - pre-checked for NULL | ||||||
| 830 | jvmtiError | ||||||
| 831 | JvmtiEnv::GetJLocationFormat(jvmtiJlocationFormat* format_ptr) { | ||||||
| 832 | *format_ptr = JVMTI_JLOCATION_JVMBCI; | ||||||
| 833 | return JVMTI_ERROR_NONE; | ||||||
| 834 | } /* end GetJLocationFormat */ | ||||||
| 835 | |||||||
| 836 | // | ||||||
| 837 | // Thread functions | ||||||
| 838 | // | ||||||
| 839 | |||||||
| 840 | // thread - NOT protected by ThreadsListHandle and NOT pre-checked | ||||||
| 841 | // thread_state_ptr - pre-checked for NULL | ||||||
| 842 | jvmtiError | ||||||
| 843 | JvmtiEnv::GetThreadState(jthread thread, jint* thread_state_ptr) { | ||||||
| 844 | JavaThread* current_thread = JavaThread::current(); | ||||||
| 845 | JavaThread* java_thread = NULL__null; | ||||||
| 846 | oop thread_oop = NULL__null; | ||||||
| 847 | ThreadsListHandle tlh(current_thread); | ||||||
| 848 | |||||||
| 849 | if (thread == NULL__null) { | ||||||
| 850 | java_thread = current_thread; | ||||||
| 851 | thread_oop = java_thread->threadObj(); | ||||||
| 852 | |||||||
| 853 | if (thread_oop == NULL__null || !thread_oop->is_a(vmClasses::Thread_klass())) { | ||||||
| 854 | return JVMTI_ERROR_INVALID_THREAD; | ||||||
| 855 | } | ||||||
| 856 | } else { | ||||||
| 857 | jvmtiError err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, &thread_oop); | ||||||
| 858 | if (err != JVMTI_ERROR_NONE) { | ||||||
| 859 | // We got an error code so we don't have a JavaThread *, but | ||||||
| 860 | // only return an error from here if we didn't get a valid | ||||||
| 861 | // thread_oop. | ||||||
| 862 | if (thread_oop == NULL__null) { | ||||||
| 863 | return err; | ||||||
| 864 | } | ||||||
| 865 | // We have a valid thread_oop so we can return some thread state. | ||||||
| 866 | } | ||||||
| 867 | } | ||||||
| 868 | |||||||
| 869 | // get most state bits | ||||||
| 870 | jint state = (jint)java_lang_Thread::get_thread_status(thread_oop); | ||||||
| 871 | |||||||
| 872 | if (java_thread != NULL__null) { | ||||||
| 873 | // We have a JavaThread* so add more state bits. | ||||||
| 874 | JavaThreadState jts = java_thread->thread_state(); | ||||||
| 875 | |||||||
| 876 | if (java_thread->is_suspended()) { | ||||||
| 877 | state |= JVMTI_THREAD_STATE_SUSPENDED; | ||||||
| 878 | } | ||||||
| 879 | if (jts == _thread_in_native) { | ||||||
| 880 | state |= JVMTI_THREAD_STATE_IN_NATIVE; | ||||||
| 881 | } | ||||||
| 882 | if (java_thread->is_interrupted(false)) { | ||||||
| 883 | state |= JVMTI_THREAD_STATE_INTERRUPTED; | ||||||
| 884 | } | ||||||
| 885 | } | ||||||
| 886 | |||||||
| 887 | *thread_state_ptr = state; | ||||||
| 888 | return JVMTI_ERROR_NONE; | ||||||
| 889 | } /* end GetThreadState */ | ||||||
| 890 | |||||||
| 891 | |||||||
| 892 | // thread_ptr - pre-checked for NULL | ||||||
| 893 | jvmtiError | ||||||
| 894 | JvmtiEnv::GetCurrentThread(jthread* thread_ptr) { | ||||||
| 895 | JavaThread* current_thread = JavaThread::current(); | ||||||
| 896 | *thread_ptr = (jthread)JNIHandles::make_local(current_thread, current_thread->threadObj()); | ||||||
| 897 | return JVMTI_ERROR_NONE; | ||||||
| 898 | } /* end GetCurrentThread */ | ||||||
| 899 | |||||||
| 900 | |||||||
| 901 | // threads_count_ptr - pre-checked for NULL | ||||||
| 902 | // threads_ptr - pre-checked for NULL | ||||||
| 903 | jvmtiError | ||||||
| 904 | JvmtiEnv::GetAllThreads(jint* threads_count_ptr, jthread** threads_ptr) { | ||||||
| 905 | int nthreads = 0; | ||||||
| 906 | Handle *thread_objs = NULL__null; | ||||||
| 907 | Thread* current_thread = Thread::current(); | ||||||
| 908 | ResourceMark rm(current_thread); | ||||||
| 909 | HandleMark hm(current_thread); | ||||||
| 910 | |||||||
| 911 | // enumerate threads (including agent threads) | ||||||
| 912 | ThreadsListEnumerator tle(current_thread, true); | ||||||
| 913 | nthreads = tle.num_threads(); | ||||||
| 914 | *threads_count_ptr = nthreads; | ||||||
| 915 | |||||||
| 916 | if (nthreads == 0) { | ||||||
| 917 | *threads_ptr = NULL__null; | ||||||
| 918 | return JVMTI_ERROR_NONE; | ||||||
| 919 | } | ||||||
| 920 | |||||||
| 921 | thread_objs = NEW_RESOURCE_ARRAY(Handle, nthreads)(Handle*) resource_allocate_bytes((nthreads) * sizeof(Handle) ); | ||||||
| 922 | NULL_CHECK(thread_objs, JVMTI_ERROR_OUT_OF_MEMORY)if ((thread_objs) == __null) { return (JVMTI_ERROR_OUT_OF_MEMORY ); }; | ||||||
| 923 | |||||||
| 924 | for (int i = 0; i < nthreads; i++) { | ||||||
| 925 | thread_objs[i] = Handle(tle.get_threadObj(i)); | ||||||
| 926 | } | ||||||
| 927 | |||||||
| 928 | jthread *jthreads = new_jthreadArray(nthreads, thread_objs); | ||||||
| 929 | NULL_CHECK(jthreads, JVMTI_ERROR_OUT_OF_MEMORY)if ((jthreads) == __null) { return (JVMTI_ERROR_OUT_OF_MEMORY ); }; | ||||||
| 930 | |||||||
| 931 | *threads_ptr = jthreads; | ||||||
| 932 | return JVMTI_ERROR_NONE; | ||||||
| 933 | } /* end GetAllThreads */ | ||||||
| 934 | |||||||
| 935 | |||||||
| 936 | // java_thread - protected by ThreadsListHandle and pre-checked | ||||||
| 937 | jvmtiError | ||||||
| 938 | JvmtiEnv::SuspendThread(JavaThread* java_thread) { | ||||||
| 939 | // don't allow hidden thread suspend request. | ||||||
| 940 | if (java_thread->is_hidden_from_external_view()) { | ||||||
| 941 | return JVMTI_ERROR_NONE; | ||||||
| 942 | } | ||||||
| 943 | if (java_thread->is_suspended()) { | ||||||
| 944 | return JVMTI_ERROR_THREAD_SUSPENDED; | ||||||
| 945 | } | ||||||
| 946 | if (!JvmtiSuspendControl::suspend(java_thread)) { | ||||||
| 947 | // Either the thread is already suspended or | ||||||
| 948 | // it was in the process of exiting. | ||||||
| 949 | if (java_thread->is_exiting()) { | ||||||
| 950 | return JVMTI_ERROR_THREAD_NOT_ALIVE; | ||||||
| 951 | } | ||||||
| 952 | return JVMTI_ERROR_THREAD_SUSPENDED; | ||||||
| 953 | } | ||||||
| 954 | return JVMTI_ERROR_NONE; | ||||||
| 955 | } /* end SuspendThread */ | ||||||
| 956 | |||||||
| 957 | |||||||
| 958 | // request_count - pre-checked to be greater than or equal to 0 | ||||||
| 959 | // request_list - pre-checked for NULL | ||||||
| 960 | // results - pre-checked for NULL | ||||||
| 961 | jvmtiError | ||||||
| 962 | JvmtiEnv::SuspendThreadList(jint request_count, const jthread* request_list, jvmtiError* results) { | ||||||
| 963 | int self_index = -1; | ||||||
| 964 | int needSafepoint = 0; // > 0 if we need a safepoint | ||||||
| 965 | JavaThread* current = JavaThread::current(); | ||||||
| 966 | ThreadsListHandle tlh(current); | ||||||
| 967 | for (int i = 0; i < request_count; i++) { | ||||||
| 968 | JavaThread *java_thread = NULL__null; | ||||||
| 969 | jvmtiError err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), request_list[i], &java_thread, NULL__null); | ||||||
| 970 | if (err != JVMTI_ERROR_NONE) { | ||||||
| 971 | results[i] = err; | ||||||
| 972 | continue; | ||||||
| 973 | } | ||||||
| 974 | // don't allow hidden thread suspend request. | ||||||
| 975 | if (java_thread->is_hidden_from_external_view()) { | ||||||
| 976 | results[i] = JVMTI_ERROR_NONE; // indicate successful suspend | ||||||
| 977 | continue; | ||||||
| 978 | } | ||||||
| 979 | if (java_thread->is_suspended()) { | ||||||
| 980 | results[i] = JVMTI_ERROR_THREAD_SUSPENDED; | ||||||
| 981 | continue; | ||||||
| 982 | } | ||||||
| 983 | if (java_thread == current) { | ||||||
| 984 | self_index = i; | ||||||
| 985 | continue; | ||||||
| 986 | } | ||||||
| 987 | if (!JvmtiSuspendControl::suspend(java_thread)) { | ||||||
| 988 | // Either the thread is already suspended or | ||||||
| 989 | // it was in the process of exiting. | ||||||
| 990 | if (java_thread->is_exiting()) { | ||||||
| 991 | results[i] = JVMTI_ERROR_THREAD_NOT_ALIVE; | ||||||
| 992 | continue; | ||||||
| 993 | } | ||||||
| 994 | results[i] = JVMTI_ERROR_THREAD_SUSPENDED; | ||||||
| 995 | continue; | ||||||
| 996 | } | ||||||
| 997 | results[i] = JVMTI_ERROR_NONE; // indicate successful suspend | ||||||
| 998 | } | ||||||
| 999 | if (self_index >= 0) { | ||||||
| 1000 | if (!JvmtiSuspendControl::suspend(current)) { | ||||||
| 1001 | // Either the thread is already suspended or | ||||||
| 1002 | // it was in the process of exiting. | ||||||
| 1003 | if (current->is_exiting()) { | ||||||
| 1004 | results[self_index] = JVMTI_ERROR_THREAD_NOT_ALIVE; | ||||||
| 1005 | } else { | ||||||
| 1006 | results[self_index] = JVMTI_ERROR_THREAD_SUSPENDED; | ||||||
| 1007 | } | ||||||
| 1008 | } else { | ||||||
| 1009 | results[self_index] = JVMTI_ERROR_NONE; // indicate successful suspend | ||||||
| 1010 | } | ||||||
| 1011 | } | ||||||
| 1012 | // per-thread suspend results returned via results parameter | ||||||
| 1013 | return JVMTI_ERROR_NONE; | ||||||
| 1014 | } /* end SuspendThreadList */ | ||||||
| 1015 | |||||||
| 1016 | |||||||
| 1017 | // java_thread - protected by ThreadsListHandle and pre-checked | ||||||
| 1018 | jvmtiError | ||||||
| 1019 | JvmtiEnv::ResumeThread(JavaThread* java_thread) { | ||||||
| 1020 | // don't allow hidden thread resume request. | ||||||
| 1021 | if (java_thread->is_hidden_from_external_view()) { | ||||||
| 1022 | return JVMTI_ERROR_NONE; | ||||||
| 1023 | } | ||||||
| 1024 | if (!java_thread->is_suspended()) { | ||||||
| 1025 | return JVMTI_ERROR_THREAD_NOT_SUSPENDED; | ||||||
| 1026 | } | ||||||
| 1027 | if (!JvmtiSuspendControl::resume(java_thread)) { | ||||||
| 1028 | return JVMTI_ERROR_INTERNAL; | ||||||
| 1029 | } | ||||||
| 1030 | return JVMTI_ERROR_NONE; | ||||||
| 1031 | } /* end ResumeThread */ | ||||||
| 1032 | |||||||
| 1033 | |||||||
| 1034 | // request_count - pre-checked to be greater than or equal to 0 | ||||||
| 1035 | // request_list - pre-checked for NULL | ||||||
| 1036 | // results - pre-checked for NULL | ||||||
| 1037 | jvmtiError | ||||||
| 1038 | JvmtiEnv::ResumeThreadList(jint request_count, const jthread* request_list, jvmtiError* results) { | ||||||
| 1039 | ThreadsListHandle tlh; | ||||||
| 1040 | for (int i = 0; i < request_count; i++) { | ||||||
| 1041 | JavaThread* java_thread = NULL__null; | ||||||
| 1042 | jvmtiError err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), request_list[i], &java_thread, NULL__null); | ||||||
| 1043 | if (err != JVMTI_ERROR_NONE) { | ||||||
| 1044 | results[i] = err; | ||||||
| 1045 | continue; | ||||||
| 1046 | } | ||||||
| 1047 | // don't allow hidden thread resume request. | ||||||
| 1048 | if (java_thread->is_hidden_from_external_view()) { | ||||||
| 1049 | results[i] = JVMTI_ERROR_NONE; // indicate successful resume | ||||||
| 1050 | continue; | ||||||
| 1051 | } | ||||||
| 1052 | if (!java_thread->is_suspended()) { | ||||||
| 1053 | results[i] = JVMTI_ERROR_THREAD_NOT_SUSPENDED; | ||||||
| 1054 | continue; | ||||||
| 1055 | } | ||||||
| 1056 | |||||||
| 1057 | if (!JvmtiSuspendControl::resume(java_thread)) { | ||||||
| 1058 | results[i] = JVMTI_ERROR_INTERNAL; | ||||||
| 1059 | continue; | ||||||
| 1060 | } | ||||||
| 1061 | |||||||
| 1062 | results[i] = JVMTI_ERROR_NONE; // indicate successful resume | ||||||
| 1063 | } | ||||||
| 1064 | // per-thread resume results returned via results parameter | ||||||
| 1065 | return JVMTI_ERROR_NONE; | ||||||
| 1066 | } /* end ResumeThreadList */ | ||||||
| 1067 | |||||||
| 1068 | |||||||
| 1069 | // java_thread - protected by ThreadsListHandle and pre-checked | ||||||
| 1070 | jvmtiError | ||||||
| 1071 | JvmtiEnv::StopThread(JavaThread* java_thread, jobject exception) { | ||||||
| 1072 | oop e = JNIHandles::resolve_external_guard(exception); | ||||||
| 1073 | NULL_CHECK(e, JVMTI_ERROR_NULL_POINTER)if ((e) == __null) { return (JVMTI_ERROR_NULL_POINTER); }; | ||||||
| 1074 | |||||||
| 1075 | JavaThread::send_async_exception(java_thread, e); | ||||||
| 1076 | |||||||
| 1077 | return JVMTI_ERROR_NONE; | ||||||
| 1078 | |||||||
| 1079 | } /* end StopThread */ | ||||||
| 1080 | |||||||
| 1081 | |||||||
| 1082 | // thread - NOT protected by ThreadsListHandle and NOT pre-checked | ||||||
| 1083 | jvmtiError | ||||||
| 1084 | JvmtiEnv::InterruptThread(jthread thread) { | ||||||
| 1085 | JavaThread* current_thread = JavaThread::current(); | ||||||
| 1086 | JavaThread* java_thread = NULL__null; | ||||||
| 1087 | ThreadsListHandle tlh(current_thread); | ||||||
| 1088 | jvmtiError err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, NULL__null); | ||||||
| 1089 | if (err != JVMTI_ERROR_NONE) { | ||||||
| 1090 | return err; | ||||||
| 1091 | } | ||||||
| 1092 | // Really this should be a Java call to Thread.interrupt to ensure the same | ||||||
| 1093 | // semantics, however historically this has not been done for some reason. | ||||||
| 1094 | // So we continue with that (which means we don't interact with any Java-level | ||||||
| 1095 | // Interruptible object) but we must set the Java-level interrupted state. | ||||||
| 1096 | java_lang_Thread::set_interrupted(JNIHandles::resolve(thread), true); | ||||||
| 1097 | java_thread->interrupt(); | ||||||
| 1098 | |||||||
| 1099 | return JVMTI_ERROR_NONE; | ||||||
| 1100 | } /* end InterruptThread */ | ||||||
| 1101 | |||||||
| 1102 | |||||||
| 1103 | // thread - NOT protected by ThreadsListHandle and NOT pre-checked | ||||||
| 1104 | // info_ptr - pre-checked for NULL | ||||||
| 1105 | jvmtiError | ||||||
| 1106 | JvmtiEnv::GetThreadInfo(jthread thread, jvmtiThreadInfo* info_ptr) { | ||||||
| 1107 | JavaThread* current_thread = JavaThread::current(); | ||||||
| 1108 | ResourceMark rm(current_thread); | ||||||
| 1109 | HandleMark hm(current_thread); | ||||||
| 1110 | |||||||
| 1111 | ThreadsListHandle tlh(current_thread); | ||||||
| 1112 | |||||||
| 1113 | // if thread is NULL the current thread is used | ||||||
| 1114 | oop thread_oop = NULL__null; | ||||||
| 1115 | if (thread == NULL__null) { | ||||||
| 1116 | thread_oop = current_thread->threadObj(); | ||||||
| 1117 | if (thread_oop == NULL__null || !thread_oop->is_a(vmClasses::Thread_klass())) { | ||||||
| 1118 | return JVMTI_ERROR_INVALID_THREAD; | ||||||
| 1119 | } | ||||||
| 1120 | } else { | ||||||
| 1121 | JavaThread* java_thread = NULL__null; | ||||||
| 1122 | jvmtiError err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, &thread_oop); | ||||||
| 1123 | if (err != JVMTI_ERROR_NONE) { | ||||||
| 1124 | // We got an error code so we don't have a JavaThread *, but | ||||||
| 1125 | // only return an error from here if we didn't get a valid | ||||||
| 1126 | // thread_oop. | ||||||
| 1127 | if (thread_oop == NULL__null) { | ||||||
| 1128 | return err; | ||||||
| 1129 | } | ||||||
| 1130 | // We have a valid thread_oop so we can return some thread info. | ||||||
| 1131 | } | ||||||
| 1132 | } | ||||||
| 1133 | |||||||
| 1134 | Handle thread_obj(current_thread, thread_oop); | ||||||
| 1135 | Handle name; | ||||||
| 1136 | ThreadPriority priority; | ||||||
| 1137 | Handle thread_group; | ||||||
| 1138 | Handle context_class_loader; | ||||||
| 1139 | bool is_daemon; | ||||||
| 1140 | |||||||
| 1141 | name = Handle(current_thread, java_lang_Thread::name(thread_obj())); | ||||||
| 1142 | priority = java_lang_Thread::priority(thread_obj()); | ||||||
| 1143 | thread_group = Handle(current_thread, java_lang_Thread::threadGroup(thread_obj())); | ||||||
| 1144 | is_daemon = java_lang_Thread::is_daemon(thread_obj()); | ||||||
| 1145 | |||||||
| 1146 | oop loader = java_lang_Thread::context_class_loader(thread_obj()); | ||||||
| 1147 | context_class_loader = Handle(current_thread, loader); | ||||||
| 1148 | |||||||
| 1149 | { const char *n; | ||||||
| 1150 | |||||||
| 1151 | if (name() != NULL__null) { | ||||||
| 1152 | n = java_lang_String::as_utf8_string(name()); | ||||||
| 1153 | } else { | ||||||
| 1154 | int utf8_length = 0; | ||||||
| 1155 | n = UNICODE::as_utf8((jchar*) NULL__null, utf8_length); | ||||||
| 1156 | } | ||||||
| 1157 | |||||||
| 1158 | info_ptr->name = (char *) jvmtiMalloc(strlen(n)+1); | ||||||
| 1159 | if (info_ptr->name == NULL__null) | ||||||
| 1160 | return JVMTI_ERROR_OUT_OF_MEMORY; | ||||||
| 1161 | |||||||
| 1162 | strcpy(info_ptr->name, n); | ||||||
| 1163 | } | ||||||
| 1164 | info_ptr->is_daemon = is_daemon; | ||||||
| 1165 | info_ptr->priority = priority; | ||||||
| 1166 | |||||||
| 1167 | info_ptr->context_class_loader = (context_class_loader.is_null()) ? NULL__null : | ||||||
| 1168 | jni_reference(context_class_loader); | ||||||
| 1169 | info_ptr->thread_group = jni_reference(thread_group); | ||||||
| 1170 | |||||||
| 1171 | return JVMTI_ERROR_NONE; | ||||||
| 1172 | } /* end GetThreadInfo */ | ||||||
| 1173 | |||||||
| 1174 | |||||||
| 1175 | // java_thread - protected by ThreadsListHandle and pre-checked | ||||||
| 1176 | // owned_monitor_count_ptr - pre-checked for NULL | ||||||
| 1177 | // owned_monitors_ptr - pre-checked for NULL | ||||||
| 1178 | jvmtiError | ||||||
| 1179 | JvmtiEnv::GetOwnedMonitorInfo(JavaThread* java_thread, jint* owned_monitor_count_ptr, jobject** owned_monitors_ptr) { | ||||||
| 1180 | jvmtiError err = JVMTI_ERROR_NONE; | ||||||
| 1181 | JavaThread* calling_thread = JavaThread::current(); | ||||||
| 1182 | |||||||
| 1183 | EscapeBarrier eb(true, calling_thread, java_thread); | ||||||
| 1184 | if (!eb.deoptimize_objects(MaxJavaStackTraceDepth)) { | ||||||
| 1185 | return JVMTI_ERROR_OUT_OF_MEMORY; | ||||||
| 1186 | } | ||||||
| 1187 | |||||||
| 1188 | // growable array of jvmti monitors info on the C-heap | ||||||
| 1189 | GrowableArray<jvmtiMonitorStackDepthInfo*> *owned_monitors_list = | ||||||
| 1190 | new (ResourceObj::C_HEAP, mtServiceability) GrowableArray<jvmtiMonitorStackDepthInfo*>(1, mtServiceability); | ||||||
| 1191 | |||||||
| 1192 | // It is only safe to perform the direct operation on the current | ||||||
| 1193 | // thread. All other usage needs to use a direct handshake for safety. | ||||||
| 1194 | if (java_thread == calling_thread) { | ||||||
| 1195 | err = get_owned_monitors(calling_thread, java_thread, owned_monitors_list); | ||||||
| 1196 | } else { | ||||||
| 1197 | // get owned monitors info with handshake | ||||||
| 1198 | GetOwnedMonitorInfoClosure op(calling_thread, this, owned_monitors_list); | ||||||
| 1199 | Handshake::execute(&op, java_thread); | ||||||
| 1200 | err = op.result(); | ||||||
| 1201 | } | ||||||
| 1202 | jint owned_monitor_count = owned_monitors_list->length(); | ||||||
| 1203 | if (err == JVMTI_ERROR_NONE) { | ||||||
| 1204 | if ((err = allocate(owned_monitor_count * sizeof(jobject *), | ||||||
| 1205 | (unsigned char**)owned_monitors_ptr)) == JVMTI_ERROR_NONE) { | ||||||
| 1206 | // copy into the returned array | ||||||
| 1207 | for (int i = 0; i < owned_monitor_count; i++) { | ||||||
| 1208 | (*owned_monitors_ptr)[i] = | ||||||
| 1209 | ((jvmtiMonitorStackDepthInfo*)owned_monitors_list->at(i))->monitor; | ||||||
| 1210 | } | ||||||
| 1211 | *owned_monitor_count_ptr = owned_monitor_count; | ||||||
| 1212 | } | ||||||
| 1213 | } | ||||||
| 1214 | // clean up. | ||||||
| 1215 | for (int i = 0; i < owned_monitor_count; i++) { | ||||||
| 1216 | deallocate((unsigned char*)owned_monitors_list->at(i)); | ||||||
| 1217 | } | ||||||
| 1218 | delete owned_monitors_list; | ||||||
| 1219 | |||||||
| 1220 | return err; | ||||||
| 1221 | } /* end GetOwnedMonitorInfo */ | ||||||
| 1222 | |||||||
| 1223 | |||||||
| 1224 | // java_thread - protected by ThreadsListHandle and pre-checked | ||||||
| 1225 | // monitor_info_count_ptr - pre-checked for NULL | ||||||
| 1226 | // monitor_info_ptr - pre-checked for NULL | ||||||
| 1227 | jvmtiError | ||||||
| 1228 | JvmtiEnv::GetOwnedMonitorStackDepthInfo(JavaThread* java_thread, jint* monitor_info_count_ptr, jvmtiMonitorStackDepthInfo** monitor_info_ptr) { | ||||||
| 1229 | jvmtiError err = JVMTI_ERROR_NONE; | ||||||
| 1230 | JavaThread* calling_thread = JavaThread::current(); | ||||||
| 1231 | |||||||
| 1232 | EscapeBarrier eb(true, calling_thread, java_thread); | ||||||
| 1233 | if (!eb.deoptimize_objects(MaxJavaStackTraceDepth)) { | ||||||
| 1234 | return JVMTI_ERROR_OUT_OF_MEMORY; | ||||||
| 1235 | } | ||||||
| 1236 | |||||||
| 1237 | // growable array of jvmti monitors info on the C-heap | ||||||
| 1238 | GrowableArray<jvmtiMonitorStackDepthInfo*> *owned_monitors_list = | ||||||
| 1239 | new (ResourceObj::C_HEAP, mtServiceability) GrowableArray<jvmtiMonitorStackDepthInfo*>(1, mtServiceability); | ||||||
| 1240 | |||||||
| 1241 | // It is only safe to perform the direct operation on the current | ||||||
| 1242 | // thread. All other usage needs to use a direct handshake for safety. | ||||||
| 1243 | if (java_thread == calling_thread) { | ||||||
| 1244 | err = get_owned_monitors(calling_thread, java_thread, owned_monitors_list); | ||||||
| 1245 | } else { | ||||||
| 1246 | // get owned monitors info with handshake | ||||||
| 1247 | GetOwnedMonitorInfoClosure op(calling_thread, this, owned_monitors_list); | ||||||
| 1248 | Handshake::execute(&op, java_thread); | ||||||
| 1249 | err = op.result(); | ||||||
| 1250 | } | ||||||
| 1251 | |||||||
| 1252 | jint owned_monitor_count = owned_monitors_list->length(); | ||||||
| 1253 | if (err == JVMTI_ERROR_NONE) { | ||||||
| 1254 | if ((err = allocate(owned_monitor_count * sizeof(jvmtiMonitorStackDepthInfo), | ||||||
| 1255 | (unsigned char**)monitor_info_ptr)) == JVMTI_ERROR_NONE) { | ||||||
| 1256 | // copy to output array. | ||||||
| 1257 | for (int i = 0; i < owned_monitor_count; i++) { | ||||||
| 1258 | (*monitor_info_ptr)[i].monitor = | ||||||
| 1259 | ((jvmtiMonitorStackDepthInfo*)owned_monitors_list->at(i))->monitor; | ||||||
| 1260 | (*monitor_info_ptr)[i].stack_depth = | ||||||
| 1261 | ((jvmtiMonitorStackDepthInfo*)owned_monitors_list->at(i))->stack_depth; | ||||||
| 1262 | } | ||||||
| 1263 | } | ||||||
| 1264 | *monitor_info_count_ptr = owned_monitor_count; | ||||||
| 1265 | } | ||||||
| 1266 | |||||||
| 1267 | // clean up. | ||||||
| 1268 | for (int i = 0; i < owned_monitor_count; i++) { | ||||||
| 1269 | deallocate((unsigned char*)owned_monitors_list->at(i)); | ||||||
| 1270 | } | ||||||
| 1271 | delete owned_monitors_list; | ||||||
| 1272 | |||||||
| 1273 | return err; | ||||||
| 1274 | } /* end GetOwnedMonitorStackDepthInfo */ | ||||||
| 1275 | |||||||
| 1276 | |||||||
| 1277 | // java_thread - protected by ThreadsListHandle and pre-checked | ||||||
| 1278 | // monitor_ptr - pre-checked for NULL | ||||||
| 1279 | jvmtiError | ||||||
| 1280 | JvmtiEnv::GetCurrentContendedMonitor(JavaThread* java_thread, jobject* monitor_ptr) { | ||||||
| 1281 | jvmtiError err = JVMTI_ERROR_NONE; | ||||||
| 1282 | JavaThread* calling_thread = JavaThread::current(); | ||||||
| 1283 | |||||||
| 1284 | // It is only safe to perform the direct operation on the current | ||||||
| 1285 | // thread. All other usage needs to use a direct handshake for safety. | ||||||
| 1286 | if (java_thread == calling_thread) { | ||||||
| 1287 | err = get_current_contended_monitor(calling_thread, java_thread, monitor_ptr); | ||||||
| 1288 | } else { | ||||||
| 1289 | // get contended monitor information with handshake | ||||||
| 1290 | GetCurrentContendedMonitorClosure op(calling_thread, this, monitor_ptr); | ||||||
| 1291 | Handshake::execute(&op, java_thread); | ||||||
| 1292 | err = op.result(); | ||||||
| 1293 | } | ||||||
| 1294 | return err; | ||||||
| 1295 | } /* end GetCurrentContendedMonitor */ | ||||||
| 1296 | |||||||
| 1297 | |||||||
| 1298 | // thread - NOT protected by ThreadsListHandle and NOT pre-checked | ||||||
| 1299 | // proc - pre-checked for NULL | ||||||
| 1300 | // arg - NULL is a valid value, must be checked | ||||||
| 1301 | jvmtiError | ||||||
| 1302 | JvmtiEnv::RunAgentThread(jthread thread, jvmtiStartFunction proc, const void* arg, jint priority) { | ||||||
| 1303 | JavaThread* current_thread = JavaThread::current(); | ||||||
| 1304 | |||||||
| 1305 | JavaThread* java_thread = NULL__null; | ||||||
| 1306 | oop thread_oop = NULL__null; | ||||||
| 1307 | ThreadsListHandle tlh(current_thread); | ||||||
| 1308 | jvmtiError err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), thread, &java_thread, &thread_oop); | ||||||
| 1309 | if (err != JVMTI_ERROR_NONE) { | ||||||
| 1310 | // We got an error code so we don't have a JavaThread *, but | ||||||
| 1311 | // only return an error from here if we didn't get a valid | ||||||
| 1312 | // thread_oop. | ||||||
| 1313 | if (thread_oop == NULL__null) { | ||||||
| 1314 | return err; | ||||||
| 1315 | } | ||||||
| 1316 | // We have a valid thread_oop. | ||||||
| 1317 | } | ||||||
| 1318 | |||||||
| 1319 | if (java_thread != NULL__null) { | ||||||
| 1320 | // 'thread' refers to an existing JavaThread. | ||||||
| 1321 | return JVMTI_ERROR_INVALID_THREAD; | ||||||
| 1322 | } | ||||||
| 1323 | |||||||
| 1324 | if (priority < JVMTI_THREAD_MIN_PRIORITY || priority > JVMTI_THREAD_MAX_PRIORITY) { | ||||||
| 1325 | return JVMTI_ERROR_INVALID_PRIORITY; | ||||||
| 1326 | } | ||||||
| 1327 | |||||||
| 1328 | Handle thread_hndl(current_thread, thread_oop); | ||||||
| 1329 | |||||||
| 1330 | JvmtiAgentThread* new_thread = new JvmtiAgentThread(this, proc, arg); | ||||||
| 1331 | |||||||
| 1332 | // At this point it may be possible that no osthread was created for the | ||||||
| 1333 | // JavaThread due to lack of resources. | ||||||
| 1334 | if (new_thread->osthread() == NULL__null) { | ||||||
| 1335 | // The new thread is not known to Thread-SMR yet so we can just delete. | ||||||
| 1336 | delete new_thread; | ||||||
| 1337 | return JVMTI_ERROR_OUT_OF_MEMORY; | ||||||
| 1338 | } | ||||||
| 1339 | |||||||
| 1340 | JavaThread::start_internal_daemon(current_thread, new_thread, thread_hndl, | ||||||
| 1341 | (ThreadPriority)priority); | ||||||
| 1342 | |||||||
| 1343 | return JVMTI_ERROR_NONE; | ||||||
| 1344 | } /* end RunAgentThread */ | ||||||
| 1345 | |||||||
| 1346 | // | ||||||
| 1347 | // Thread Group functions | ||||||
| 1348 | // | ||||||
| 1349 | |||||||
| 1350 | // group_count_ptr - pre-checked for NULL | ||||||
| 1351 | // groups_ptr - pre-checked for NULL | ||||||
| 1352 | jvmtiError | ||||||
| 1353 | JvmtiEnv::GetTopThreadGroups(jint* group_count_ptr, jthreadGroup** groups_ptr) { | ||||||
| 1354 | JavaThread* current_thread = JavaThread::current(); | ||||||
| 1355 | |||||||
| 1356 | // Only one top level thread group now. | ||||||
| 1357 | *group_count_ptr = 1; | ||||||
| 1358 | |||||||
| 1359 | // Allocate memory to store global-refs to the thread groups. | ||||||
| 1360 | // Assume this area is freed by caller. | ||||||
| 1361 | *groups_ptr = (jthreadGroup *) jvmtiMalloc((sizeof(jthreadGroup)) * (*group_count_ptr)); | ||||||
| 1362 | |||||||
| 1363 | NULL_CHECK(*groups_ptr, JVMTI_ERROR_OUT_OF_MEMORY)if ((*groups_ptr) == __null) { return (JVMTI_ERROR_OUT_OF_MEMORY ); }; | ||||||
| 1364 | |||||||
| 1365 | // Convert oop to Handle, then convert Handle to global-ref. | ||||||
| 1366 | { | ||||||
| 1367 | HandleMark hm(current_thread); | ||||||
| 1368 | Handle system_thread_group(current_thread, Universe::system_thread_group()); | ||||||
| 1369 | *groups_ptr[0] = jni_reference(system_thread_group); | ||||||
| 1370 | } | ||||||
| 1371 | |||||||
| 1372 | return JVMTI_ERROR_NONE; | ||||||
| 1373 | } /* end GetTopThreadGroups */ | ||||||
| 1374 | |||||||
| 1375 | |||||||
| 1376 | // info_ptr - pre-checked for NULL | ||||||
| 1377 | jvmtiError | ||||||
| 1378 | JvmtiEnv::GetThreadGroupInfo(jthreadGroup group, jvmtiThreadGroupInfo* info_ptr) { | ||||||
| 1379 | Thread* current_thread = Thread::current(); | ||||||
| 1380 | ResourceMark rm(current_thread); | ||||||
| 1381 | HandleMark hm(current_thread); | ||||||
| 1382 | |||||||
| 1383 | Handle group_obj (current_thread, JNIHandles::resolve_external_guard(group)); | ||||||
| 1384 | NULL_CHECK(group_obj(), JVMTI_ERROR_INVALID_THREAD_GROUP)if ((group_obj()) == __null) { return (JVMTI_ERROR_INVALID_THREAD_GROUP ); }; | ||||||
| 1385 | |||||||
| 1386 | const char* name; | ||||||
| 1387 | Handle parent_group; | ||||||
| 1388 | bool is_daemon; | ||||||
| 1389 | ThreadPriority max_priority; | ||||||
| 1390 | |||||||
| 1391 | name = java_lang_ThreadGroup::name(group_obj()); | ||||||
| 1392 | parent_group = Handle(current_thread, java_lang_ThreadGroup::parent(group_obj())); | ||||||
| 1393 | is_daemon = java_lang_ThreadGroup::is_daemon(group_obj()); | ||||||
| 1394 | max_priority = java_lang_ThreadGroup::maxPriority(group_obj()); | ||||||
| 1395 | |||||||
| 1396 | info_ptr->is_daemon = is_daemon; | ||||||
| 1397 | info_ptr->max_priority = max_priority; | ||||||
| 1398 | info_ptr->parent = jni_reference(parent_group); | ||||||
| 1399 | |||||||
| 1400 | if (name != NULL__null) { | ||||||
| 1401 | info_ptr->name = (char*)jvmtiMalloc(strlen(name)+1); | ||||||
| 1402 | NULL_CHECK(info_ptr->name, JVMTI_ERROR_OUT_OF_MEMORY)if ((info_ptr->name) == __null) { return (JVMTI_ERROR_OUT_OF_MEMORY ); }; | ||||||
| 1403 | strcpy(info_ptr->name, name); | ||||||
| 1404 | } else { | ||||||
| 1405 | info_ptr->name = NULL__null; | ||||||
| 1406 | } | ||||||
| 1407 | |||||||
| 1408 | return JVMTI_ERROR_NONE; | ||||||
| 1409 | } /* end GetThreadGroupInfo */ | ||||||
| 1410 | |||||||
| 1411 | |||||||
| 1412 | // thread_count_ptr - pre-checked for NULL | ||||||
| 1413 | // threads_ptr - pre-checked for NULL | ||||||
| 1414 | // group_count_ptr - pre-checked for NULL | ||||||
| 1415 | // groups_ptr - pre-checked for NULL | ||||||
| 1416 | jvmtiError | ||||||
| 1417 | JvmtiEnv::GetThreadGroupChildren(jthreadGroup group, jint* thread_count_ptr, jthread** threads_ptr, jint* group_count_ptr, jthreadGroup** groups_ptr) { | ||||||
| 1418 | JavaThread* current_thread = JavaThread::current(); | ||||||
| 1419 | oop group_obj = JNIHandles::resolve_external_guard(group); | ||||||
| 1420 | NULL_CHECK(group_obj, JVMTI_ERROR_INVALID_THREAD_GROUP)if ((group_obj) == __null) { return (JVMTI_ERROR_INVALID_THREAD_GROUP ); }; | ||||||
| 1421 | |||||||
| 1422 | Handle *thread_objs = NULL__null; | ||||||
| 1423 | Handle *group_objs = NULL__null; | ||||||
| 1424 | int nthreads = 0; | ||||||
| 1425 | int ngroups = 0; | ||||||
| 1426 | int hidden_threads = 0; | ||||||
| 1427 | |||||||
| 1428 | ResourceMark rm(current_thread); | ||||||
| 1429 | HandleMark hm(current_thread); | ||||||
| 1430 | |||||||
| 1431 | Handle group_hdl(current_thread, group_obj); | ||||||
| 1432 | |||||||
| 1433 | { // Cannot allow thread or group counts to change. | ||||||
| 1434 | ObjectLocker ol(group_hdl, current_thread); | ||||||
| 1435 | |||||||
| 1436 | nthreads = java_lang_ThreadGroup::nthreads(group_hdl()); | ||||||
| 1437 | ngroups = java_lang_ThreadGroup::ngroups(group_hdl()); | ||||||
| 1438 | |||||||
| 1439 | if (nthreads > 0) { | ||||||
| 1440 | ThreadsListHandle tlh(current_thread); | ||||||
| 1441 | objArrayOop threads = java_lang_ThreadGroup::threads(group_hdl()); | ||||||
| 1442 | assert(nthreads <= threads->length(), "too many threads")do { if (!(nthreads <= threads->length())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/prims/jvmtiEnv.cpp" , 1442, "assert(" "nthreads <= threads->length()" ") failed" , "too many threads"); ::breakpoint(); } } while (0); | ||||||
| 1443 | thread_objs = NEW_RESOURCE_ARRAY(Handle,nthreads)(Handle*) resource_allocate_bytes((nthreads) * sizeof(Handle) ); | ||||||
| 1444 | for (int i = 0, j = 0; i < nthreads; i++) { | ||||||
| 1445 | oop thread_obj = threads->obj_at(i); | ||||||
| 1446 | assert(thread_obj != NULL, "thread_obj is NULL")do { if (!(thread_obj != __null)) { (*g_assert_poison) = 'X'; ; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/prims/jvmtiEnv.cpp" , 1446, "assert(" "thread_obj != __null" ") failed", "thread_obj is NULL" ); ::breakpoint(); } } while (0); | ||||||
| 1447 | JavaThread *java_thread = NULL__null; | ||||||
| 1448 | jvmtiError err = JvmtiExport::cv_oop_to_JavaThread(tlh.list(), thread_obj, &java_thread); | ||||||
| 1449 | if (err == JVMTI_ERROR_NONE) { | ||||||
| 1450 | // Have a valid JavaThread*. | ||||||
| 1451 | if (java_thread->is_hidden_from_external_view()) { | ||||||
| 1452 | // Filter out hidden java threads. | ||||||
| 1453 | hidden_threads++; | ||||||
| 1454 | continue; | ||||||
| 1455 | } | ||||||
| 1456 | } else { | ||||||
| 1457 | // We couldn't convert thread_obj into a JavaThread*. | ||||||
| 1458 | if (err == JVMTI_ERROR_INVALID_THREAD) { | ||||||
| 1459 | // The thread_obj does not refer to a java.lang.Thread object | ||||||
| 1460 | // so skip it. | ||||||
| 1461 | hidden_threads++; | ||||||
| 1462 | continue; | ||||||
| 1463 | } | ||||||
| 1464 | // We have a valid thread_obj, but no JavaThread*; the caller | ||||||
| 1465 | // can still have limited use for the thread_obj. | ||||||
| 1466 | } | ||||||
| 1467 | thread_objs[j++] = Handle(current_thread, thread_obj); | ||||||
| 1468 | } | ||||||
| 1469 | nthreads -= hidden_threads; | ||||||
| 1470 | } // ThreadsListHandle is destroyed here. | ||||||
| 1471 | |||||||
| 1472 | if (ngroups > 0) { | ||||||
| 1473 | objArrayOop groups = java_lang_ThreadGroup::groups(group_hdl()); | ||||||
| 1474 | assert(ngroups <= groups->length(), "too many groups")do { if (!(ngroups <= groups->length())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/prims/jvmtiEnv.cpp" , 1474, "assert(" "ngroups <= groups->length()" ") failed" , "too many groups"); ::breakpoint(); } } while (0); | ||||||
| 1475 | group_objs = NEW_RESOURCE_ARRAY(Handle,ngroups)(Handle*) resource_allocate_bytes((ngroups) * sizeof(Handle)); | ||||||
| 1476 | for (int i = 0; i < ngroups; i++) { | ||||||
| 1477 | oop group_obj = groups->obj_at(i); | ||||||
| 1478 | assert(group_obj != NULL, "group_obj != NULL")do { if (!(group_obj != __null)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/prims/jvmtiEnv.cpp" , 1478, "assert(" "group_obj != __null" ") failed", "group_obj != NULL" ); ::breakpoint(); } } while (0); | ||||||
| 1479 | group_objs[i] = Handle(current_thread, group_obj); | ||||||
| 1480 | } | ||||||
| 1481 | } | ||||||
| 1482 | } // ThreadGroup unlocked here | ||||||
| 1483 | |||||||
| 1484 | *group_count_ptr = ngroups; | ||||||
| 1485 | *thread_count_ptr = nthreads; | ||||||
| 1486 | *threads_ptr = new_jthreadArray(nthreads, thread_objs); | ||||||
| 1487 | *groups_ptr = new_jthreadGroupArray(ngroups, group_objs); | ||||||
| 1488 | if ((nthreads > 0) && (*threads_ptr == NULL__null)) { | ||||||
| 1489 | return JVMTI_ERROR_OUT_OF_MEMORY; | ||||||
| 1490 | } | ||||||
| 1491 | if ((ngroups > 0) && (*groups_ptr == NULL__null)) { | ||||||
| 1492 | return JVMTI_ERROR_OUT_OF_MEMORY; | ||||||
| 1493 | } | ||||||
| 1494 | |||||||
| 1495 | return JVMTI_ERROR_NONE; | ||||||
| 1496 | } /* end GetThreadGroupChildren */ | ||||||
| 1497 | |||||||
| 1498 | |||||||
| 1499 | // | ||||||
| 1500 | // Stack Frame functions | ||||||
| 1501 | // | ||||||
| 1502 | |||||||
| 1503 | // java_thread - protected by ThreadsListHandle and pre-checked | ||||||
| 1504 | // max_frame_count - pre-checked to be greater than or equal to 0 | ||||||
| 1505 | // frame_buffer - pre-checked for NULL | ||||||
| 1506 | // count_ptr - pre-checked for NULL | ||||||
| 1507 | jvmtiError | ||||||
| 1508 | JvmtiEnv::GetStackTrace(JavaThread* java_thread, jint start_depth, jint max_frame_count, jvmtiFrameInfo* frame_buffer, jint* count_ptr) { | ||||||
| 1509 | jvmtiError err = JVMTI_ERROR_NONE; | ||||||
| 1510 | |||||||
| 1511 | // It is only safe to perform the direct operation on the current | ||||||
| 1512 | // thread. All other usage needs to use a direct handshake for safety. | ||||||
| 1513 | if (java_thread == JavaThread::current()) { | ||||||
| 1514 | err = get_stack_trace(java_thread, start_depth, max_frame_count, frame_buffer, count_ptr); | ||||||
| 1515 | } else { | ||||||
| 1516 | // Get stack trace with handshake. | ||||||
| 1517 | GetStackTraceClosure op(this, start_depth, max_frame_count, frame_buffer, count_ptr); | ||||||
| 1518 | Handshake::execute(&op, java_thread); | ||||||
| 1519 | err = op.result(); | ||||||
| 1520 | } | ||||||
| 1521 | |||||||
| 1522 | return err; | ||||||
| 1523 | } /* end GetStackTrace */ | ||||||
| 1524 | |||||||
| 1525 | |||||||
| 1526 | // max_frame_count - pre-checked to be greater than or equal to 0 | ||||||
| 1527 | // stack_info_ptr - pre-checked for NULL | ||||||
| 1528 | // thread_count_ptr - pre-checked for NULL | ||||||
| 1529 | jvmtiError | ||||||
| 1530 | JvmtiEnv::GetAllStackTraces(jint max_frame_count, jvmtiStackInfo** stack_info_ptr, jint* thread_count_ptr) { | ||||||
| 1531 | jvmtiError err = JVMTI_ERROR_NONE; | ||||||
| 1532 | JavaThread* calling_thread = JavaThread::current(); | ||||||
| 1533 | |||||||
| 1534 | // JVMTI get stack traces at safepoint. | ||||||
| 1535 | VM_GetAllStackTraces op(this, calling_thread, max_frame_count); | ||||||
| 1536 | VMThread::execute(&op); | ||||||
| 1537 | *thread_count_ptr = op.final_thread_count(); | ||||||
| 1538 | *stack_info_ptr = op.stack_info(); | ||||||
| 1539 | err = op.result(); | ||||||
| 1540 | return err; | ||||||
| 1541 | } /* end GetAllStackTraces */ | ||||||
| 1542 | |||||||
| 1543 | |||||||
| 1544 | // thread_count - pre-checked to be greater than or equal to 0 | ||||||
| 1545 | // thread_list - pre-checked for NULL | ||||||
| 1546 | // max_frame_count - pre-checked to be greater than or equal to 0 | ||||||
| 1547 | // stack_info_ptr - pre-checked for NULL | ||||||
| 1548 | jvmtiError | ||||||
| 1549 | JvmtiEnv::GetThreadListStackTraces(jint thread_count, const jthread* thread_list, jint max_frame_count, jvmtiStackInfo** stack_info_ptr) { | ||||||
| 1550 | jvmtiError err = JVMTI_ERROR_NONE; | ||||||
| 1551 | |||||||
| 1552 | if (thread_count == 1) { | ||||||
| 1553 | // Use direct handshake if we need to get only one stack trace. | ||||||
| 1554 | JavaThread *current_thread = JavaThread::current(); | ||||||
| 1555 | ThreadsListHandle tlh(current_thread); | ||||||
| 1556 | JavaThread *java_thread; | ||||||
| 1557 | err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), *thread_list, &java_thread, NULL__null); | ||||||
| 1558 | if (err != JVMTI_ERROR_NONE) { | ||||||
| 1559 | return err; | ||||||
| 1560 | } | ||||||
| 1561 | |||||||
| 1562 | GetSingleStackTraceClosure op(this, current_thread, *thread_list, max_frame_count); | ||||||
| 1563 | Handshake::execute(&op, &tlh, java_thread); | ||||||
| 1564 | err = op.result(); | ||||||
| 1565 | if (err == JVMTI_ERROR_NONE) { | ||||||
| 1566 | *stack_info_ptr = op.stack_info(); | ||||||
| 1567 | } | ||||||
| 1568 | } else { | ||||||
| 1569 | // JVMTI get stack traces at safepoint. | ||||||
| 1570 | VM_GetThreadListStackTraces op(this, thread_count, thread_list, max_frame_count); | ||||||
| 1571 | VMThread::execute(&op); | ||||||
| 1572 | err = op.result(); | ||||||
| 1573 | if (err == JVMTI_ERROR_NONE) { | ||||||
| 1574 | *stack_info_ptr = op.stack_info(); | ||||||
| 1575 | } | ||||||
| 1576 | } | ||||||
| 1577 | return err; | ||||||
| 1578 | } /* end GetThreadListStackTraces */ | ||||||
| 1579 | |||||||
| 1580 | |||||||
| 1581 | // java_thread - protected by ThreadsListHandle and pre-checked | ||||||
| 1582 | // count_ptr - pre-checked for NULL | ||||||
| 1583 | jvmtiError | ||||||
| 1584 | JvmtiEnv::GetFrameCount(JavaThread* java_thread, jint* count_ptr) { | ||||||
| 1585 | jvmtiError err = JVMTI_ERROR_NONE; | ||||||
| 1586 | |||||||
| 1587 | // retrieve or create JvmtiThreadState. | ||||||
| 1588 | JvmtiThreadState* state = JvmtiThreadState::state_for(java_thread); | ||||||
| 1589 | if (state == NULL__null) { | ||||||
| 1590 | return JVMTI_ERROR_THREAD_NOT_ALIVE; | ||||||
| 1591 | } | ||||||
| 1592 | |||||||
| 1593 | // It is only safe to perform the direct operation on the current | ||||||
| 1594 | // thread. All other usage needs to use a direct handshake for safety. | ||||||
| 1595 | if (java_thread == JavaThread::current()) { | ||||||
| 1596 | err = get_frame_count(state, count_ptr); | ||||||
| 1597 | } else { | ||||||
| 1598 | // get java stack frame count with handshake. | ||||||
| 1599 | GetFrameCountClosure op(this, state, count_ptr); | ||||||
| 1600 | Handshake::execute(&op, java_thread); | ||||||
| 1601 | err = op.result(); | ||||||
| 1602 | } | ||||||
| 1603 | return err; | ||||||
| 1604 | } /* end GetFrameCount */ | ||||||
| 1605 | |||||||
| 1606 | |||||||
| 1607 | // java_thread - protected by ThreadsListHandle and pre-checked | ||||||
| 1608 | jvmtiError | ||||||
| 1609 | JvmtiEnv::PopFrame(JavaThread* java_thread) { | ||||||
| 1610 | // retrieve or create the state | ||||||
| 1611 | JvmtiThreadState* state = JvmtiThreadState::state_for(java_thread); | ||||||
| 1612 | if (state == NULL__null) { | ||||||
| 1613 | return JVMTI_ERROR_THREAD_NOT_ALIVE; | ||||||
| 1614 | } | ||||||
| 1615 | |||||||
| 1616 | // Eagerly reallocate scalar replaced objects. | ||||||
| 1617 | JavaThread* current_thread = JavaThread::current(); | ||||||
| 1618 | EscapeBarrier eb(true, current_thread, java_thread); | ||||||
| 1619 | if (!eb.deoptimize_objects(1)) { | ||||||
| 1620 | // Reallocation of scalar replaced objects failed -> return with error | ||||||
| 1621 | return JVMTI_ERROR_OUT_OF_MEMORY; | ||||||
| 1622 | } | ||||||
| 1623 | |||||||
| 1624 | MutexLocker mu(JvmtiThreadState_lock); | ||||||
| 1625 | UpdateForPopTopFrameClosure op(state); | ||||||
| 1626 | if (java_thread == current_thread) { | ||||||
| 1627 | op.doit(java_thread, true /* self */); | ||||||
| 1628 | } else { | ||||||
| 1629 | Handshake::execute(&op, java_thread); | ||||||
| 1630 | } | ||||||
| 1631 | return op.result(); | ||||||
| 1632 | } /* end PopFrame */ | ||||||
| 1633 | |||||||
| 1634 | |||||||
| 1635 | // java_thread - protected by ThreadsListHandle and pre-checked | ||||||
| 1636 | // depth - pre-checked as non-negative | ||||||
| 1637 | // method_ptr - pre-checked for NULL | ||||||
| 1638 | // location_ptr - pre-checked for NULL | ||||||
| 1639 | jvmtiError | ||||||
| 1640 | JvmtiEnv::GetFrameLocation(JavaThread* java_thread, jint depth, jmethodID* method_ptr, jlocation* location_ptr) { | ||||||
| 1641 | jvmtiError err = JVMTI_ERROR_NONE; | ||||||
| 1642 | |||||||
| 1643 | // It is only safe to perform the direct operation on the current | ||||||
| 1644 | // thread. All other usage needs to use a direct handshake for safety. | ||||||
| 1645 | if (java_thread == JavaThread::current()) { | ||||||
| 1646 | err = get_frame_location(java_thread, depth, method_ptr, location_ptr); | ||||||
| 1647 | } else { | ||||||
| 1648 | // JVMTI get java stack frame location via direct handshake. | ||||||
| 1649 | GetFrameLocationClosure op(this, depth, method_ptr, location_ptr); | ||||||
| 1650 | Handshake::execute(&op, java_thread); | ||||||
| 1651 | err = op.result(); | ||||||
| 1652 | } | ||||||
| 1653 | return err; | ||||||
| 1654 | } /* end GetFrameLocation */ | ||||||
| 1655 | |||||||
| 1656 | |||||||
| 1657 | // java_thread - protected by ThreadsListHandle and pre-checked | ||||||
| 1658 | // depth - pre-checked as non-negative | ||||||
| 1659 | jvmtiError | ||||||
| 1660 | JvmtiEnv::NotifyFramePop(JavaThread* java_thread, jint depth) { | ||||||
| 1661 | JvmtiThreadState *state = JvmtiThreadState::state_for(java_thread); | ||||||
| 1662 | if (state == NULL__null) { | ||||||
| 1663 | return JVMTI_ERROR_THREAD_NOT_ALIVE; | ||||||
| 1664 | } | ||||||
| 1665 | |||||||
| 1666 | SetFramePopClosure op(this, state, depth); | ||||||
| 1667 | MutexLocker mu(JvmtiThreadState_lock); | ||||||
| 1668 | if (java_thread == JavaThread::current()) { | ||||||
| 1669 | op.doit(java_thread, true /* self */); | ||||||
| 1670 | } else { | ||||||
| 1671 | Handshake::execute(&op, java_thread); | ||||||
| 1672 | } | ||||||
| 1673 | return op.result(); | ||||||
| 1674 | } /* end NotifyFramePop */ | ||||||
| 1675 | |||||||
| 1676 | |||||||
| 1677 | // | ||||||
| 1678 | // Force Early Return functions | ||||||
| 1679 | // | ||||||
| 1680 | |||||||
| 1681 | // java_thread - protected by ThreadsListHandle and pre-checked | ||||||
| 1682 | jvmtiError | ||||||
| 1683 | JvmtiEnv::ForceEarlyReturnObject(JavaThread* java_thread, jobject value) { | ||||||
| 1684 | jvalue val; | ||||||
| 1685 | val.l = value; | ||||||
| 1686 | return force_early_return(java_thread, val, atos); | ||||||
| 1687 | } /* end ForceEarlyReturnObject */ | ||||||
| 1688 | |||||||
| 1689 | |||||||
| 1690 | // java_thread - protected by ThreadsListHandle and pre-checked | ||||||
| 1691 | jvmtiError | ||||||
| 1692 | JvmtiEnv::ForceEarlyReturnInt(JavaThread* java_thread, jint value) { | ||||||
| 1693 | jvalue val; | ||||||
| 1694 | val.i = value; | ||||||
| 1695 | return force_early_return(java_thread, val, itos); | ||||||
| 1696 | } /* end ForceEarlyReturnInt */ | ||||||
| 1697 | |||||||
| 1698 | |||||||
| 1699 | // java_thread - protected by ThreadsListHandle and pre-checked | ||||||
| 1700 | jvmtiError | ||||||
| 1701 | JvmtiEnv::ForceEarlyReturnLong(JavaThread* java_thread, jlong value) { | ||||||
| 1702 | jvalue val; | ||||||
| 1703 | val.j = value; | ||||||
| 1704 | return force_early_return(java_thread, val, ltos); | ||||||
| 1705 | } /* end ForceEarlyReturnLong */ | ||||||
| 1706 | |||||||
| 1707 | |||||||
| 1708 | // java_thread - protected by ThreadsListHandle and pre-checked | ||||||
| 1709 | jvmtiError | ||||||
| 1710 | JvmtiEnv::ForceEarlyReturnFloat(JavaThread* java_thread, jfloat value) { | ||||||
| 1711 | jvalue val; | ||||||
| 1712 | val.f = value; | ||||||
| 1713 | return force_early_return(java_thread, val, ftos); | ||||||
| 1714 | } /* end ForceEarlyReturnFloat */ | ||||||
| 1715 | |||||||
| 1716 | |||||||
| 1717 | // java_thread - protected by ThreadsListHandle and pre-checked | ||||||
| 1718 | jvmtiError | ||||||
| 1719 | JvmtiEnv::ForceEarlyReturnDouble(JavaThread* java_thread, jdouble value) { | ||||||
| 1720 | jvalue val; | ||||||
| 1721 | val.d = value; | ||||||
| 1722 | return force_early_return(java_thread, val, dtos); | ||||||
| 1723 | } /* end ForceEarlyReturnDouble */ | ||||||
| 1724 | |||||||
| 1725 | |||||||
| 1726 | // java_thread - protected by ThreadsListHandle and pre-checked | ||||||
| 1727 | jvmtiError | ||||||
| 1728 | JvmtiEnv::ForceEarlyReturnVoid(JavaThread* java_thread) { | ||||||
| 1729 | jvalue val; | ||||||
| 1730 | val.j = 0L; | ||||||
| 1731 | return force_early_return(java_thread, val, vtos); | ||||||
| 1732 | } /* end ForceEarlyReturnVoid */ | ||||||
| 1733 | |||||||
| 1734 | |||||||
| 1735 | // | ||||||
| 1736 | // Heap functions | ||||||
| 1737 | // | ||||||
| 1738 | |||||||
| 1739 | // klass - NULL is a valid value, must be checked | ||||||
| 1740 | // initial_object - NULL is a valid value, must be checked | ||||||
| 1741 | // callbacks - pre-checked for NULL | ||||||
| 1742 | // user_data - NULL is a valid value, must be checked | ||||||
| 1743 | jvmtiError | ||||||
| 1744 | JvmtiEnv::FollowReferences(jint heap_filter, jclass klass, jobject initial_object, const jvmtiHeapCallbacks* callbacks, const void* user_data) { | ||||||
| 1745 | // check klass if provided | ||||||
| 1746 | Klass* k = NULL__null; | ||||||
| 1747 | if (klass != NULL__null) { | ||||||
| 1748 | oop k_mirror = JNIHandles::resolve_external_guard(klass); | ||||||
| 1749 | if (k_mirror == NULL__null) { | ||||||
| 1750 | return JVMTI_ERROR_INVALID_CLASS; | ||||||
| 1751 | } | ||||||
| 1752 | if (java_lang_Class::is_primitive(k_mirror)) { | ||||||
| 1753 | return JVMTI_ERROR_NONE; | ||||||
| 1754 | } | ||||||
| 1755 | k = java_lang_Class::as_Klass(k_mirror); | ||||||
| 1756 | if (klass == NULL__null) { | ||||||
| 1757 | return JVMTI_ERROR_INVALID_CLASS; | ||||||
| 1758 | } | ||||||
| 1759 | } | ||||||
| 1760 | |||||||
| 1761 | if (initial_object != NULL__null) { | ||||||
| 1762 | oop init_obj = JNIHandles::resolve_external_guard(initial_object); | ||||||
| 1763 | if (init_obj == NULL__null) { | ||||||
| 1764 | return JVMTI_ERROR_INVALID_OBJECT; | ||||||
| 1765 | } | ||||||
| 1766 | } | ||||||
| 1767 | |||||||
| 1768 | Thread *thread = Thread::current(); | ||||||
| 1769 | HandleMark hm(thread); | ||||||
| 1770 | |||||||
| 1771 | TraceTime t("FollowReferences", TRACETIME_LOG(Debug, jvmti, objecttagging)(LogImpl<(LogTag::_jvmti), (LogTag::_objecttagging), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG)>::is_level(LogLevel::Debug)) ? static_cast<TraceTimerLogPrintFunc >(&LogImpl<(LogTag::_jvmti), (LogTag::_objecttagging ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) , (LogTag::__NO_TAG)>::write<LogLevel::Debug>) : (TraceTimerLogPrintFunc )__null); | ||||||
| 1772 | JvmtiTagMap::tag_map_for(this)->follow_references(heap_filter, k, initial_object, callbacks, user_data); | ||||||
| 1773 | return JVMTI_ERROR_NONE; | ||||||
| 1774 | } /* end FollowReferences */ | ||||||
| 1775 | |||||||
| 1776 | |||||||
| 1777 | // klass - NULL is a valid value, must be checked | ||||||
| 1778 | // callbacks - pre-checked for NULL | ||||||
| 1779 | // user_data - NULL is a valid value, must be checked | ||||||
| 1780 | jvmtiError | ||||||
| 1781 | JvmtiEnv::IterateThroughHeap(jint heap_filter, jclass klass, const jvmtiHeapCallbacks* callbacks, const void* user_data) { | ||||||
| 1782 | // check klass if provided | ||||||
| 1783 | Klass* k = NULL__null; | ||||||
| 1784 | if (klass != NULL__null) { | ||||||
| 1785 | oop k_mirror = JNIHandles::resolve_external_guard(klass); | ||||||
| 1786 | if (k_mirror == NULL__null) { | ||||||
| 1787 | return JVMTI_ERROR_INVALID_CLASS; | ||||||
| 1788 | } | ||||||
| 1789 | if (java_lang_Class::is_primitive(k_mirror)) { | ||||||
| 1790 | return JVMTI_ERROR_NONE; | ||||||
| 1791 | } | ||||||
| 1792 | k = java_lang_Class::as_Klass(k_mirror); | ||||||
| 1793 | if (k == NULL__null) { | ||||||
| 1794 | return JVMTI_ERROR_INVALID_CLASS; | ||||||
| 1795 | } | ||||||
| 1796 | } | ||||||
| 1797 | |||||||
| 1798 | TraceTime t("IterateThroughHeap", TRACETIME_LOG(Debug, jvmti, objecttagging)(LogImpl<(LogTag::_jvmti), (LogTag::_objecttagging), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG)>::is_level(LogLevel::Debug)) ? static_cast<TraceTimerLogPrintFunc >(&LogImpl<(LogTag::_jvmti), (LogTag::_objecttagging ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) , (LogTag::__NO_TAG)>::write<LogLevel::Debug>) : (TraceTimerLogPrintFunc )__null); | ||||||
| 1799 | JvmtiTagMap::tag_map_for(this)->iterate_through_heap(heap_filter, k, callbacks, user_data); | ||||||
| 1800 | return JVMTI_ERROR_NONE; | ||||||
| 1801 | } /* end IterateThroughHeap */ | ||||||
| 1802 | |||||||
| 1803 | |||||||
| 1804 | // tag_ptr - pre-checked for NULL | ||||||
| 1805 | jvmtiError | ||||||
| 1806 | JvmtiEnv::GetTag(jobject object, jlong* tag_ptr) { | ||||||
| 1807 | oop o = JNIHandles::resolve_external_guard(object); | ||||||
| 1808 | NULL_CHECK(o, JVMTI_ERROR_INVALID_OBJECT)if ((o) == __null) { return (JVMTI_ERROR_INVALID_OBJECT); }; | ||||||
| 1809 | *tag_ptr = JvmtiTagMap::tag_map_for(this)->get_tag(object); | ||||||
| 1810 | return JVMTI_ERROR_NONE; | ||||||
| 1811 | } /* end GetTag */ | ||||||
| 1812 | |||||||
| 1813 | |||||||
| 1814 | jvmtiError | ||||||
| 1815 | JvmtiEnv::SetTag(jobject object, jlong tag) { | ||||||
| 1816 | oop o = JNIHandles::resolve_external_guard(object); | ||||||
| 1817 | NULL_CHECK(o, JVMTI_ERROR_INVALID_OBJECT)if ((o) == __null) { return (JVMTI_ERROR_INVALID_OBJECT); }; | ||||||
| 1818 | JvmtiTagMap::tag_map_for(this)->set_tag(object, tag); | ||||||
| 1819 | return JVMTI_ERROR_NONE; | ||||||
| 1820 | } /* end SetTag */ | ||||||
| 1821 | |||||||
| 1822 | |||||||
| 1823 | // tag_count - pre-checked to be greater than or equal to 0 | ||||||
| 1824 | // tags - pre-checked for NULL | ||||||
| 1825 | // count_ptr - pre-checked for NULL | ||||||
| 1826 | // object_result_ptr - NULL is a valid value, must be checked | ||||||
| 1827 | // tag_result_ptr - NULL is a valid value, must be checked | ||||||
| 1828 | jvmtiError | ||||||
| 1829 | JvmtiEnv::GetObjectsWithTags(jint tag_count, const jlong* tags, jint* count_ptr, jobject** object_result_ptr, jlong** tag_result_ptr) { | ||||||
| 1830 | TraceTime t("GetObjectsWithTags", TRACETIME_LOG(Debug, jvmti, objecttagging)(LogImpl<(LogTag::_jvmti), (LogTag::_objecttagging), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG)>::is_level(LogLevel::Debug)) ? static_cast<TraceTimerLogPrintFunc >(&LogImpl<(LogTag::_jvmti), (LogTag::_objecttagging ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) , (LogTag::__NO_TAG)>::write<LogLevel::Debug>) : (TraceTimerLogPrintFunc )__null); | ||||||
| 1831 | return JvmtiTagMap::tag_map_for(this)->get_objects_with_tags((jlong*)tags, tag_count, count_ptr, object_result_ptr, tag_result_ptr); | ||||||
| 1832 | } /* end GetObjectsWithTags */ | ||||||
| 1833 | |||||||
| 1834 | |||||||
| 1835 | jvmtiError | ||||||
| 1836 | JvmtiEnv::ForceGarbageCollection() { | ||||||
| 1837 | Universe::heap()->collect(GCCause::_jvmti_force_gc); | ||||||
| 1838 | return JVMTI_ERROR_NONE; | ||||||
| 1839 | } /* end ForceGarbageCollection */ | ||||||
| 1840 | |||||||
| 1841 | |||||||
| 1842 | // | ||||||
| 1843 | // Heap (1.0) functions | ||||||
| 1844 | // | ||||||
| 1845 | |||||||
| 1846 | // object_reference_callback - pre-checked for NULL | ||||||
| 1847 | // user_data - NULL is a valid value, must be checked | ||||||
| 1848 | jvmtiError | ||||||
| 1849 | JvmtiEnv::IterateOverObjectsReachableFromObject(jobject object, jvmtiObjectReferenceCallback object_reference_callback, const void* user_data) { | ||||||
| 1850 | oop o = JNIHandles::resolve_external_guard(object); | ||||||
| 1851 | NULL_CHECK(o, JVMTI_ERROR_INVALID_OBJECT)if ((o) == __null) { return (JVMTI_ERROR_INVALID_OBJECT); }; | ||||||
| 1852 | JvmtiTagMap::tag_map_for(this)->iterate_over_objects_reachable_from_object(object, object_reference_callback, user_data); | ||||||
| 1853 | return JVMTI_ERROR_NONE; | ||||||
| 1854 | } /* end IterateOverObjectsReachableFromObject */ | ||||||
| 1855 | |||||||
| 1856 | |||||||
| 1857 | // heap_root_callback - NULL is a valid value, must be checked | ||||||
| 1858 | // stack_ref_callback - NULL is a valid value, must be checked | ||||||
| 1859 | // object_ref_callback - NULL is a valid value, must be checked | ||||||
| 1860 | // user_data - NULL is a valid value, must be checked | ||||||
| 1861 | jvmtiError | ||||||
| 1862 | JvmtiEnv::IterateOverReachableObjects(jvmtiHeapRootCallback heap_root_callback, jvmtiStackReferenceCallback stack_ref_callback, jvmtiObjectReferenceCallback object_ref_callback, const void* user_data) { | ||||||
| 1863 | TraceTime t("IterateOverReachableObjects", TRACETIME_LOG(Debug, jvmti, objecttagging)(LogImpl<(LogTag::_jvmti), (LogTag::_objecttagging), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG)>::is_level(LogLevel::Debug)) ? static_cast<TraceTimerLogPrintFunc >(&LogImpl<(LogTag::_jvmti), (LogTag::_objecttagging ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) , (LogTag::__NO_TAG)>::write<LogLevel::Debug>) : (TraceTimerLogPrintFunc )__null); | ||||||
| 1864 | JvmtiTagMap::tag_map_for(this)->iterate_over_reachable_objects(heap_root_callback, stack_ref_callback, object_ref_callback, user_data); | ||||||
| 1865 | return JVMTI_ERROR_NONE; | ||||||
| 1866 | } /* end IterateOverReachableObjects */ | ||||||
| 1867 | |||||||
| 1868 | |||||||
| 1869 | // heap_object_callback - pre-checked for NULL | ||||||
| 1870 | // user_data - NULL is a valid value, must be checked | ||||||
| 1871 | jvmtiError | ||||||
| 1872 | JvmtiEnv::IterateOverHeap(jvmtiHeapObjectFilter object_filter, jvmtiHeapObjectCallback heap_object_callback, const void* user_data) { | ||||||
| 1873 | TraceTime t("IterateOverHeap", TRACETIME_LOG(Debug, jvmti, objecttagging)(LogImpl<(LogTag::_jvmti), (LogTag::_objecttagging), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG)>::is_level(LogLevel::Debug)) ? static_cast<TraceTimerLogPrintFunc >(&LogImpl<(LogTag::_jvmti), (LogTag::_objecttagging ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) , (LogTag::__NO_TAG)>::write<LogLevel::Debug>) : (TraceTimerLogPrintFunc )__null); | ||||||
| 1874 | Thread *thread = Thread::current(); | ||||||
| 1875 | HandleMark hm(thread); | ||||||
| 1876 | JvmtiTagMap::tag_map_for(this)->iterate_over_heap(object_filter, NULL__null, heap_object_callback, user_data); | ||||||
| 1877 | return JVMTI_ERROR_NONE; | ||||||
| 1878 | } /* end IterateOverHeap */ | ||||||
| 1879 | |||||||
| 1880 | |||||||
| 1881 | // k_mirror - may be primitive, this must be checked | ||||||
| 1882 | // heap_object_callback - pre-checked for NULL | ||||||
| 1883 | // user_data - NULL is a valid value, must be checked | ||||||
| 1884 | jvmtiError | ||||||
| 1885 | JvmtiEnv::IterateOverInstancesOfClass(oop k_mirror, jvmtiHeapObjectFilter object_filter, jvmtiHeapObjectCallback heap_object_callback, const void* user_data) { | ||||||
| 1886 | if (java_lang_Class::is_primitive(k_mirror)) { | ||||||
| 1887 | // DO PRIMITIVE CLASS PROCESSING | ||||||
| 1888 | return JVMTI_ERROR_NONE; | ||||||
| 1889 | } | ||||||
| 1890 | Klass* klass = java_lang_Class::as_Klass(k_mirror); | ||||||
| 1891 | if (klass == NULL__null) { | ||||||
| 1892 | return JVMTI_ERROR_INVALID_CLASS; | ||||||
| 1893 | } | ||||||
| 1894 | TraceTime t("IterateOverInstancesOfClass", TRACETIME_LOG(Debug, jvmti, objecttagging)(LogImpl<(LogTag::_jvmti), (LogTag::_objecttagging), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG)>::is_level(LogLevel::Debug)) ? static_cast<TraceTimerLogPrintFunc >(&LogImpl<(LogTag::_jvmti), (LogTag::_objecttagging ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) , (LogTag::__NO_TAG)>::write<LogLevel::Debug>) : (TraceTimerLogPrintFunc )__null); | ||||||
| 1895 | JvmtiTagMap::tag_map_for(this)->iterate_over_heap(object_filter, klass, heap_object_callback, user_data); | ||||||
| 1896 | return JVMTI_ERROR_NONE; | ||||||
| 1897 | } /* end IterateOverInstancesOfClass */ | ||||||
| 1898 | |||||||
| 1899 | |||||||
| 1900 | // | ||||||
| 1901 | // Local Variable functions | ||||||
| 1902 | // | ||||||
| 1903 | |||||||
| 1904 | // java_thread - protected by ThreadsListHandle and pre-checked | ||||||
| 1905 | // depth - pre-checked as non-negative | ||||||
| 1906 | // value_ptr - pre-checked for NULL | ||||||
| 1907 | jvmtiError | ||||||
| 1908 | JvmtiEnv::GetLocalObject(JavaThread* java_thread, jint depth, jint slot, jobject* value_ptr) { | ||||||
| 1909 | JavaThread* current_thread = JavaThread::current(); | ||||||
| 1910 | // rm object is created to clean up the javaVFrame created in | ||||||
| 1911 | // doit_prologue(), but after doit() is finished with it. | ||||||
| 1912 | ResourceMark rm(current_thread); | ||||||
| 1913 | |||||||
| 1914 | VM_GetOrSetLocal op(java_thread, current_thread, depth, slot); | ||||||
| 1915 | VMThread::execute(&op); | ||||||
| 1916 | jvmtiError err = op.result(); | ||||||
| 1917 | if (err != JVMTI_ERROR_NONE) { | ||||||
| 1918 | return err; | ||||||
| 1919 | } else { | ||||||
| 1920 | *value_ptr = op.value().l; | ||||||
| 1921 | return JVMTI_ERROR_NONE; | ||||||
| 1922 | } | ||||||
| 1923 | } /* end GetLocalObject */ | ||||||
| 1924 | |||||||
| 1925 | // java_thread - protected by ThreadsListHandle and pre-checked | ||||||
| 1926 | // depth - pre-checked as non-negative | ||||||
| 1927 | // value - pre-checked for NULL | ||||||
| 1928 | jvmtiError | ||||||
| 1929 | JvmtiEnv::GetLocalInstance(JavaThread* java_thread, jint depth, jobject* value_ptr){ | ||||||
| 1930 | JavaThread* current_thread = JavaThread::current(); | ||||||
| 1931 | // rm object is created to clean up the javaVFrame created in | ||||||
| 1932 | // doit_prologue(), but after doit() is finished with it. | ||||||
| 1933 | ResourceMark rm(current_thread); | ||||||
| 1934 | |||||||
| 1935 | VM_GetReceiver op(java_thread, current_thread, depth); | ||||||
| 1936 | VMThread::execute(&op); | ||||||
| 1937 | jvmtiError err = op.result(); | ||||||
| 1938 | if (err != JVMTI_ERROR_NONE) { | ||||||
| 1939 | return err; | ||||||
| 1940 | } else { | ||||||
| 1941 | *value_ptr = op.value().l; | ||||||
| 1942 | return JVMTI_ERROR_NONE; | ||||||
| 1943 | } | ||||||
| 1944 | } /* end GetLocalInstance */ | ||||||
| 1945 | |||||||
| 1946 | |||||||
| 1947 | // java_thread - protected by ThreadsListHandle and pre-checked | ||||||
| 1948 | // depth - pre-checked as non-negative | ||||||
| 1949 | // value_ptr - pre-checked for NULL | ||||||
| 1950 | jvmtiError | ||||||
| 1951 | JvmtiEnv::GetLocalInt(JavaThread* java_thread, jint depth, jint slot, jint* value_ptr) { | ||||||
| 1952 | // rm object is created to clean up the javaVFrame created in | ||||||
| 1953 | // doit_prologue(), but after doit() is finished with it. | ||||||
| 1954 | ResourceMark rm; | ||||||
| 1955 | |||||||
| 1956 | VM_GetOrSetLocal op(java_thread, depth, slot, T_INT); | ||||||
| 1957 | VMThread::execute(&op); | ||||||
| 1958 | *value_ptr = op.value().i; | ||||||
| 1959 | return op.result(); | ||||||
| 1960 | } /* end GetLocalInt */ | ||||||
| 1961 | |||||||
| 1962 | |||||||
| 1963 | // java_thread - protected by ThreadsListHandle and pre-checked | ||||||
| 1964 | // depth - pre-checked as non-negative | ||||||
| 1965 | // value_ptr - pre-checked for NULL | ||||||
| 1966 | jvmtiError | ||||||
| 1967 | JvmtiEnv::GetLocalLong(JavaThread* java_thread, jint depth, jint slot, jlong* value_ptr) { | ||||||
| 1968 | // rm object is created to clean up the javaVFrame created in | ||||||
| 1969 | // doit_prologue(), but after doit() is finished with it. | ||||||
| 1970 | ResourceMark rm; | ||||||
| 1971 | |||||||
| 1972 | VM_GetOrSetLocal op(java_thread, depth, slot, T_LONG); | ||||||
| 1973 | VMThread::execute(&op); | ||||||
| 1974 | *value_ptr = op.value().j; | ||||||
| 1975 | return op.result(); | ||||||
| 1976 | } /* end GetLocalLong */ | ||||||
| 1977 | |||||||
| 1978 | |||||||
| 1979 | // java_thread - protected by ThreadsListHandle and pre-checked | ||||||
| 1980 | // depth - pre-checked as non-negative | ||||||
| 1981 | // value_ptr - pre-checked for NULL | ||||||
| 1982 | jvmtiError | ||||||
| 1983 | JvmtiEnv::GetLocalFloat(JavaThread* java_thread, jint depth, jint slot, jfloat* value_ptr) { | ||||||
| 1984 | // rm object is created to clean up the javaVFrame created in | ||||||
| 1985 | // doit_prologue(), but after doit() is finished with it. | ||||||
| 1986 | ResourceMark rm; | ||||||
| 1987 | |||||||
| 1988 | VM_GetOrSetLocal op(java_thread, depth, slot, T_FLOAT); | ||||||
| 1989 | VMThread::execute(&op); | ||||||
| 1990 | *value_ptr = op.value().f; | ||||||
| 1991 | return op.result(); | ||||||
| 1992 | } /* end GetLocalFloat */ | ||||||
| 1993 | |||||||
| 1994 | |||||||
| 1995 | // java_thread - protected by ThreadsListHandle and pre-checked | ||||||
| 1996 | // depth - pre-checked as non-negative | ||||||
| 1997 | // value_ptr - pre-checked for NULL | ||||||
| 1998 | jvmtiError | ||||||
| 1999 | JvmtiEnv::GetLocalDouble(JavaThread* java_thread, jint depth, jint slot, jdouble* value_ptr) { | ||||||
| 2000 | // rm object is created to clean up the javaVFrame created in | ||||||
| 2001 | // doit_prologue(), but after doit() is finished with it. | ||||||
| 2002 | ResourceMark rm; | ||||||
| 2003 | |||||||
| 2004 | VM_GetOrSetLocal op(java_thread, depth, slot, T_DOUBLE); | ||||||
| 2005 | VMThread::execute(&op); | ||||||
| 2006 | *value_ptr = op.value().d; | ||||||
| 2007 | return op.result(); | ||||||
| 2008 | } /* end GetLocalDouble */ | ||||||
| 2009 | |||||||
| 2010 | |||||||
| 2011 | // java_thread - protected by ThreadsListHandle and pre-checked | ||||||
| 2012 | // depth - pre-checked as non-negative | ||||||
| 2013 | jvmtiError | ||||||
| 2014 | JvmtiEnv::SetLocalObject(JavaThread* java_thread, jint depth, jint slot, jobject value) { | ||||||
| 2015 | // rm object is created to clean up the javaVFrame created in | ||||||
| 2016 | // doit_prologue(), but after doit() is finished with it. | ||||||
| 2017 | ResourceMark rm; | ||||||
| 2018 | jvalue val; | ||||||
| 2019 | val.l = value; | ||||||
| 2020 | VM_GetOrSetLocal op(java_thread, depth, slot, T_OBJECT, val); | ||||||
| 2021 | VMThread::execute(&op); | ||||||
| 2022 | return op.result(); | ||||||
| 2023 | } /* end SetLocalObject */ | ||||||
| 2024 | |||||||
| 2025 | |||||||
| 2026 | // java_thread - protected by ThreadsListHandle and pre-checked | ||||||
| 2027 | // depth - pre-checked as non-negative | ||||||
| 2028 | jvmtiError | ||||||
| 2029 | JvmtiEnv::SetLocalInt(JavaThread* java_thread, jint depth, jint slot, jint value) { | ||||||
| 2030 | // rm object is created to clean up the javaVFrame created in | ||||||
| 2031 | // doit_prologue(), but after doit() is finished with it. | ||||||
| 2032 | ResourceMark rm; | ||||||
| 2033 | jvalue val; | ||||||
| 2034 | val.i = value; | ||||||
| 2035 | VM_GetOrSetLocal op(java_thread, depth, slot, T_INT, val); | ||||||
| 2036 | VMThread::execute(&op); | ||||||
| 2037 | return op.result(); | ||||||
| 2038 | } /* end SetLocalInt */ | ||||||
| 2039 | |||||||
| 2040 | |||||||
| 2041 | // java_thread - protected by ThreadsListHandle and pre-checked | ||||||
| 2042 | // depth - pre-checked as non-negative | ||||||
| 2043 | jvmtiError | ||||||
| 2044 | JvmtiEnv::SetLocalLong(JavaThread* java_thread, jint depth, jint slot, jlong value) { | ||||||
| 2045 | // rm object is created to clean up the javaVFrame created in | ||||||
| 2046 | // doit_prologue(), but after doit() is finished with it. | ||||||
| 2047 | ResourceMark rm; | ||||||
| 2048 | jvalue val; | ||||||
| 2049 | val.j = value; | ||||||
| 2050 | VM_GetOrSetLocal op(java_thread, depth, slot, T_LONG, val); | ||||||
| 2051 | VMThread::execute(&op); | ||||||
| 2052 | return op.result(); | ||||||
| 2053 | } /* end SetLocalLong */ | ||||||
| 2054 | |||||||
| 2055 | |||||||
| 2056 | // java_thread - protected by ThreadsListHandle and pre-checked | ||||||
| 2057 | // depth - pre-checked as non-negative | ||||||
| 2058 | jvmtiError | ||||||
| 2059 | JvmtiEnv::SetLocalFloat(JavaThread* java_thread, jint depth, jint slot, jfloat value) { | ||||||
| 2060 | // rm object is created to clean up the javaVFrame created in | ||||||
| 2061 | // doit_prologue(), but after doit() is finished with it. | ||||||
| 2062 | ResourceMark rm; | ||||||
| 2063 | jvalue val; | ||||||
| 2064 | val.f = value; | ||||||
| 2065 | VM_GetOrSetLocal op(java_thread, depth, slot, T_FLOAT, val); | ||||||
| 2066 | VMThread::execute(&op); | ||||||
| 2067 | return op.result(); | ||||||
| 2068 | } /* end SetLocalFloat */ | ||||||
| 2069 | |||||||
| 2070 | |||||||
| 2071 | // java_thread - protected by ThreadsListHandle and pre-checked | ||||||
| 2072 | // depth - pre-checked as non-negative | ||||||
| 2073 | jvmtiError | ||||||
| 2074 | JvmtiEnv::SetLocalDouble(JavaThread* java_thread, jint depth, jint slot, jdouble value) { | ||||||
| 2075 | // rm object is created to clean up the javaVFrame created in | ||||||
| 2076 | // doit_prologue(), but after doit() is finished with it. | ||||||
| 2077 | ResourceMark rm; | ||||||
| 2078 | jvalue val; | ||||||
| 2079 | val.d = value; | ||||||
| 2080 | VM_GetOrSetLocal op(java_thread, depth, slot, T_DOUBLE, val); | ||||||
| 2081 | VMThread::execute(&op); | ||||||
| 2082 | return op.result(); | ||||||
| 2083 | } /* end SetLocalDouble */ | ||||||
| 2084 | |||||||
| 2085 | |||||||
| 2086 | // | ||||||
| 2087 | // Breakpoint functions | ||||||
| 2088 | // | ||||||
| 2089 | |||||||
| 2090 | // method - pre-checked for validity, but may be NULL meaning obsolete method | ||||||
| 2091 | jvmtiError | ||||||
| 2092 | JvmtiEnv::SetBreakpoint(Method* method, jlocation location) { | ||||||
| 2093 | NULL_CHECK(method, JVMTI_ERROR_INVALID_METHODID)if ((method) == __null) { return (JVMTI_ERROR_INVALID_METHODID ); }; | ||||||
| 2094 | if (location < 0) { // simple invalid location check first | ||||||
| 2095 | return JVMTI_ERROR_INVALID_LOCATION; | ||||||
| 2096 | } | ||||||
| 2097 | // verify that the breakpoint is not past the end of the method | ||||||
| 2098 | if (location >= (jlocation) method->code_size()) { | ||||||
| 2099 | return JVMTI_ERROR_INVALID_LOCATION; | ||||||
| 2100 | } | ||||||
| 2101 | |||||||
| 2102 | ResourceMark rm; | ||||||
| 2103 | JvmtiBreakpoint bp(method, location); | ||||||
| 2104 | JvmtiBreakpoints& jvmti_breakpoints = JvmtiCurrentBreakpoints::get_jvmti_breakpoints(); | ||||||
| 2105 | if (jvmti_breakpoints.set(bp) == JVMTI_ERROR_DUPLICATE) | ||||||
| 2106 | return JVMTI_ERROR_DUPLICATE; | ||||||
| 2107 | |||||||
| 2108 | if (TraceJVMTICallsfalse) { | ||||||
| 2109 | jvmti_breakpoints.print(); | ||||||
| 2110 | } | ||||||
| 2111 | |||||||
| 2112 | return JVMTI_ERROR_NONE; | ||||||
| 2113 | } /* end SetBreakpoint */ | ||||||
| 2114 | |||||||
| 2115 | |||||||
| 2116 | // method - pre-checked for validity, but may be NULL meaning obsolete method | ||||||
| 2117 | jvmtiError | ||||||
| 2118 | JvmtiEnv::ClearBreakpoint(Method* method, jlocation location) { | ||||||
| 2119 | NULL_CHECK(method, JVMTI_ERROR_INVALID_METHODID)if ((method) == __null) { return (JVMTI_ERROR_INVALID_METHODID ); }; | ||||||
| 2120 | |||||||
| 2121 | if (location < 0) { // simple invalid location check first | ||||||
| 2122 | return JVMTI_ERROR_INVALID_LOCATION; | ||||||
| 2123 | } | ||||||
| 2124 | |||||||
| 2125 | // verify that the breakpoint is not past the end of the method | ||||||
| 2126 | if (location >= (jlocation) method->code_size()) { | ||||||
| 2127 | return JVMTI_ERROR_INVALID_LOCATION; | ||||||
| 2128 | } | ||||||
| 2129 | |||||||
| 2130 | JvmtiBreakpoint bp(method, location); | ||||||
| 2131 | |||||||
| 2132 | JvmtiBreakpoints& jvmti_breakpoints = JvmtiCurrentBreakpoints::get_jvmti_breakpoints(); | ||||||
| 2133 | if (jvmti_breakpoints.clear(bp) == JVMTI_ERROR_NOT_FOUND) | ||||||
| 2134 | return JVMTI_ERROR_NOT_FOUND; | ||||||
| 2135 | |||||||
| 2136 | if (TraceJVMTICallsfalse) { | ||||||
| 2137 | jvmti_breakpoints.print(); | ||||||
| 2138 | } | ||||||
| 2139 | |||||||
| 2140 | return JVMTI_ERROR_NONE; | ||||||
| 2141 | } /* end ClearBreakpoint */ | ||||||
| 2142 | |||||||
| 2143 | |||||||
| 2144 | // | ||||||
| 2145 | // Watched Field functions | ||||||
| 2146 | // | ||||||
| 2147 | |||||||
| 2148 | jvmtiError | ||||||
| 2149 | JvmtiEnv::SetFieldAccessWatch(fieldDescriptor* fdesc_ptr) { | ||||||
| 2150 | // make sure we haven't set this watch before | ||||||
| 2151 | if (fdesc_ptr->is_field_access_watched()) return JVMTI_ERROR_DUPLICATE; | ||||||
| 2152 | fdesc_ptr->set_is_field_access_watched(true); | ||||||
| 2153 | |||||||
| 2154 | JvmtiEventController::change_field_watch(JVMTI_EVENT_FIELD_ACCESS, true); | ||||||
| 2155 | |||||||
| 2156 | return JVMTI_ERROR_NONE; | ||||||
| 2157 | } /* end SetFieldAccessWatch */ | ||||||
| 2158 | |||||||
| 2159 | |||||||
| 2160 | jvmtiError | ||||||
| 2161 | JvmtiEnv::ClearFieldAccessWatch(fieldDescriptor* fdesc_ptr) { | ||||||
| 2162 | // make sure we have a watch to clear | ||||||
| 2163 | if (!fdesc_ptr->is_field_access_watched()) return JVMTI_ERROR_NOT_FOUND; | ||||||
| 2164 | fdesc_ptr->set_is_field_access_watched(false); | ||||||
| 2165 | |||||||
| 2166 | JvmtiEventController::change_field_watch(JVMTI_EVENT_FIELD_ACCESS, false); | ||||||
| 2167 | |||||||
| 2168 | return JVMTI_ERROR_NONE; | ||||||
| 2169 | } /* end ClearFieldAccessWatch */ | ||||||
| 2170 | |||||||
| 2171 | |||||||
| 2172 | jvmtiError | ||||||
| 2173 | JvmtiEnv::SetFieldModificationWatch(fieldDescriptor* fdesc_ptr) { | ||||||
| 2174 | // make sure we haven't set this watch before | ||||||
| 2175 | if (fdesc_ptr->is_field_modification_watched()) return JVMTI_ERROR_DUPLICATE; | ||||||
| 2176 | fdesc_ptr->set_is_field_modification_watched(true); | ||||||
| 2177 | |||||||
| 2178 | JvmtiEventController::change_field_watch(JVMTI_EVENT_FIELD_MODIFICATION, true); | ||||||
| 2179 | |||||||
| 2180 | return JVMTI_ERROR_NONE; | ||||||
| 2181 | } /* end SetFieldModificationWatch */ | ||||||
| 2182 | |||||||
| 2183 | |||||||
| 2184 | jvmtiError | ||||||
| 2185 | JvmtiEnv::ClearFieldModificationWatch(fieldDescriptor* fdesc_ptr) { | ||||||
| 2186 | // make sure we have a watch to clear | ||||||
| 2187 | if (!fdesc_ptr->is_field_modification_watched()) return JVMTI_ERROR_NOT_FOUND; | ||||||
| 2188 | fdesc_ptr->set_is_field_modification_watched(false); | ||||||
| 2189 | |||||||
| 2190 | JvmtiEventController::change_field_watch(JVMTI_EVENT_FIELD_MODIFICATION, false); | ||||||
| 2191 | |||||||
| 2192 | return JVMTI_ERROR_NONE; | ||||||
| 2193 | } /* end ClearFieldModificationWatch */ | ||||||
| 2194 | |||||||
| 2195 | // | ||||||
| 2196 | // Class functions | ||||||
| 2197 | // | ||||||
| 2198 | |||||||
| 2199 | |||||||
| 2200 | // k_mirror - may be primitive, this must be checked | ||||||
| 2201 | // signature_ptr - NULL is a valid value, must be checked | ||||||
| 2202 | // generic_ptr - NULL is a valid value, must be checked | ||||||
| 2203 | jvmtiError | ||||||
| 2204 | JvmtiEnv::GetClassSignature(oop k_mirror, char** signature_ptr, char** generic_ptr) { | ||||||
| 2205 | ResourceMark rm; | ||||||
| 2206 | bool isPrimitive = java_lang_Class::is_primitive(k_mirror); | ||||||
| 2207 | Klass* k = NULL__null; | ||||||
| 2208 | if (!isPrimitive) { | ||||||
| 2209 | k = java_lang_Class::as_Klass(k_mirror); | ||||||
| 2210 | NULL_CHECK(k, JVMTI_ERROR_INVALID_CLASS)if ((k) == __null) { return (JVMTI_ERROR_INVALID_CLASS); }; | ||||||
| 2211 | } | ||||||
| 2212 | if (signature_ptr != NULL__null) { | ||||||
| 2213 | char* result = NULL__null; | ||||||
| 2214 | if (isPrimitive) { | ||||||
| 2215 | char tchar = type2char(java_lang_Class::primitive_type(k_mirror)); | ||||||
| 2216 | result = (char*) jvmtiMalloc(2); | ||||||
| 2217 | result[0] = tchar; | ||||||
| 2218 | result[1] = '\0'; | ||||||
| 2219 | } else { | ||||||
| 2220 | const char* class_sig = k->signature_name(); | ||||||
| 2221 | result = (char *) jvmtiMalloc(strlen(class_sig)+1); | ||||||
| 2222 | strcpy(result, class_sig); | ||||||
| 2223 | } | ||||||
| 2224 | *signature_ptr = result; | ||||||
| 2225 | } | ||||||
| 2226 | if (generic_ptr != NULL__null) { | ||||||
| 2227 | *generic_ptr = NULL__null; | ||||||
| 2228 | if (!isPrimitive && k->is_instance_klass()) { | ||||||
| 2229 | Symbol* soo = InstanceKlass::cast(k)->generic_signature(); | ||||||
| 2230 | if (soo != NULL__null) { | ||||||
| 2231 | const char *gen_sig = soo->as_C_string(); | ||||||
| 2232 | if (gen_sig != NULL__null) { | ||||||
| 2233 | char* gen_result; | ||||||
| 2234 | jvmtiError err = allocate(strlen(gen_sig) + 1, | ||||||
| 2235 | (unsigned char **)&gen_result); | ||||||
| 2236 | if (err != JVMTI_ERROR_NONE) { | ||||||
| 2237 | return err; | ||||||
| 2238 | } | ||||||
| 2239 | strcpy(gen_result, gen_sig); | ||||||
| 2240 | *generic_ptr = gen_result; | ||||||
| 2241 | } | ||||||
| 2242 | } | ||||||
| 2243 | } | ||||||
| 2244 | } | ||||||
| 2245 | return JVMTI_ERROR_NONE; | ||||||
| 2246 | } /* end GetClassSignature */ | ||||||
| 2247 | |||||||
| 2248 | |||||||
| 2249 | // k_mirror - may be primitive, this must be checked | ||||||
| 2250 | // status_ptr - pre-checked for NULL | ||||||
| 2251 | jvmtiError | ||||||
| 2252 | JvmtiEnv::GetClassStatus(oop k_mirror, jint* status_ptr) { | ||||||
| 2253 | jint result = 0; | ||||||
| 2254 | if (java_lang_Class::is_primitive(k_mirror)) { | ||||||
| 2255 | result |= JVMTI_CLASS_STATUS_PRIMITIVE; | ||||||
| 2256 | } else { | ||||||
| 2257 | Klass* k = java_lang_Class::as_Klass(k_mirror); | ||||||
| 2258 | NULL_CHECK(k, JVMTI_ERROR_INVALID_CLASS)if ((k) == __null) { return (JVMTI_ERROR_INVALID_CLASS); }; | ||||||
| 2259 | result = k->jvmti_class_status(); | ||||||
| 2260 | } | ||||||
| 2261 | *status_ptr = result; | ||||||
| 2262 | |||||||
| 2263 | return JVMTI_ERROR_NONE; | ||||||
| 2264 | } /* end GetClassStatus */ | ||||||
| 2265 | |||||||
| 2266 | |||||||
| 2267 | // k_mirror - may be primitive, this must be checked | ||||||
| 2268 | // source_name_ptr - pre-checked for NULL | ||||||
| 2269 | jvmtiError | ||||||
| 2270 | JvmtiEnv::GetSourceFileName(oop k_mirror, char** source_name_ptr) { | ||||||
| 2271 | if (java_lang_Class::is_primitive(k_mirror)) { | ||||||
| 2272 | return JVMTI_ERROR_ABSENT_INFORMATION; | ||||||
| 2273 | } | ||||||
| 2274 | Klass* k_klass = java_lang_Class::as_Klass(k_mirror); | ||||||
| 2275 | NULL_CHECK(k_klass, JVMTI_ERROR_INVALID_CLASS)if ((k_klass) == __null) { return (JVMTI_ERROR_INVALID_CLASS) ; }; | ||||||
| 2276 | |||||||
| 2277 | if (!k_klass->is_instance_klass()) { | ||||||
| 2278 | return JVMTI_ERROR_ABSENT_INFORMATION; | ||||||
| 2279 | } | ||||||
| 2280 | |||||||
| 2281 | Symbol* sfnOop = InstanceKlass::cast(k_klass)->source_file_name(); | ||||||
| 2282 | NULL_CHECK(sfnOop, JVMTI_ERROR_ABSENT_INFORMATION)if ((sfnOop) == __null) { return (JVMTI_ERROR_ABSENT_INFORMATION ); }; | ||||||
| 2283 | { | ||||||
| 2284 | JavaThread* current_thread = JavaThread::current(); | ||||||
| 2285 | ResourceMark rm(current_thread); | ||||||
| 2286 | const char* sfncp = (const char*) sfnOop->as_C_string(); | ||||||
| 2287 | *source_name_ptr = (char *) jvmtiMalloc(strlen(sfncp)+1); | ||||||
| 2288 | strcpy(*source_name_ptr, sfncp); | ||||||
| 2289 | } | ||||||
| 2290 | |||||||
| 2291 | return JVMTI_ERROR_NONE; | ||||||
| 2292 | } /* end GetSourceFileName */ | ||||||
| 2293 | |||||||
| 2294 | |||||||
| 2295 | // k_mirror - may be primitive, this must be checked | ||||||
| 2296 | // modifiers_ptr - pre-checked for NULL | ||||||
| 2297 | jvmtiError | ||||||
| 2298 | JvmtiEnv::GetClassModifiers(oop k_mirror, jint* modifiers_ptr) { | ||||||
| 2299 | JavaThread* current_thread = JavaThread::current(); | ||||||
| 2300 | jint result = 0; | ||||||
| 2301 | if (!java_lang_Class::is_primitive(k_mirror)) { | ||||||
| 2302 | Klass* k = java_lang_Class::as_Klass(k_mirror); | ||||||
| 2303 | NULL_CHECK(k, JVMTI_ERROR_INVALID_CLASS)if ((k) == __null) { return (JVMTI_ERROR_INVALID_CLASS); }; | ||||||
| 2304 | result = k->compute_modifier_flags(); | ||||||
| 2305 | |||||||
| 2306 | // Reset the deleted ACC_SUPER bit (deleted in compute_modifier_flags()). | ||||||
| 2307 | if (k->is_super()) { | ||||||
| 2308 | result |= JVM_ACC_SUPER; | ||||||
| 2309 | } | ||||||
| 2310 | } else { | ||||||
| 2311 | result = (JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC); | ||||||
| 2312 | } | ||||||
| 2313 | *modifiers_ptr = result; | ||||||
| 2314 | |||||||
| 2315 | return JVMTI_ERROR_NONE; | ||||||
| 2316 | } /* end GetClassModifiers */ | ||||||
| 2317 | |||||||
| 2318 | |||||||
| 2319 | // k_mirror - may be primitive, this must be checked | ||||||
| 2320 | // method_count_ptr - pre-checked for NULL | ||||||
| 2321 | // methods_ptr - pre-checked for NULL | ||||||
| 2322 | jvmtiError | ||||||
| 2323 | JvmtiEnv::GetClassMethods(oop k_mirror, jint* method_count_ptr, jmethodID** methods_ptr) { | ||||||
| 2324 | JavaThread* current_thread = JavaThread::current(); | ||||||
| 2325 | HandleMark hm(current_thread); | ||||||
| 2326 | |||||||
| 2327 | if (java_lang_Class::is_primitive(k_mirror)) { | ||||||
| 2328 | *method_count_ptr = 0; | ||||||
| 2329 | *methods_ptr = (jmethodID*) jvmtiMalloc(0 * sizeof(jmethodID)); | ||||||
| 2330 | return JVMTI_ERROR_NONE; | ||||||
| 2331 | } | ||||||
| 2332 | Klass* k = java_lang_Class::as_Klass(k_mirror); | ||||||
| 2333 | NULL_CHECK(k, JVMTI_ERROR_INVALID_CLASS)if ((k) == __null) { return (JVMTI_ERROR_INVALID_CLASS); }; | ||||||
| 2334 | |||||||
| 2335 | // Return CLASS_NOT_PREPARED error as per JVMTI spec. | ||||||
| 2336 | if (!(k->jvmti_class_status() & (JVMTI_CLASS_STATUS_PREPARED|JVMTI_CLASS_STATUS_ARRAY) )) { | ||||||
| 2337 | return JVMTI_ERROR_CLASS_NOT_PREPARED; | ||||||
| 2338 | } | ||||||
| 2339 | |||||||
| 2340 | if (!k->is_instance_klass()) { | ||||||
| 2341 | *method_count_ptr = 0; | ||||||
| 2342 | *methods_ptr = (jmethodID*) jvmtiMalloc(0 * sizeof(jmethodID)); | ||||||
| 2343 | return JVMTI_ERROR_NONE; | ||||||
| 2344 | } | ||||||
| 2345 | InstanceKlass* ik = InstanceKlass::cast(k); | ||||||
| 2346 | // Allocate the result and fill it in | ||||||
| 2347 | int result_length = ik->methods()->length(); | ||||||
| 2348 | jmethodID* result_list = (jmethodID*)jvmtiMalloc(result_length * sizeof(jmethodID)); | ||||||
| 2349 | int index; | ||||||
| 2350 | bool jmethodids_found = true; | ||||||
| 2351 | int skipped = 0; // skip overpass methods | ||||||
| 2352 | |||||||
| 2353 | for (index = 0; index < result_length; index++) { | ||||||
| 2354 | Method* m = ik->methods()->at(index); | ||||||
| 2355 | // Depending on can_maintain_original_method_order capability use the original | ||||||
| 2356 | // method ordering indices stored in the class, so we can emit jmethodIDs in | ||||||
| 2357 | // the order they appeared in the class file or just copy in current order. | ||||||
| 2358 | int result_index = JvmtiExport::can_maintain_original_method_order() ? ik->method_ordering()->at(index) : index; | ||||||
| 2359 | assert(result_index >= 0 && result_index < result_length, "invalid original method index")do { if (!(result_index >= 0 && result_index < result_length )) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/prims/jvmtiEnv.cpp" , 2359, "assert(" "result_index >= 0 && result_index < result_length" ") failed", "invalid original method index"); ::breakpoint() ; } } while (0); | ||||||
| 2360 | if (m->is_overpass()) { | ||||||
| 2361 | result_list[result_index] = NULL__null; | ||||||
| 2362 | skipped++; | ||||||
| 2363 | continue; | ||||||
| 2364 | } | ||||||
| 2365 | jmethodID id; | ||||||
| 2366 | if (jmethodids_found) { | ||||||
| 2367 | id = m->find_jmethod_id_or_null(); | ||||||
| 2368 | if (id == NULL__null) { | ||||||
| 2369 | // If we find an uninitialized value, make sure there is | ||||||
| 2370 | // enough space for all the uninitialized values we might | ||||||
| 2371 | // find. | ||||||
| 2372 | ik->ensure_space_for_methodids(index); | ||||||
| 2373 | jmethodids_found = false; | ||||||
| 2374 | id = m->jmethod_id(); | ||||||
| 2375 | } | ||||||
| 2376 | } else { | ||||||
| 2377 | id = m->jmethod_id(); | ||||||
| 2378 | } | ||||||
| 2379 | result_list[result_index] = id; | ||||||
| 2380 | } | ||||||
| 2381 | |||||||
| 2382 | // Fill in return value. | ||||||
| 2383 | if (skipped > 0) { | ||||||
| 2384 | // copy results skipping NULL methodIDs | ||||||
| 2385 | *methods_ptr = (jmethodID*)jvmtiMalloc((result_length - skipped) * sizeof(jmethodID)); | ||||||
| 2386 | *method_count_ptr = result_length - skipped; | ||||||
| 2387 | for (index = 0, skipped = 0; index < result_length; index++) { | ||||||
| 2388 | if (result_list[index] == NULL__null) { | ||||||
| 2389 | skipped++; | ||||||
| 2390 | } else { | ||||||
| 2391 | (*methods_ptr)[index - skipped] = result_list[index]; | ||||||
| 2392 | } | ||||||
| 2393 | } | ||||||
| 2394 | deallocate((unsigned char *)result_list); | ||||||
| 2395 | } else { | ||||||
| 2396 | *method_count_ptr = result_length; | ||||||
| 2397 | *methods_ptr = result_list; | ||||||
| 2398 | } | ||||||
| 2399 | |||||||
| 2400 | return JVMTI_ERROR_NONE; | ||||||
| 2401 | } /* end GetClassMethods */ | ||||||
| 2402 | |||||||
| 2403 | |||||||
| 2404 | // k_mirror - may be primitive, this must be checked | ||||||
| 2405 | // field_count_ptr - pre-checked for NULL | ||||||
| 2406 | // fields_ptr - pre-checked for NULL | ||||||
| 2407 | jvmtiError | ||||||
| 2408 | JvmtiEnv::GetClassFields(oop k_mirror, jint* field_count_ptr, jfieldID** fields_ptr) { | ||||||
| 2409 | if (java_lang_Class::is_primitive(k_mirror)) { | ||||||
| 2410 | *field_count_ptr = 0; | ||||||
| 2411 | *fields_ptr = (jfieldID*) jvmtiMalloc(0 * sizeof(jfieldID)); | ||||||
| 2412 | return JVMTI_ERROR_NONE; | ||||||
| 2413 | } | ||||||
| 2414 | JavaThread* current_thread = JavaThread::current(); | ||||||
| 2415 | HandleMark hm(current_thread); | ||||||
| 2416 | Klass* k = java_lang_Class::as_Klass(k_mirror); | ||||||
| 2417 | NULL_CHECK(k, JVMTI_ERROR_INVALID_CLASS)if ((k) == __null) { return (JVMTI_ERROR_INVALID_CLASS); }; | ||||||
| 2418 | |||||||
| 2419 | // Return CLASS_NOT_PREPARED error as per JVMTI spec. | ||||||
| 2420 | if (!(k->jvmti_class_status() & (JVMTI_CLASS_STATUS_PREPARED|JVMTI_CLASS_STATUS_ARRAY) )) { | ||||||
| 2421 | return JVMTI_ERROR_CLASS_NOT_PREPARED; | ||||||
| 2422 | } | ||||||
| 2423 | |||||||
| 2424 | if (!k->is_instance_klass()) { | ||||||
| 2425 | *field_count_ptr = 0; | ||||||
| 2426 | *fields_ptr = (jfieldID*) jvmtiMalloc(0 * sizeof(jfieldID)); | ||||||
| 2427 | return JVMTI_ERROR_NONE; | ||||||
| 2428 | } | ||||||
| 2429 | |||||||
| 2430 | |||||||
| 2431 | InstanceKlass* ik = InstanceKlass::cast(k); | ||||||
| 2432 | |||||||
| 2433 | int result_count = 0; | ||||||
| 2434 | // First, count the fields. | ||||||
| 2435 | FilteredFieldStream flds(ik, true, true); | ||||||
| 2436 | result_count = flds.field_count(); | ||||||
| 2437 | |||||||
| 2438 | // Allocate the result and fill it in | ||||||
| 2439 | jfieldID* result_list = (jfieldID*) jvmtiMalloc(result_count * sizeof(jfieldID)); | ||||||
| 2440 | // The JVMTI spec requires fields in the order they occur in the class file, | ||||||
| 2441 | // this is the reverse order of what FieldStream hands out. | ||||||
| 2442 | int id_index = (result_count - 1); | ||||||
| 2443 | |||||||
| 2444 | for (FilteredFieldStream src_st(ik, true, true); !src_st.eos(); src_st.next()) { | ||||||
| 2445 | result_list[id_index--] = jfieldIDWorkaround::to_jfieldID( | ||||||
| 2446 | ik, src_st.offset(), | ||||||
| 2447 | src_st.access_flags().is_static()); | ||||||
| 2448 | } | ||||||
| 2449 | assert(id_index == -1, "just checking")do { if (!(id_index == -1)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/prims/jvmtiEnv.cpp" , 2449, "assert(" "id_index == -1" ") failed", "just checking" ); ::breakpoint(); } } while (0); | ||||||
| 2450 | // Fill in the results | ||||||
| 2451 | *field_count_ptr = result_count; | ||||||
| 2452 | *fields_ptr = result_list; | ||||||
| 2453 | |||||||
| 2454 | return JVMTI_ERROR_NONE; | ||||||
| 2455 | } /* end GetClassFields */ | ||||||
| 2456 | |||||||
| 2457 | |||||||
| 2458 | // k_mirror - may be primitive, this must be checked | ||||||
| 2459 | // interface_count_ptr - pre-checked for NULL | ||||||
| 2460 | // interfaces_ptr - pre-checked for NULL | ||||||
| 2461 | jvmtiError | ||||||
| 2462 | JvmtiEnv::GetImplementedInterfaces(oop k_mirror, jint* interface_count_ptr, jclass** interfaces_ptr) { | ||||||
| 2463 | { | ||||||
| 2464 | if (java_lang_Class::is_primitive(k_mirror)) { | ||||||
| 2465 | *interface_count_ptr = 0; | ||||||
| 2466 | *interfaces_ptr = (jclass*) jvmtiMalloc(0 * sizeof(jclass)); | ||||||
| 2467 | return JVMTI_ERROR_NONE; | ||||||
| 2468 | } | ||||||
| 2469 | JavaThread* current_thread = JavaThread::current(); | ||||||
| 2470 | HandleMark hm(current_thread); | ||||||
| 2471 | Klass* k = java_lang_Class::as_Klass(k_mirror); | ||||||
| 2472 | NULL_CHECK(k, JVMTI_ERROR_INVALID_CLASS)if ((k) == __null) { return (JVMTI_ERROR_INVALID_CLASS); }; | ||||||
| 2473 | |||||||
| 2474 | // Return CLASS_NOT_PREPARED error as per JVMTI spec. | ||||||
| 2475 | if (!(k->jvmti_class_status() & (JVMTI_CLASS_STATUS_PREPARED|JVMTI_CLASS_STATUS_ARRAY) )) | ||||||
| 2476 | return JVMTI_ERROR_CLASS_NOT_PREPARED; | ||||||
| 2477 | |||||||
| 2478 | if (!k->is_instance_klass()) { | ||||||
| 2479 | *interface_count_ptr = 0; | ||||||
| 2480 | *interfaces_ptr = (jclass*) jvmtiMalloc(0 * sizeof(jclass)); | ||||||
| 2481 | return JVMTI_ERROR_NONE; | ||||||
| 2482 | } | ||||||
| 2483 | |||||||
| 2484 | Array<InstanceKlass*>* interface_list = InstanceKlass::cast(k)->local_interfaces(); | ||||||
| 2485 | const int result_length = (interface_list == NULL__null ? 0 : interface_list->length()); | ||||||
| 2486 | jclass* result_list = (jclass*) jvmtiMalloc(result_length * sizeof(jclass)); | ||||||
| 2487 | for (int i_index = 0; i_index < result_length; i_index += 1) { | ||||||
| 2488 | InstanceKlass* klass_at = interface_list->at(i_index); | ||||||
| 2489 | assert(klass_at->is_klass(), "interfaces must be Klass*s")do { if (!(klass_at->is_klass())) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/prims/jvmtiEnv.cpp" , 2489, "assert(" "klass_at->is_klass()" ") failed", "interfaces must be Klass*s" ); ::breakpoint(); } } while (0); | ||||||
| 2490 | assert(klass_at->is_interface(), "interfaces must be interfaces")do { if (!(klass_at->is_interface())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/prims/jvmtiEnv.cpp" , 2490, "assert(" "klass_at->is_interface()" ") failed", "interfaces must be interfaces" ); ::breakpoint(); } } while (0); | ||||||
| 2491 | oop mirror_at = klass_at->java_mirror(); | ||||||
| 2492 | Handle handle_at = Handle(current_thread, mirror_at); | ||||||
| 2493 | result_list[i_index] = (jclass) jni_reference(handle_at); | ||||||
| 2494 | } | ||||||
| 2495 | *interface_count_ptr = result_length; | ||||||
| 2496 | *interfaces_ptr = result_list; | ||||||
| 2497 | } | ||||||
| 2498 | |||||||
| 2499 | return JVMTI_ERROR_NONE; | ||||||
| 2500 | } /* end GetImplementedInterfaces */ | ||||||
| 2501 | |||||||
| 2502 | |||||||
| 2503 | // k_mirror - may be primitive, this must be checked | ||||||
| 2504 | // minor_version_ptr - pre-checked for NULL | ||||||
| 2505 | // major_version_ptr - pre-checked for NULL | ||||||
| 2506 | jvmtiError | ||||||
| 2507 | JvmtiEnv::GetClassVersionNumbers(oop k_mirror, jint* minor_version_ptr, jint* major_version_ptr) { | ||||||
| 2508 | if (java_lang_Class::is_primitive(k_mirror)) { | ||||||
| 2509 | return JVMTI_ERROR_ABSENT_INFORMATION; | ||||||
| 2510 | } | ||||||
| 2511 | Klass* klass = java_lang_Class::as_Klass(k_mirror); | ||||||
| 2512 | |||||||
| 2513 | jint status = klass->jvmti_class_status(); | ||||||
| 2514 | if (status & (JVMTI_CLASS_STATUS_ERROR)) { | ||||||
| 2515 | return JVMTI_ERROR_INVALID_CLASS; | ||||||
| 2516 | } | ||||||
| 2517 | if (status & (JVMTI_CLASS_STATUS_ARRAY)) { | ||||||
| 2518 | return JVMTI_ERROR_ABSENT_INFORMATION; | ||||||
| 2519 | } | ||||||
| 2520 | |||||||
| 2521 | InstanceKlass* ik = InstanceKlass::cast(klass); | ||||||
| 2522 | *minor_version_ptr = ik->minor_version(); | ||||||
| 2523 | *major_version_ptr = ik->major_version(); | ||||||
| 2524 | |||||||
| 2525 | return JVMTI_ERROR_NONE; | ||||||
| 2526 | } /* end GetClassVersionNumbers */ | ||||||
| 2527 | |||||||
| 2528 | |||||||
| 2529 | // k_mirror - may be primitive, this must be checked | ||||||
| 2530 | // constant_pool_count_ptr - pre-checked for NULL | ||||||
| 2531 | // constant_pool_byte_count_ptr - pre-checked for NULL | ||||||
| 2532 | // constant_pool_bytes_ptr - pre-checked for NULL | ||||||
| 2533 | jvmtiError | ||||||
| 2534 | JvmtiEnv::GetConstantPool(oop k_mirror, jint* constant_pool_count_ptr, jint* constant_pool_byte_count_ptr, unsigned char** constant_pool_bytes_ptr) { | ||||||
| 2535 | if (java_lang_Class::is_primitive(k_mirror)) { | ||||||
| 2536 | return JVMTI_ERROR_ABSENT_INFORMATION; | ||||||
| 2537 | } | ||||||
| 2538 | |||||||
| 2539 | Klass* klass = java_lang_Class::as_Klass(k_mirror); | ||||||
| 2540 | Thread *thread = Thread::current(); | ||||||
| 2541 | ResourceMark rm(thread); | ||||||
| 2542 | |||||||
| 2543 | jint status = klass->jvmti_class_status(); | ||||||
| 2544 | if (status & (JVMTI_CLASS_STATUS_ERROR)) { | ||||||
| 2545 | return JVMTI_ERROR_INVALID_CLASS; | ||||||
| 2546 | } | ||||||
| 2547 | if (status & (JVMTI_CLASS_STATUS_ARRAY)) { | ||||||
| 2548 | return JVMTI_ERROR_ABSENT_INFORMATION; | ||||||
| 2549 | } | ||||||
| 2550 | |||||||
| 2551 | InstanceKlass* ik = InstanceKlass::cast(klass); | ||||||
| 2552 | JvmtiConstantPoolReconstituter reconstituter(ik); | ||||||
| 2553 | if (reconstituter.get_error() != JVMTI_ERROR_NONE) { | ||||||
| 2554 | return reconstituter.get_error(); | ||||||
| 2555 | } | ||||||
| 2556 | |||||||
| 2557 | unsigned char *cpool_bytes; | ||||||
| 2558 | int cpool_size = reconstituter.cpool_size(); | ||||||
| 2559 | if (reconstituter.get_error() != JVMTI_ERROR_NONE) { | ||||||
| 2560 | return reconstituter.get_error(); | ||||||
| 2561 | } | ||||||
| 2562 | jvmtiError res = allocate(cpool_size, &cpool_bytes); | ||||||
| 2563 | if (res != JVMTI_ERROR_NONE) { | ||||||
| 2564 | return res; | ||||||
| 2565 | } | ||||||
| 2566 | reconstituter.copy_cpool_bytes(cpool_bytes); | ||||||
| 2567 | if (reconstituter.get_error() != JVMTI_ERROR_NONE) { | ||||||
| 2568 | return reconstituter.get_error(); | ||||||
| 2569 | } | ||||||
| 2570 | |||||||
| 2571 | constantPoolHandle constants(thread, ik->constants()); | ||||||
| 2572 | *constant_pool_count_ptr = constants->length(); | ||||||
| 2573 | *constant_pool_byte_count_ptr = cpool_size; | ||||||
| 2574 | *constant_pool_bytes_ptr = cpool_bytes; | ||||||
| 2575 | |||||||
| 2576 | return JVMTI_ERROR_NONE; | ||||||
| 2577 | } /* end GetConstantPool */ | ||||||
| 2578 | |||||||
| 2579 | |||||||
| 2580 | // k_mirror - may be primitive, this must be checked | ||||||
| 2581 | // is_interface_ptr - pre-checked for NULL | ||||||
| 2582 | jvmtiError | ||||||
| 2583 | JvmtiEnv::IsInterface(oop k_mirror, jboolean* is_interface_ptr) { | ||||||
| 2584 | { | ||||||
| 2585 | bool result = false; | ||||||
| 2586 | if (!java_lang_Class::is_primitive(k_mirror)) { | ||||||
| 2587 | Klass* k = java_lang_Class::as_Klass(k_mirror); | ||||||
| 2588 | if (k != NULL__null && k->is_interface()) { | ||||||
| 2589 | result = true; | ||||||
| 2590 | } | ||||||
| 2591 | } | ||||||
| 2592 | *is_interface_ptr = result; | ||||||
| 2593 | } | ||||||
| 2594 | |||||||
| 2595 | return JVMTI_ERROR_NONE; | ||||||
| 2596 | } /* end IsInterface */ | ||||||
| 2597 | |||||||
| 2598 | |||||||
| 2599 | // k_mirror - may be primitive, this must be checked | ||||||
| 2600 | // is_array_class_ptr - pre-checked for NULL | ||||||
| 2601 | jvmtiError | ||||||
| 2602 | JvmtiEnv::IsArrayClass(oop k_mirror, jboolean* is_array_class_ptr) { | ||||||
| 2603 | { | ||||||
| 2604 | bool result = false; | ||||||
| 2605 | if (!java_lang_Class::is_primitive(k_mirror)) { | ||||||
| 2606 | Klass* k = java_lang_Class::as_Klass(k_mirror); | ||||||
| 2607 | if (k != NULL__null && k->is_array_klass()) { | ||||||
| 2608 | result = true; | ||||||
| 2609 | } | ||||||
| 2610 | } | ||||||
| 2611 | *is_array_class_ptr = result; | ||||||
| 2612 | } | ||||||
| 2613 | |||||||
| 2614 | return JVMTI_ERROR_NONE; | ||||||
| 2615 | } /* end IsArrayClass */ | ||||||
| 2616 | |||||||
| 2617 | |||||||
| 2618 | // k_mirror - may be primitive, this must be checked | ||||||
| 2619 | // classloader_ptr - pre-checked for NULL | ||||||
| 2620 | jvmtiError | ||||||
| 2621 | JvmtiEnv::GetClassLoader(oop k_mirror, jobject* classloader_ptr) { | ||||||
| 2622 | { | ||||||
| 2623 | if (java_lang_Class::is_primitive(k_mirror)) { | ||||||
| 2624 | *classloader_ptr = (jclass) jni_reference(Handle()); | ||||||
| 2625 | return JVMTI_ERROR_NONE; | ||||||
| 2626 | } | ||||||
| 2627 | JavaThread* current_thread = JavaThread::current(); | ||||||
| 2628 | HandleMark hm(current_thread); | ||||||
| 2629 | Klass* k = java_lang_Class::as_Klass(k_mirror); | ||||||
| 2630 | NULL_CHECK(k, JVMTI_ERROR_INVALID_CLASS)if ((k) == __null) { return (JVMTI_ERROR_INVALID_CLASS); }; | ||||||
| 2631 | |||||||
| 2632 | oop result_oop = k->class_loader(); | ||||||
| 2633 | if (result_oop == NULL__null) { | ||||||
| 2634 | *classloader_ptr = (jclass) jni_reference(Handle()); | ||||||
| 2635 | return JVMTI_ERROR_NONE; | ||||||
| 2636 | } | ||||||
| 2637 | Handle result_handle = Handle(current_thread, result_oop); | ||||||
| 2638 | jclass result_jnihandle = (jclass) jni_reference(result_handle); | ||||||
| 2639 | *classloader_ptr = result_jnihandle; | ||||||
| 2640 | } | ||||||
| 2641 | return JVMTI_ERROR_NONE; | ||||||
| 2642 | } /* end GetClassLoader */ | ||||||
| 2643 | |||||||
| 2644 | |||||||
| 2645 | // k_mirror - may be primitive, this must be checked | ||||||
| 2646 | // source_debug_extension_ptr - pre-checked for NULL | ||||||
| 2647 | jvmtiError | ||||||
| 2648 | JvmtiEnv::GetSourceDebugExtension(oop k_mirror, char** source_debug_extension_ptr) { | ||||||
| 2649 | { | ||||||
| 2650 | if (java_lang_Class::is_primitive(k_mirror)) { | ||||||
| 2651 | return JVMTI_ERROR_ABSENT_INFORMATION; | ||||||
| 2652 | } | ||||||
| 2653 | Klass* k = java_lang_Class::as_Klass(k_mirror); | ||||||
| 2654 | NULL_CHECK(k, JVMTI_ERROR_INVALID_CLASS)if ((k) == __null) { return (JVMTI_ERROR_INVALID_CLASS); }; | ||||||
| 2655 | if (!k->is_instance_klass()) { | ||||||
| 2656 | return JVMTI_ERROR_ABSENT_INFORMATION; | ||||||
| 2657 | } | ||||||
| 2658 | const char* sde = InstanceKlass::cast(k)->source_debug_extension(); | ||||||
| 2659 | NULL_CHECK(sde, JVMTI_ERROR_ABSENT_INFORMATION)if ((sde) == __null) { return (JVMTI_ERROR_ABSENT_INFORMATION ); }; | ||||||
| 2660 | |||||||
| 2661 | { | ||||||
| 2662 | *source_debug_extension_ptr = (char *) jvmtiMalloc(strlen(sde)+1); | ||||||
| 2663 | strcpy(*source_debug_extension_ptr, sde); | ||||||
| 2664 | } | ||||||
| 2665 | } | ||||||
| 2666 | |||||||
| 2667 | return JVMTI_ERROR_NONE; | ||||||
| 2668 | } /* end GetSourceDebugExtension */ | ||||||
| 2669 | |||||||
| 2670 | // | ||||||
| 2671 | // Object functions | ||||||
| 2672 | // | ||||||
| 2673 | |||||||
| 2674 | // hash_code_ptr - pre-checked for NULL | ||||||
| 2675 | jvmtiError | ||||||
| 2676 | JvmtiEnv::GetObjectHashCode(jobject object, jint* hash_code_ptr) { | ||||||
| 2677 | oop mirror = JNIHandles::resolve_external_guard(object); | ||||||
| 2678 | NULL_CHECK(mirror, JVMTI_ERROR_INVALID_OBJECT)if ((mirror) == __null) { return (JVMTI_ERROR_INVALID_OBJECT) ; }; | ||||||
| 2679 | NULL_CHECK(hash_code_ptr, JVMTI_ERROR_NULL_POINTER)if ((hash_code_ptr) == __null) { return (JVMTI_ERROR_NULL_POINTER ); }; | ||||||
| 2680 | |||||||
| 2681 | { | ||||||
| 2682 | jint result = (jint) mirror->identity_hash(); | ||||||
| 2683 | *hash_code_ptr = result; | ||||||
| 2684 | } | ||||||
| 2685 | return JVMTI_ERROR_NONE; | ||||||
| 2686 | } /* end GetObjectHashCode */ | ||||||
| 2687 | |||||||
| 2688 | |||||||
| 2689 | // info_ptr - pre-checked for NULL | ||||||
| 2690 | jvmtiError | ||||||
| 2691 | JvmtiEnv::GetObjectMonitorUsage(jobject object, jvmtiMonitorUsage* info_ptr) { | ||||||
| 2692 | // This needs to be performed at a safepoint to gather stable data | ||||||
| 2693 | // because monitor owner / waiters might not be suspended. | ||||||
| 2694 | VM_GetObjectMonitorUsage op(this, JavaThread::current(), object, info_ptr); | ||||||
| 2695 | VMThread::execute(&op); | ||||||
| 2696 | return op.result(); | ||||||
| 2697 | } /* end GetObjectMonitorUsage */ | ||||||
| 2698 | |||||||
| 2699 | |||||||
| 2700 | // | ||||||
| 2701 | // Field functions | ||||||
| 2702 | // | ||||||
| 2703 | |||||||
| 2704 | // name_ptr - NULL is a valid value, must be checked | ||||||
| 2705 | // signature_ptr - NULL is a valid value, must be checked | ||||||
| 2706 | // generic_ptr - NULL is a valid value, must be checked | ||||||
| 2707 | jvmtiError | ||||||
| 2708 | JvmtiEnv::GetFieldName(fieldDescriptor* fdesc_ptr, char** name_ptr, char** signature_ptr, char** generic_ptr) { | ||||||
| 2709 | JavaThread* current_thread = JavaThread::current(); | ||||||
| 2710 | ResourceMark rm(current_thread); | ||||||
| 2711 | if (name_ptr == NULL__null) { | ||||||
| 2712 | // just don't return the name | ||||||
| 2713 | } else { | ||||||
| 2714 | const char* fieldName = fdesc_ptr->name()->as_C_string(); | ||||||
| 2715 | *name_ptr = (char*) jvmtiMalloc(strlen(fieldName) + 1); | ||||||
| 2716 | if (*name_ptr == NULL__null) | ||||||
| 2717 | return JVMTI_ERROR_OUT_OF_MEMORY; | ||||||
| 2718 | strcpy(*name_ptr, fieldName); | ||||||
| 2719 | } | ||||||
| 2720 | if (signature_ptr== NULL__null) { | ||||||
| 2721 | // just don't return the signature | ||||||
| 2722 | } else { | ||||||
| 2723 | const char* fieldSignature = fdesc_ptr->signature()->as_C_string(); | ||||||
| 2724 | *signature_ptr = (char*) jvmtiMalloc(strlen(fieldSignature) + 1); | ||||||
| 2725 | if (*signature_ptr == NULL__null) | ||||||
| 2726 | return JVMTI_ERROR_OUT_OF_MEMORY; | ||||||
| 2727 | strcpy(*signature_ptr, fieldSignature); | ||||||
| 2728 | } | ||||||
| 2729 | if (generic_ptr != NULL__null) { | ||||||
| 2730 | *generic_ptr = NULL__null; | ||||||
| 2731 | Symbol* soop = fdesc_ptr->generic_signature(); | ||||||
| 2732 | if (soop != NULL__null) { | ||||||
| 2733 | const char* gen_sig = soop->as_C_string(); | ||||||
| 2734 | if (gen_sig != NULL__null) { | ||||||
| 2735 | jvmtiError err = allocate(strlen(gen_sig) + 1, (unsigned char **)generic_ptr); | ||||||
| 2736 | if (err != JVMTI_ERROR_NONE) { | ||||||
| 2737 | return err; | ||||||
| 2738 | } | ||||||
| 2739 | strcpy(*generic_ptr, gen_sig); | ||||||
| 2740 | } | ||||||
| 2741 | } | ||||||
| 2742 | } | ||||||
| 2743 | return JVMTI_ERROR_NONE; | ||||||
| 2744 | } /* end GetFieldName */ | ||||||
| 2745 | |||||||
| 2746 | |||||||
| 2747 | // declaring_class_ptr - pre-checked for NULL | ||||||
| 2748 | jvmtiError | ||||||
| 2749 | JvmtiEnv::GetFieldDeclaringClass(fieldDescriptor* fdesc_ptr, jclass* declaring_class_ptr) { | ||||||
| 2750 | |||||||
| 2751 | *declaring_class_ptr = get_jni_class_non_null(fdesc_ptr->field_holder()); | ||||||
| 2752 | return JVMTI_ERROR_NONE; | ||||||
| 2753 | } /* end GetFieldDeclaringClass */ | ||||||
| 2754 | |||||||
| 2755 | |||||||
| 2756 | // modifiers_ptr - pre-checked for NULL | ||||||
| 2757 | jvmtiError | ||||||
| 2758 | JvmtiEnv::GetFieldModifiers(fieldDescriptor* fdesc_ptr, jint* modifiers_ptr) { | ||||||
| 2759 | |||||||
| 2760 | AccessFlags resultFlags = fdesc_ptr->access_flags(); | ||||||
| 2761 | jint result = resultFlags.as_int(); | ||||||
| 2762 | *modifiers_ptr = result; | ||||||
| 2763 | |||||||
| 2764 | return JVMTI_ERROR_NONE; | ||||||
| 2765 | } /* end GetFieldModifiers */ | ||||||
| 2766 | |||||||
| 2767 | |||||||
| 2768 | // is_synthetic_ptr - pre-checked for NULL | ||||||
| 2769 | jvmtiError | ||||||
| 2770 | JvmtiEnv::IsFieldSynthetic(fieldDescriptor* fdesc_ptr, jboolean* is_synthetic_ptr) { | ||||||
| 2771 | *is_synthetic_ptr = fdesc_ptr->is_synthetic(); | ||||||
| 2772 | return JVMTI_ERROR_NONE; | ||||||
| 2773 | } /* end IsFieldSynthetic */ | ||||||
| 2774 | |||||||
| 2775 | |||||||
| 2776 | // | ||||||
| 2777 | // Method functions | ||||||
| 2778 | // | ||||||
| 2779 | |||||||
| 2780 | // method - pre-checked for validity, but may be NULL meaning obsolete method | ||||||
| 2781 | // name_ptr - NULL is a valid value, must be checked | ||||||
| 2782 | // signature_ptr - NULL is a valid value, must be checked | ||||||
| 2783 | // generic_ptr - NULL is a valid value, must be checked | ||||||
| 2784 | jvmtiError | ||||||
| 2785 | JvmtiEnv::GetMethodName(Method* method, char** name_ptr, char** signature_ptr, char** generic_ptr) { | ||||||
| 2786 | NULL_CHECK(method, JVMTI_ERROR_INVALID_METHODID)if ((method) == __null) { return (JVMTI_ERROR_INVALID_METHODID ); }; | ||||||
| 2787 | JavaThread* current_thread = JavaThread::current(); | ||||||
| 2788 | |||||||
| 2789 | ResourceMark rm(current_thread); // get the utf8 name and signature | ||||||
| 2790 | if (name_ptr == NULL__null) { | ||||||
| 2791 | // just don't return the name | ||||||
| 2792 | } else { | ||||||
| 2793 | const char* utf8_name = (const char *) method->name()->as_utf8(); | ||||||
| 2794 | *name_ptr = (char *) jvmtiMalloc(strlen(utf8_name)+1); | ||||||
| 2795 | strcpy(*name_ptr, utf8_name); | ||||||
| 2796 | } | ||||||
| 2797 | if (signature_ptr == NULL__null) { | ||||||
| 2798 | // just don't return the signature | ||||||
| 2799 | } else { | ||||||
| 2800 | const char* utf8_signature = (const char *) method->signature()->as_utf8(); | ||||||
| 2801 | *signature_ptr = (char *) jvmtiMalloc(strlen(utf8_signature) + 1); | ||||||
| 2802 | strcpy(*signature_ptr, utf8_signature); | ||||||
| 2803 | } | ||||||
| 2804 | |||||||
| 2805 | if (generic_ptr != NULL__null) { | ||||||
| 2806 | *generic_ptr = NULL__null; | ||||||
| 2807 | Symbol* soop = method->generic_signature(); | ||||||
| 2808 | if (soop != NULL__null) { | ||||||
| 2809 | const char* gen_sig = soop->as_C_string(); | ||||||
| 2810 | if (gen_sig != NULL__null) { | ||||||
| 2811 | jvmtiError err = allocate(strlen(gen_sig) + 1, (unsigned char **)generic_ptr); | ||||||
| 2812 | if (err != JVMTI_ERROR_NONE) { | ||||||
| 2813 | return err; | ||||||
| 2814 | } | ||||||
| 2815 | strcpy(*generic_ptr, gen_sig); | ||||||
| 2816 | } | ||||||
| 2817 | } | ||||||
| 2818 | } | ||||||
| 2819 | return JVMTI_ERROR_NONE; | ||||||
| 2820 | } /* end GetMethodName */ | ||||||
| 2821 | |||||||
| 2822 | |||||||
| 2823 | // method - pre-checked for validity, but may be NULL meaning obsolete method | ||||||
| 2824 | // declaring_class_ptr - pre-checked for NULL | ||||||
| 2825 | jvmtiError | ||||||
| 2826 | JvmtiEnv::GetMethodDeclaringClass(Method* method, jclass* declaring_class_ptr) { | ||||||
| 2827 | NULL_CHECK(method, JVMTI_ERROR_INVALID_METHODID)if ((method) == __null) { return (JVMTI_ERROR_INVALID_METHODID ); }; | ||||||
| 2828 | (*declaring_class_ptr) = get_jni_class_non_null(method->method_holder()); | ||||||
| 2829 | return JVMTI_ERROR_NONE; | ||||||
| 2830 | } /* end GetMethodDeclaringClass */ | ||||||
| 2831 | |||||||
| 2832 | |||||||
| 2833 | // method - pre-checked for validity, but may be NULL meaning obsolete method | ||||||
| 2834 | // modifiers_ptr - pre-checked for NULL | ||||||
| 2835 | jvmtiError | ||||||
| 2836 | JvmtiEnv::GetMethodModifiers(Method* method, jint* modifiers_ptr) { | ||||||
| 2837 | NULL_CHECK(method, JVMTI_ERROR_INVALID_METHODID)if ((method) == __null) { return (JVMTI_ERROR_INVALID_METHODID ); }; | ||||||
| 2838 | (*modifiers_ptr) = method->access_flags().as_int() & JVM_RECOGNIZED_METHOD_MODIFIERS(JVM_ACC_PUBLIC | JVM_ACC_PRIVATE | JVM_ACC_PROTECTED | JVM_ACC_STATIC | JVM_ACC_FINAL | JVM_ACC_SYNCHRONIZED | JVM_ACC_BRIDGE | JVM_ACC_VARARGS | JVM_ACC_NATIVE | JVM_ACC_ABSTRACT | JVM_ACC_STRICT | JVM_ACC_SYNTHETIC ); | ||||||
| 2839 | return JVMTI_ERROR_NONE; | ||||||
| 2840 | } /* end GetMethodModifiers */ | ||||||
| 2841 | |||||||
| 2842 | |||||||
| 2843 | // method - pre-checked for validity, but may be NULL meaning obsolete method | ||||||
| 2844 | // max_ptr - pre-checked for NULL | ||||||
| 2845 | jvmtiError | ||||||
| 2846 | JvmtiEnv::GetMaxLocals(Method* method, jint* max_ptr) { | ||||||
| 2847 | NULL_CHECK(method, JVMTI_ERROR_INVALID_METHODID)if ((method) == __null) { return (JVMTI_ERROR_INVALID_METHODID ); }; | ||||||
| 2848 | // get max stack | ||||||
| 2849 | (*max_ptr) = method->max_locals(); | ||||||
| 2850 | return JVMTI_ERROR_NONE; | ||||||
| 2851 | } /* end GetMaxLocals */ | ||||||
| 2852 | |||||||
| 2853 | |||||||
| 2854 | // method - pre-checked for validity, but may be NULL meaning obsolete method | ||||||
| 2855 | // size_ptr - pre-checked for NULL | ||||||
| 2856 | jvmtiError | ||||||
| 2857 | JvmtiEnv::GetArgumentsSize(Method* method, jint* size_ptr) { | ||||||
| 2858 | NULL_CHECK(method, JVMTI_ERROR_INVALID_METHODID)if ((method) == __null) { return (JVMTI_ERROR_INVALID_METHODID ); }; | ||||||
| 2859 | // get size of arguments | ||||||
| 2860 | |||||||
| 2861 | (*size_ptr) = method->size_of_parameters(); | ||||||
| 2862 | return JVMTI_ERROR_NONE; | ||||||
| 2863 | } /* end GetArgumentsSize */ | ||||||
| 2864 | |||||||
| 2865 | |||||||
| 2866 | // method - pre-checked for validity, but may be NULL meaning obsolete method | ||||||
| 2867 | // entry_count_ptr - pre-checked for NULL | ||||||
| 2868 | // table_ptr - pre-checked for NULL | ||||||
| 2869 | jvmtiError | ||||||
| 2870 | JvmtiEnv::GetLineNumberTable(Method* method, jint* entry_count_ptr, jvmtiLineNumberEntry** table_ptr) { | ||||||
| 2871 | NULL_CHECK(method, JVMTI_ERROR_INVALID_METHODID)if ((method) == __null) { return (JVMTI_ERROR_INVALID_METHODID ); }; | ||||||
| 2872 | if (!method->has_linenumber_table()) { | ||||||
| 2873 | return (JVMTI_ERROR_ABSENT_INFORMATION); | ||||||
| 2874 | } | ||||||
| 2875 | |||||||
| 2876 | // The line number table is compressed so we don't know how big it is until decompressed. | ||||||
| 2877 | // Decompression is really fast so we just do it twice. | ||||||
| 2878 | |||||||
| 2879 | // Compute size of table | ||||||
| 2880 | jint num_entries = 0; | ||||||
| 2881 | CompressedLineNumberReadStream stream(method->compressed_linenumber_table()); | ||||||
| 2882 | while (stream.read_pair()) { | ||||||
| 2883 | num_entries++; | ||||||
| 2884 | } | ||||||
| 2885 | jvmtiLineNumberEntry *jvmti_table = | ||||||
| 2886 | (jvmtiLineNumberEntry *)jvmtiMalloc(num_entries * (sizeof(jvmtiLineNumberEntry))); | ||||||
| 2887 | |||||||
| 2888 | // Fill jvmti table | ||||||
| 2889 | if (num_entries > 0) { | ||||||
| 2890 | int index = 0; | ||||||
| 2891 | CompressedLineNumberReadStream stream(method->compressed_linenumber_table()); | ||||||
| 2892 | while (stream.read_pair()) { | ||||||
| 2893 | jvmti_table[index].start_location = (jlocation) stream.bci(); | ||||||
| 2894 | jvmti_table[index].line_number = (jint) stream.line(); | ||||||
| 2895 | index++; | ||||||
| 2896 | } | ||||||
| 2897 | assert(index == num_entries, "sanity check")do { if (!(index == num_entries)) { (*g_assert_poison) = 'X'; ; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/prims/jvmtiEnv.cpp" , 2897, "assert(" "index == num_entries" ") failed", "sanity check" ); ::breakpoint(); } } while (0); | ||||||
| 2898 | } | ||||||
| 2899 | |||||||
| 2900 | // Set up results | ||||||
| 2901 | (*entry_count_ptr) = num_entries; | ||||||
| 2902 | (*table_ptr) = jvmti_table; | ||||||
| 2903 | |||||||
| 2904 | return JVMTI_ERROR_NONE; | ||||||
| 2905 | } /* end GetLineNumberTable */ | ||||||
| 2906 | |||||||
| 2907 | |||||||
| 2908 | // method - pre-checked for validity, but may be NULL meaning obsolete method | ||||||
| 2909 | // start_location_ptr - pre-checked for NULL | ||||||
| 2910 | // end_location_ptr - pre-checked for NULL | ||||||
| 2911 | jvmtiError | ||||||
| 2912 | JvmtiEnv::GetMethodLocation(Method* method, jlocation* start_location_ptr, jlocation* end_location_ptr) { | ||||||
| 2913 | |||||||
| 2914 | NULL_CHECK(method, JVMTI_ERROR_INVALID_METHODID)if ((method) == __null) { return (JVMTI_ERROR_INVALID_METHODID ); }; | ||||||
| 2915 | // get start and end location | ||||||
| 2916 | (*end_location_ptr) = (jlocation) (method->code_size() - 1); | ||||||
| 2917 | if (method->code_size() == 0) { | ||||||
| 2918 | // there is no code so there is no start location | ||||||
| 2919 | (*start_location_ptr) = (jlocation)(-1); | ||||||
| 2920 | } else { | ||||||
| 2921 | (*start_location_ptr) = (jlocation)(0); | ||||||
| 2922 | } | ||||||
| 2923 | |||||||
| 2924 | return JVMTI_ERROR_NONE; | ||||||
| 2925 | } /* end GetMethodLocation */ | ||||||
| 2926 | |||||||
| 2927 | |||||||
| 2928 | // method - pre-checked for validity, but may be NULL meaning obsolete method | ||||||
| 2929 | // entry_count_ptr - pre-checked for NULL | ||||||
| 2930 | // table_ptr - pre-checked for NULL | ||||||
| 2931 | jvmtiError | ||||||
| 2932 | JvmtiEnv::GetLocalVariableTable(Method* method, jint* entry_count_ptr, jvmtiLocalVariableEntry** table_ptr) { | ||||||
| 2933 | |||||||
| 2934 | NULL_CHECK(method, JVMTI_ERROR_INVALID_METHODID)if ((method) == __null) { return (JVMTI_ERROR_INVALID_METHODID ); }; | ||||||
| 2935 | JavaThread* current_thread = JavaThread::current(); | ||||||
| 2936 | |||||||
| 2937 | // does the klass have any local variable information? | ||||||
| 2938 | InstanceKlass* ik = method->method_holder(); | ||||||
| 2939 | if (!ik->access_flags().has_localvariable_table()) { | ||||||
| 2940 | return (JVMTI_ERROR_ABSENT_INFORMATION); | ||||||
| 2941 | } | ||||||
| 2942 | |||||||
| 2943 | ConstantPool* constants = method->constants(); | ||||||
| 2944 | NULL_CHECK(constants, JVMTI_ERROR_ABSENT_INFORMATION)if ((constants) == __null) { return (JVMTI_ERROR_ABSENT_INFORMATION ); }; | ||||||
| 2945 | |||||||
| 2946 | // in the vm localvariable table representation, 6 consecutive elements in the table | ||||||
| 2947 | // represent a 6-tuple of shorts | ||||||
| 2948 | // [start_pc, length, name_index, descriptor_index, signature_index, index] | ||||||
| 2949 | jint num_entries = method->localvariable_table_length(); | ||||||
| 2950 | jvmtiLocalVariableEntry *jvmti_table = (jvmtiLocalVariableEntry *) | ||||||
| 2951 | jvmtiMalloc(num_entries * (sizeof(jvmtiLocalVariableEntry))); | ||||||
| 2952 | |||||||
| 2953 | if (num_entries > 0) { | ||||||
| 2954 | LocalVariableTableElement* table = method->localvariable_table_start(); | ||||||
| 2955 | for (int i = 0; i < num_entries; i++) { | ||||||
| 2956 | // get the 5 tuple information from the vm table | ||||||
| 2957 | jlocation start_location = (jlocation) table[i].start_bci; | ||||||
| 2958 | jint length = (jint) table[i].length; | ||||||
| 2959 | int name_index = (int) table[i].name_cp_index; | ||||||
| 2960 | int signature_index = (int) table[i].descriptor_cp_index; | ||||||
| 2961 | int generic_signature_index = (int) table[i].signature_cp_index; | ||||||
| 2962 | jint slot = (jint) table[i].slot; | ||||||
| 2963 | |||||||
| 2964 | // get utf8 name and signature | ||||||
| 2965 | char *name_buf = NULL__null; | ||||||
| 2966 | char *sig_buf = NULL__null; | ||||||
| 2967 | char *gen_sig_buf = NULL__null; | ||||||
| 2968 | { | ||||||
| 2969 | ResourceMark rm(current_thread); | ||||||
| 2970 | |||||||
| 2971 | const char *utf8_name = (const char *) constants->symbol_at(name_index)->as_utf8(); | ||||||
| 2972 | name_buf = (char *) jvmtiMalloc(strlen(utf8_name)+1); | ||||||
| 2973 | strcpy(name_buf, utf8_name); | ||||||
| 2974 | |||||||
| 2975 | const char *utf8_signature = (const char *) constants->symbol_at(signature_index)->as_utf8(); | ||||||
| 2976 | sig_buf = (char *) jvmtiMalloc(strlen(utf8_signature)+1); | ||||||
| 2977 | strcpy(sig_buf, utf8_signature); | ||||||
| 2978 | |||||||
| 2979 | if (generic_signature_index > 0) { | ||||||
| 2980 | const char *utf8_gen_sign = (const char *) | ||||||
| 2981 | constants->symbol_at(generic_signature_index)->as_utf8(); | ||||||
| 2982 | gen_sig_buf = (char *) jvmtiMalloc(strlen(utf8_gen_sign)+1); | ||||||
| 2983 | strcpy(gen_sig_buf, utf8_gen_sign); | ||||||
| 2984 | } | ||||||
| 2985 | } | ||||||
| 2986 | |||||||
| 2987 | // fill in the jvmti local variable table | ||||||
| 2988 | jvmti_table[i].start_location = start_location; | ||||||
| 2989 | jvmti_table[i].length = length; | ||||||
| 2990 | jvmti_table[i].name = name_buf; | ||||||
| 2991 | jvmti_table[i].signature = sig_buf; | ||||||
| 2992 | jvmti_table[i].generic_signature = gen_sig_buf; | ||||||
| 2993 | jvmti_table[i].slot = slot; | ||||||
| 2994 | } | ||||||
| 2995 | } | ||||||
| 2996 | |||||||
| 2997 | // set results | ||||||
| 2998 | (*entry_count_ptr) = num_entries; | ||||||
| 2999 | (*table_ptr) = jvmti_table; | ||||||
| 3000 | |||||||
| 3001 | return JVMTI_ERROR_NONE; | ||||||
| 3002 | } /* end GetLocalVariableTable */ | ||||||
| 3003 | |||||||
| 3004 | |||||||
| 3005 | // method - pre-checked for validity, but may be NULL meaning obsolete method | ||||||
| 3006 | // bytecode_count_ptr - pre-checked for NULL | ||||||
| 3007 | // bytecodes_ptr - pre-checked for NULL | ||||||
| 3008 | jvmtiError | ||||||
| 3009 | JvmtiEnv::GetBytecodes(Method* method, jint* bytecode_count_ptr, unsigned char** bytecodes_ptr) { | ||||||
| 3010 | NULL_CHECK(method, JVMTI_ERROR_INVALID_METHODID)if ((method) == __null) { return (JVMTI_ERROR_INVALID_METHODID ); }; | ||||||
| 3011 | |||||||
| 3012 | methodHandle mh(Thread::current(), method); | ||||||
| 3013 | jint size = (jint)mh->code_size(); | ||||||
| 3014 | jvmtiError err = allocate(size, bytecodes_ptr); | ||||||
| 3015 | if (err != JVMTI_ERROR_NONE) { | ||||||
| 3016 | return err; | ||||||
| 3017 | } | ||||||
| 3018 | |||||||
| 3019 | (*bytecode_count_ptr) = size; | ||||||
| 3020 | // get byte codes | ||||||
| 3021 | JvmtiClassFileReconstituter::copy_bytecodes(mh, *bytecodes_ptr); | ||||||
| 3022 | |||||||
| 3023 | return JVMTI_ERROR_NONE; | ||||||
| 3024 | } /* end GetBytecodes */ | ||||||
| 3025 | |||||||
| 3026 | |||||||
| 3027 | // method - pre-checked for validity, but may be NULL meaning obsolete method | ||||||
| 3028 | // is_native_ptr - pre-checked for NULL | ||||||
| 3029 | jvmtiError | ||||||
| 3030 | JvmtiEnv::IsMethodNative(Method* method, jboolean* is_native_ptr) { | ||||||
| 3031 | NULL_CHECK(method, JVMTI_ERROR_INVALID_METHODID)if ((method) == __null) { return (JVMTI_ERROR_INVALID_METHODID ); }; | ||||||
| 3032 | (*is_native_ptr) = method->is_native(); | ||||||
| 3033 | return JVMTI_ERROR_NONE; | ||||||
| 3034 | } /* end IsMethodNative */ | ||||||
| 3035 | |||||||
| 3036 | |||||||
| 3037 | // method - pre-checked for validity, but may be NULL meaning obsolete method | ||||||
| 3038 | // is_synthetic_ptr - pre-checked for NULL | ||||||
| 3039 | jvmtiError | ||||||
| 3040 | JvmtiEnv::IsMethodSynthetic(Method* method, jboolean* is_synthetic_ptr) { | ||||||
| 3041 | NULL_CHECK(method, JVMTI_ERROR_INVALID_METHODID)if ((method) == __null) { return (JVMTI_ERROR_INVALID_METHODID ); }; | ||||||
| 3042 | (*is_synthetic_ptr) = method->is_synthetic(); | ||||||
| 3043 | return JVMTI_ERROR_NONE; | ||||||
| 3044 | } /* end IsMethodSynthetic */ | ||||||
| 3045 | |||||||
| 3046 | |||||||
| 3047 | // method - pre-checked for validity, but may be NULL meaning obsolete method | ||||||
| 3048 | // is_obsolete_ptr - pre-checked for NULL | ||||||
| 3049 | jvmtiError | ||||||
| 3050 | JvmtiEnv::IsMethodObsolete(Method* method, jboolean* is_obsolete_ptr) { | ||||||
| 3051 | if (use_version_1_0_semantics() && | ||||||
| 3052 | get_capabilities()->can_redefine_classes == 0) { | ||||||
| 3053 | // This JvmtiEnv requested version 1.0 semantics and this function | ||||||
| 3054 | // requires the can_redefine_classes capability in version 1.0 so | ||||||
| 3055 | // we need to return an error here. | ||||||
| 3056 | return JVMTI_ERROR_MUST_POSSESS_CAPABILITY; | ||||||
| 3057 | } | ||||||
| 3058 | |||||||
| 3059 | if (method == NULL__null || method->is_obsolete()) { | ||||||
| 3060 | *is_obsolete_ptr = true; | ||||||
| 3061 | } else { | ||||||
| 3062 | *is_obsolete_ptr = false; | ||||||
| 3063 | } | ||||||
| 3064 | return JVMTI_ERROR_NONE; | ||||||
| 3065 | } /* end IsMethodObsolete */ | ||||||
| 3066 | |||||||
| 3067 | // | ||||||
| 3068 | // Raw Monitor functions | ||||||
| 3069 | // | ||||||
| 3070 | |||||||
| 3071 | // name - pre-checked for NULL | ||||||
| 3072 | // monitor_ptr - pre-checked for NULL | ||||||
| 3073 | jvmtiError | ||||||
| 3074 | JvmtiEnv::CreateRawMonitor(const char* name, jrawMonitorID* monitor_ptr) { | ||||||
| 3075 | JvmtiRawMonitor* rmonitor = new JvmtiRawMonitor(name); | ||||||
| 3076 | NULL_CHECK(rmonitor, JVMTI_ERROR_OUT_OF_MEMORY)if ((rmonitor) == __null) { return (JVMTI_ERROR_OUT_OF_MEMORY ); }; | ||||||
| 3077 | |||||||
| 3078 | *monitor_ptr = (jrawMonitorID)rmonitor; | ||||||
| 3079 | |||||||
| 3080 | return JVMTI_ERROR_NONE; | ||||||
| 3081 | } /* end CreateRawMonitor */ | ||||||
| 3082 | |||||||
| 3083 | |||||||
| 3084 | // rmonitor - pre-checked for validity | ||||||
| 3085 | jvmtiError | ||||||
| 3086 | JvmtiEnv::DestroyRawMonitor(JvmtiRawMonitor * rmonitor) { | ||||||
| 3087 | if (Threads::number_of_threads() == 0) { | ||||||
| 3088 | // Remove this monitor from pending raw monitors list | ||||||
| 3089 | // if it has entered in onload or start phase. | ||||||
| 3090 | JvmtiPendingMonitors::destroy(rmonitor); | ||||||
| 3091 | } else { | ||||||
| 3092 | Thread* thread = Thread::current(); | ||||||
| 3093 | if (rmonitor->owner() == thread) { | ||||||
| 3094 | // The caller owns this monitor which we are about to destroy. | ||||||
| 3095 | // We exit the underlying synchronization object so that the | ||||||
| 3096 | // "delete monitor" call below can work without an assertion | ||||||
| 3097 | // failure on systems that don't like destroying synchronization | ||||||
| 3098 | // objects that are locked. | ||||||
| 3099 | int r; | ||||||
| 3100 | int recursion = rmonitor->recursions(); | ||||||
| 3101 | for (int i = 0; i <= recursion; i++) { | ||||||
| 3102 | r = rmonitor->raw_exit(thread); | ||||||
| 3103 | assert(r == JvmtiRawMonitor::M_OK, "raw_exit should have worked")do { if (!(r == JvmtiRawMonitor::M_OK)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/prims/jvmtiEnv.cpp" , 3103, "assert(" "r == JvmtiRawMonitor::M_OK" ") failed", "raw_exit should have worked" ); ::breakpoint(); } } while (0); | ||||||
| 3104 | if (r != JvmtiRawMonitor::M_OK) { // robustness | ||||||
| 3105 | return JVMTI_ERROR_INTERNAL; | ||||||
| 3106 | } | ||||||
| 3107 | } | ||||||
| 3108 | } | ||||||
| 3109 | if (rmonitor->owner() != NULL__null) { | ||||||
| 3110 | // The caller is trying to destroy a monitor that is locked by | ||||||
| 3111 | // someone else. While this is not forbidden by the JVMTI | ||||||
| 3112 | // spec, it will cause an assertion failure on systems that don't | ||||||
| 3113 | // like destroying synchronization objects that are locked. | ||||||
| 3114 | // We indicate a problem with the error return (and leak the | ||||||
| 3115 | // monitor's memory). | ||||||
| 3116 | return JVMTI_ERROR_NOT_MONITOR_OWNER; | ||||||
| 3117 | } | ||||||
| 3118 | } | ||||||
| 3119 | |||||||
| 3120 | delete rmonitor; | ||||||
| 3121 | |||||||
| 3122 | return JVMTI_ERROR_NONE; | ||||||
| 3123 | } /* end DestroyRawMonitor */ | ||||||
| 3124 | |||||||
| 3125 | |||||||
| 3126 | // rmonitor - pre-checked for validity | ||||||
| 3127 | jvmtiError | ||||||
| 3128 | JvmtiEnv::RawMonitorEnter(JvmtiRawMonitor * rmonitor) { | ||||||
| 3129 | if (Threads::number_of_threads() == 0) { | ||||||
| 3130 | // No JavaThreads exist so JvmtiRawMonitor enter cannot be | ||||||
| 3131 | // used, add this raw monitor to the pending list. | ||||||
| 3132 | // The pending monitors will be actually entered when | ||||||
| 3133 | // the VM is setup. | ||||||
| 3134 | // See transition_pending_raw_monitors in create_vm() | ||||||
| 3135 | // in thread.cpp. | ||||||
| 3136 | JvmtiPendingMonitors::enter(rmonitor); | ||||||
| 3137 | } else { | ||||||
| 3138 | Thread* thread = Thread::current(); | ||||||
| 3139 | // 8266889: raw_enter changes Java thread state, needs WXWrite | ||||||
| 3140 | MACOS_AARCH64_ONLY(ThreadWXEnable __wx(WXWrite, thread)); | ||||||
| 3141 | rmonitor->raw_enter(thread); | ||||||
| 3142 | } | ||||||
| 3143 | return JVMTI_ERROR_NONE; | ||||||
| 3144 | } /* end RawMonitorEnter */ | ||||||
| 3145 | |||||||
| 3146 | |||||||
| 3147 | // rmonitor - pre-checked for validity | ||||||
| 3148 | jvmtiError | ||||||
| 3149 | JvmtiEnv::RawMonitorExit(JvmtiRawMonitor * rmonitor) { | ||||||
| 3150 | jvmtiError err = JVMTI_ERROR_NONE; | ||||||
| 3151 | |||||||
| 3152 | if (Threads::number_of_threads() == 0) { | ||||||
| 3153 | // No JavaThreads exist so just remove this monitor from the pending list. | ||||||
| 3154 | // Bool value from exit is false if rmonitor is not in the list. | ||||||
| 3155 | if (!JvmtiPendingMonitors::exit(rmonitor)) { | ||||||
| 3156 | err = JVMTI_ERROR_NOT_MONITOR_OWNER; | ||||||
| 3157 | } | ||||||
| 3158 | } else { | ||||||
| 3159 | Thread* thread = Thread::current(); | ||||||
| 3160 | int r = rmonitor->raw_exit(thread); | ||||||
| 3161 | if (r == JvmtiRawMonitor::M_ILLEGAL_MONITOR_STATE) { | ||||||
| 3162 | err = JVMTI_ERROR_NOT_MONITOR_OWNER; | ||||||
| 3163 | } | ||||||
| 3164 | } | ||||||
| 3165 | return err; | ||||||
| 3166 | } /* end RawMonitorExit */ | ||||||
| 3167 | |||||||
| 3168 | |||||||
| 3169 | // rmonitor - pre-checked for validity | ||||||
| 3170 | jvmtiError | ||||||
| 3171 | JvmtiEnv::RawMonitorWait(JvmtiRawMonitor * rmonitor, jlong millis) { | ||||||
| 3172 | Thread* thread = Thread::current(); | ||||||
| 3173 | // 8266889: raw_wait changes Java thread state, needs WXWrite | ||||||
| 3174 | MACOS_AARCH64_ONLY(ThreadWXEnable __wx(WXWrite, thread)); | ||||||
| 3175 | int r = rmonitor->raw_wait(millis, thread); | ||||||
| 3176 | |||||||
| 3177 | switch (r) { | ||||||
| 3178 | case JvmtiRawMonitor::M_INTERRUPTED: | ||||||
| 3179 | return JVMTI_ERROR_INTERRUPT; | ||||||
| 3180 | case JvmtiRawMonitor::M_ILLEGAL_MONITOR_STATE: | ||||||
| 3181 | return JVMTI_ERROR_NOT_MONITOR_OWNER; | ||||||
| 3182 | default: | ||||||
| 3183 | return JVMTI_ERROR_NONE; | ||||||
| 3184 | } | ||||||
| 3185 | } /* end RawMonitorWait */ | ||||||
| 3186 | |||||||
| 3187 | |||||||
| 3188 | // rmonitor - pre-checked for validity | ||||||
| 3189 | jvmtiError | ||||||
| 3190 | JvmtiEnv::RawMonitorNotify(JvmtiRawMonitor * rmonitor) { | ||||||
| 3191 | Thread* thread = Thread::current(); | ||||||
| 3192 | int r = rmonitor->raw_notify(thread); | ||||||
| 3193 | |||||||
| 3194 | if (r == JvmtiRawMonitor::M_ILLEGAL_MONITOR_STATE) { | ||||||
| 3195 | return JVMTI_ERROR_NOT_MONITOR_OWNER; | ||||||
| 3196 | } | ||||||
| 3197 | return JVMTI_ERROR_NONE; | ||||||
| 3198 | } /* end RawMonitorNotify */ | ||||||
| 3199 | |||||||
| 3200 | |||||||
| 3201 | // rmonitor - pre-checked for validity | ||||||
| 3202 | jvmtiError | ||||||
| 3203 | JvmtiEnv::RawMonitorNotifyAll(JvmtiRawMonitor * rmonitor) { | ||||||
| 3204 | Thread* thread = Thread::current(); | ||||||
| 3205 | int r = rmonitor->raw_notifyAll(thread); | ||||||
| 3206 | |||||||
| 3207 | if (r == JvmtiRawMonitor::M_ILLEGAL_MONITOR_STATE) { | ||||||
| 3208 | return JVMTI_ERROR_NOT_MONITOR_OWNER; | ||||||
| 3209 | } | ||||||
| 3210 | return JVMTI_ERROR_NONE; | ||||||
| 3211 | } /* end RawMonitorNotifyAll */ | ||||||
| 3212 | |||||||
| 3213 | |||||||
| 3214 | // | ||||||
| 3215 | // JNI Function Interception functions | ||||||
| 3216 | // | ||||||
| 3217 | |||||||
| 3218 | |||||||
| 3219 | // function_table - pre-checked for NULL | ||||||
| 3220 | jvmtiError | ||||||
| 3221 | JvmtiEnv::SetJNIFunctionTable(const jniNativeInterface* function_table) { | ||||||
| 3222 | // Copy jni function table at safepoint. | ||||||
| 3223 | VM_JNIFunctionTableCopier copier(function_table); | ||||||
| 3224 | VMThread::execute(&copier); | ||||||
| 3225 | |||||||
| 3226 | return JVMTI_ERROR_NONE; | ||||||
| 3227 | } /* end SetJNIFunctionTable */ | ||||||
| 3228 | |||||||
| 3229 | |||||||
| 3230 | // function_table - pre-checked for NULL | ||||||
| 3231 | jvmtiError | ||||||
| 3232 | JvmtiEnv::GetJNIFunctionTable(jniNativeInterface** function_table) { | ||||||
| 3233 | *function_table=(jniNativeInterface*)jvmtiMalloc(sizeof(jniNativeInterface)); | ||||||
| 3234 | if (*function_table == NULL__null) | ||||||
| 3235 | return JVMTI_ERROR_OUT_OF_MEMORY; | ||||||
| 3236 | memcpy(*function_table,(JavaThread::current())->get_jni_functions(),sizeof(jniNativeInterface)); | ||||||
| 3237 | return JVMTI_ERROR_NONE; | ||||||
| 3238 | } /* end GetJNIFunctionTable */ | ||||||
| 3239 | |||||||
| 3240 | |||||||
| 3241 | // | ||||||
| 3242 | // Event Management functions | ||||||
| 3243 | // | ||||||
| 3244 | |||||||
| 3245 | jvmtiError | ||||||
| 3246 | JvmtiEnv::GenerateEvents(jvmtiEvent event_type) { | ||||||
| 3247 | // can only generate two event types | ||||||
| 3248 | if (event_type != JVMTI_EVENT_COMPILED_METHOD_LOAD && | ||||||
| 3249 | event_type != JVMTI_EVENT_DYNAMIC_CODE_GENERATED) { | ||||||
| 3250 | return JVMTI_ERROR_ILLEGAL_ARGUMENT; | ||||||
| 3251 | } | ||||||
| 3252 | |||||||
| 3253 | // for compiled_method_load events we must check that the environment | ||||||
| 3254 | // has the can_generate_compiled_method_load_events capability. | ||||||
| 3255 | if (event_type == JVMTI_EVENT_COMPILED_METHOD_LOAD) { | ||||||
| 3256 | if (get_capabilities()->can_generate_compiled_method_load_events == 0) { | ||||||
| 3257 | return JVMTI_ERROR_MUST_POSSESS_CAPABILITY; | ||||||
| 3258 | } | ||||||
| 3259 | return JvmtiCodeBlobEvents::generate_compiled_method_load_events(this); | ||||||
| 3260 | } else { | ||||||
| 3261 | return JvmtiCodeBlobEvents::generate_dynamic_code_events(this); | ||||||
| 3262 | } | ||||||
| 3263 | |||||||
| 3264 | } /* end GenerateEvents */ | ||||||
| 3265 | |||||||
| 3266 | |||||||
| 3267 | // | ||||||
| 3268 | // Extension Mechanism functions | ||||||
| 3269 | // | ||||||
| 3270 | |||||||
| 3271 | // extension_count_ptr - pre-checked for NULL | ||||||
| 3272 | // extensions - pre-checked for NULL | ||||||
| 3273 | jvmtiError | ||||||
| 3274 | JvmtiEnv::GetExtensionFunctions(jint* extension_count_ptr, jvmtiExtensionFunctionInfo** extensions) { | ||||||
| 3275 | return JvmtiExtensions::get_functions(this, extension_count_ptr, extensions); | ||||||
| 3276 | } /* end GetExtensionFunctions */ | ||||||
| 3277 | |||||||
| 3278 | |||||||
| 3279 | // extension_count_ptr - pre-checked for NULL | ||||||
| 3280 | // extensions - pre-checked for NULL | ||||||
| 3281 | jvmtiError | ||||||
| 3282 | JvmtiEnv::GetExtensionEvents(jint* extension_count_ptr, jvmtiExtensionEventInfo** extensions) { | ||||||
| 3283 | return JvmtiExtensions::get_events(this, extension_count_ptr, extensions); | ||||||
| 3284 | } /* end GetExtensionEvents */ | ||||||
| 3285 | |||||||
| 3286 | |||||||
| 3287 | // callback - NULL is a valid value, must be checked | ||||||
| 3288 | jvmtiError | ||||||
| 3289 | JvmtiEnv::SetExtensionEventCallback(jint extension_event_index, jvmtiExtensionEvent callback) { | ||||||
| 3290 | return JvmtiExtensions::set_event_callback(this, extension_event_index, callback); | ||||||
| 3291 | } /* end SetExtensionEventCallback */ | ||||||
| 3292 | |||||||
| 3293 | // | ||||||
| 3294 | // Timers functions | ||||||
| 3295 | // | ||||||
| 3296 | |||||||
| 3297 | // info_ptr - pre-checked for NULL | ||||||
| 3298 | jvmtiError | ||||||
| 3299 | JvmtiEnv::GetCurrentThreadCpuTimerInfo(jvmtiTimerInfo* info_ptr) { | ||||||
| 3300 | os::current_thread_cpu_time_info(info_ptr); | ||||||
| 3301 | return JVMTI_ERROR_NONE; | ||||||
| 3302 | } /* end GetCurrentThreadCpuTimerInfo */ | ||||||
| 3303 | |||||||
| 3304 | |||||||
| 3305 | // nanos_ptr - pre-checked for NULL | ||||||
| 3306 | jvmtiError | ||||||
| 3307 | JvmtiEnv::GetCurrentThreadCpuTime(jlong* nanos_ptr) { | ||||||
| 3308 | *nanos_ptr = os::current_thread_cpu_time(); | ||||||
| 3309 | return JVMTI_ERROR_NONE; | ||||||
| 3310 | } /* end GetCurrentThreadCpuTime */ | ||||||
| 3311 | |||||||
| 3312 | |||||||
| 3313 | // info_ptr - pre-checked for NULL | ||||||
| 3314 | jvmtiError | ||||||
| 3315 | JvmtiEnv::GetThreadCpuTimerInfo(jvmtiTimerInfo* info_ptr) { | ||||||
| 3316 | os::thread_cpu_time_info(info_ptr); | ||||||
| 3317 | return JVMTI_ERROR_NONE; | ||||||
| 3318 | } /* end GetThreadCpuTimerInfo */ | ||||||
| 3319 | |||||||
| 3320 | |||||||
| 3321 | // java_thread - protected by ThreadsListHandle and pre-checked | ||||||
| 3322 | // nanos_ptr - pre-checked for NULL | ||||||
| 3323 | jvmtiError | ||||||
| 3324 | JvmtiEnv::GetThreadCpuTime(JavaThread* java_thread, jlong* nanos_ptr) { | ||||||
| 3325 | *nanos_ptr = os::thread_cpu_time(java_thread); | ||||||
| 3326 | return JVMTI_ERROR_NONE; | ||||||
| 3327 | } /* end GetThreadCpuTime */ | ||||||
| 3328 | |||||||
| 3329 | |||||||
| 3330 | // info_ptr - pre-checked for NULL | ||||||
| 3331 | jvmtiError | ||||||
| 3332 | JvmtiEnv::GetTimerInfo(jvmtiTimerInfo* info_ptr) { | ||||||
| 3333 | os::javaTimeNanos_info(info_ptr); | ||||||
| 3334 | return JVMTI_ERROR_NONE; | ||||||
| 3335 | } /* end GetTimerInfo */ | ||||||
| 3336 | |||||||
| 3337 | |||||||
| 3338 | // nanos_ptr - pre-checked for NULL | ||||||
| 3339 | jvmtiError | ||||||
| 3340 | JvmtiEnv::GetTime(jlong* nanos_ptr) { | ||||||
| 3341 | *nanos_ptr = os::javaTimeNanos(); | ||||||
| 3342 | return JVMTI_ERROR_NONE; | ||||||
| 3343 | } /* end GetTime */ | ||||||
| 3344 | |||||||
| 3345 | |||||||
| 3346 | // processor_count_ptr - pre-checked for NULL | ||||||
| 3347 | jvmtiError | ||||||
| 3348 | JvmtiEnv::GetAvailableProcessors(jint* processor_count_ptr) { | ||||||
| 3349 | *processor_count_ptr = os::active_processor_count(); | ||||||
| 3350 | return JVMTI_ERROR_NONE; | ||||||
| 3351 | } /* end GetAvailableProcessors */ | ||||||
| 3352 | |||||||
| 3353 | jvmtiError | ||||||
| 3354 | JvmtiEnv::SetHeapSamplingInterval(jint sampling_interval) { | ||||||
| 3355 | if (sampling_interval < 0) { | ||||||
| 3356 | return JVMTI_ERROR_ILLEGAL_ARGUMENT; | ||||||
| 3357 | } | ||||||
| 3358 | ThreadHeapSampler::set_sampling_interval(sampling_interval); | ||||||
| 3359 | return JVMTI_ERROR_NONE; | ||||||
| 3360 | } /* end SetHeapSamplingInterval */ | ||||||
| 3361 | |||||||
| 3362 | // | ||||||
| 3363 | // System Properties functions | ||||||
| 3364 | // | ||||||
| 3365 | |||||||
| 3366 | // count_ptr - pre-checked for NULL | ||||||
| 3367 | // property_ptr - pre-checked for NULL | ||||||
| 3368 | jvmtiError | ||||||
| 3369 | JvmtiEnv::GetSystemProperties(jint* count_ptr, char*** property_ptr) { | ||||||
| 3370 | jvmtiError err = JVMTI_ERROR_NONE; | ||||||
| 3371 | |||||||
| 3372 | // Get the number of readable properties. | ||||||
| 3373 | *count_ptr = Arguments::PropertyList_readable_count(Arguments::system_properties()); | ||||||
| 3374 | |||||||
| 3375 | // Allocate memory to hold the exact number of readable properties. | ||||||
| 3376 | err = allocate(*count_ptr * sizeof(char *), (unsigned char **)property_ptr); | ||||||
| 3377 | if (err
| ||||||
| |||||||
| 3378 | return err; | ||||||
| 3379 | } | ||||||
| 3380 | int readable_count = 0; | ||||||
| 3381 | // Loop through the system properties until all the readable properties are found. | ||||||
| 3382 | for (SystemProperty* p = Arguments::system_properties(); p != NULL__null && readable_count < *count_ptr; p = p->next()) { | ||||||
| 3383 | if (p->is_readable()) { | ||||||
| 3384 | const char *key = p->key(); | ||||||
| 3385 | char **tmp_value = *property_ptr+readable_count; | ||||||
| 3386 | readable_count++; | ||||||
| 3387 | err = allocate((strlen(key)+1) * sizeof(char), (unsigned char**)tmp_value); | ||||||
| 3388 | if (err == JVMTI_ERROR_NONE) { | ||||||
| 3389 | strcpy(*tmp_value, key); | ||||||
| 3390 | } else { | ||||||
| 3391 | // clean up previously allocated memory. | ||||||
| 3392 | for (int j = 0; j < readable_count; j++) { | ||||||
| 3393 | Deallocate((unsigned char*)*property_ptr+j); | ||||||
| 3394 | } | ||||||
| 3395 | Deallocate((unsigned char*)property_ptr); | ||||||
| 3396 | break; | ||||||
| 3397 | } | ||||||
| 3398 | } | ||||||
| 3399 | } | ||||||
| 3400 | assert(err != JVMTI_ERROR_NONE || readable_count == *count_ptr, "Bad readable property count")do { if (!(err != JVMTI_ERROR_NONE || readable_count == *count_ptr )) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/prims/jvmtiEnv.cpp" , 3400, "assert(" "err != JVMTI_ERROR_NONE || readable_count == *count_ptr" ") failed", "Bad readable property count"); ::breakpoint(); } } while (0); | ||||||
| 3401 | return err; | ||||||
| 3402 | } /* end GetSystemProperties */ | ||||||
| 3403 | |||||||
| 3404 | |||||||
| 3405 | // property - pre-checked for NULL | ||||||
| 3406 | // value_ptr - pre-checked for NULL | ||||||
| 3407 | jvmtiError | ||||||
| 3408 | JvmtiEnv::GetSystemProperty(const char* property, char** value_ptr) { | ||||||
| 3409 | jvmtiError err = JVMTI_ERROR_NONE; | ||||||
| 3410 | const char *value; | ||||||
| 3411 | |||||||
| 3412 | // Return JVMTI_ERROR_NOT_AVAILABLE if property is not readable or doesn't exist. | ||||||
| 3413 | value = Arguments::PropertyList_get_readable_value(Arguments::system_properties(), property); | ||||||
| 3414 | if (value == NULL__null) { | ||||||
| 3415 | err = JVMTI_ERROR_NOT_AVAILABLE; | ||||||
| 3416 | } else { | ||||||
| 3417 | err = allocate((strlen(value)+1) * sizeof(char), (unsigned char **)value_ptr); | ||||||
| 3418 | if (err == JVMTI_ERROR_NONE) { | ||||||
| 3419 | strcpy(*value_ptr, value); | ||||||
| 3420 | } | ||||||
| 3421 | } | ||||||
| 3422 | return err; | ||||||
| 3423 | } /* end GetSystemProperty */ | ||||||
| 3424 | |||||||
| 3425 | |||||||
| 3426 | // property - pre-checked for NULL | ||||||
| 3427 | // value - NULL is a valid value, must be checked | ||||||
| 3428 | jvmtiError | ||||||
| 3429 | JvmtiEnv::SetSystemProperty(const char* property, const char* value_ptr) { | ||||||
| 3430 | jvmtiError err =JVMTI_ERROR_NOT_AVAILABLE; | ||||||
| 3431 | |||||||
| 3432 | for (SystemProperty* p = Arguments::system_properties(); p != NULL__null; p = p->next()) { | ||||||
| 3433 | if (strcmp(property, p->key()) == 0) { | ||||||
| 3434 | if (p->set_writeable_value(value_ptr)) { | ||||||
| 3435 | err = JVMTI_ERROR_NONE; | ||||||
| 3436 | } | ||||||
| 3437 | } | ||||||
| 3438 | } | ||||||
| 3439 | return err; | ||||||
| 3440 | } /* end SetSystemProperty */ |
| 1 | /* |
| 2 | * Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | * accompanied this code). |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License version |
| 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | * |
| 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 20 | * or visit www.oracle.com if you need additional information or have any |
| 21 | * questions. |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | #ifndef SHARE_RUNTIME_ARGUMENTS_HPP |
| 26 | #define SHARE_RUNTIME_ARGUMENTS_HPP |
| 27 | |
| 28 | #include "logging/logLevel.hpp" |
| 29 | #include "logging/logTag.hpp" |
| 30 | #include "memory/allocation.hpp" |
| 31 | #include "runtime/globals.hpp" |
| 32 | #include "runtime/java.hpp" |
| 33 | #include "runtime/os.hpp" |
| 34 | #include "utilities/debug.hpp" |
| 35 | #include "utilities/vmEnums.hpp" |
| 36 | |
| 37 | // Arguments parses the command line and recognizes options |
| 38 | |
| 39 | // Invocation API hook typedefs (these should really be defined in jni.h) |
| 40 | extern "C" { |
| 41 | typedef void (JNICALL *abort_hook_t)(void); |
| 42 | typedef void (JNICALL *exit_hook_t)(jint code); |
| 43 | typedef jint (JNICALL *vfprintf_hook_t)(FILE *fp, const char *format, va_list args) ATTRIBUTE_PRINTF(2, 0)__attribute__((format(printf, 2, 0))); |
| 44 | } |
| 45 | |
| 46 | // Obsolete or deprecated -XX flag. |
| 47 | struct SpecialFlag { |
| 48 | const char* name; |
| 49 | JDK_Version deprecated_in; // When the deprecation warning started (or "undefined"). |
| 50 | JDK_Version obsolete_in; // When the obsolete warning started (or "undefined"). |
| 51 | JDK_Version expired_in; // When the option expires (or "undefined"). |
| 52 | }; |
| 53 | |
| 54 | struct LegacyGCLogging { |
| 55 | const char* file; // NULL -> stdout |
| 56 | int lastFlag; // 0 not set; 1 -> -verbose:gc; 2 -> -Xloggc |
| 57 | }; |
| 58 | |
| 59 | // PathString is used as: |
| 60 | // - the underlying value for a SystemProperty |
| 61 | // - the path portion of an --patch-module module/path pair |
| 62 | // - the string that represents the system boot class path, Arguments::_system_boot_class_path. |
| 63 | class PathString : public CHeapObj<mtArguments> { |
| 64 | protected: |
| 65 | char* _value; |
| 66 | public: |
| 67 | char* value() const { return _value; } |
| 68 | |
| 69 | bool set_value(const char *value); |
| 70 | void append_value(const char *value); |
| 71 | |
| 72 | PathString(const char* value); |
| 73 | ~PathString(); |
| 74 | }; |
| 75 | |
| 76 | // ModulePatchPath records the module/path pair as specified to --patch-module. |
| 77 | class ModulePatchPath : public CHeapObj<mtInternal> { |
| 78 | private: |
| 79 | char* _module_name; |
| 80 | PathString* _path; |
| 81 | public: |
| 82 | ModulePatchPath(const char* module_name, const char* path); |
| 83 | ~ModulePatchPath(); |
| 84 | |
| 85 | inline void set_path(const char* path) { _path->set_value(path); } |
| 86 | inline const char* module_name() const { return _module_name; } |
| 87 | inline char* path_string() const { return _path->value(); } |
| 88 | }; |
| 89 | |
| 90 | // Element describing System and User (-Dkey=value flags) defined property. |
| 91 | // |
| 92 | // An internal SystemProperty is one that has been removed in |
| 93 | // jdk.internal.VM.saveAndRemoveProperties, like jdk.boot.class.path.append. |
| 94 | // |
| 95 | class SystemProperty : public PathString { |
| 96 | private: |
| 97 | char* _key; |
| 98 | SystemProperty* _next; |
| 99 | bool _internal; |
| 100 | bool _writeable; |
| 101 | bool writeable() { return _writeable; } |
| 102 | |
| 103 | public: |
| 104 | // Accessors |
| 105 | char* value() const { return PathString::value(); } |
| 106 | const char* key() const { return _key; } |
| 107 | bool internal() const { return _internal; } |
| 108 | SystemProperty* next() const { return _next; } |
| 109 | void set_next(SystemProperty* next) { _next = next; } |
| 110 | |
| 111 | bool is_readable() const { |
| 112 | return !_internal || strcmp(_key, "jdk.boot.class.path.append") == 0; |
| 113 | } |
| 114 | |
| 115 | // A system property should only have its value set |
| 116 | // via an external interface if it is a writeable property. |
| 117 | // The internal, non-writeable property jdk.boot.class.path.append |
| 118 | // is the only exception to this rule. It can be set externally |
| 119 | // via -Xbootclasspath/a or JVMTI OnLoad phase call to AddToBootstrapClassLoaderSearch. |
| 120 | // In those cases for jdk.boot.class.path.append, the base class |
| 121 | // set_value and append_value methods are called directly. |
| 122 | bool set_writeable_value(const char *value) { |
| 123 | if (writeable()) { |
| 124 | return set_value(value); |
| 125 | } |
| 126 | return false; |
| 127 | } |
| 128 | void append_writeable_value(const char *value) { |
| 129 | if (writeable()) { |
| 130 | append_value(value); |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | // Constructor |
| 135 | SystemProperty(const char* key, const char* value, bool writeable, bool internal = false); |
| 136 | }; |
| 137 | |
| 138 | |
| 139 | // For use by -agentlib, -agentpath and -Xrun |
| 140 | class AgentLibrary : public CHeapObj<mtArguments> { |
| 141 | friend class AgentLibraryList; |
| 142 | public: |
| 143 | // Is this library valid or not. Don't rely on os_lib == NULL as statically |
| 144 | // linked lib could have handle of RTLD_DEFAULT which == 0 on some platforms |
| 145 | enum AgentState { |
| 146 | agent_invalid = 0, |
| 147 | agent_valid = 1 |
| 148 | }; |
| 149 | |
| 150 | private: |
| 151 | char* _name; |
| 152 | char* _options; |
| 153 | void* _os_lib; |
| 154 | bool _is_absolute_path; |
| 155 | bool _is_static_lib; |
| 156 | bool _is_instrument_lib; |
| 157 | AgentState _state; |
| 158 | AgentLibrary* _next; |
| 159 | |
| 160 | public: |
| 161 | // Accessors |
| 162 | const char* name() const { return _name; } |
| 163 | char* options() const { return _options; } |
| 164 | bool is_absolute_path() const { return _is_absolute_path; } |
| 165 | void* os_lib() const { return _os_lib; } |
| 166 | void set_os_lib(void* os_lib) { _os_lib = os_lib; } |
| 167 | AgentLibrary* next() const { return _next; } |
| 168 | bool is_static_lib() const { return _is_static_lib; } |
| 169 | bool is_instrument_lib() const { return _is_instrument_lib; } |
| 170 | void set_static_lib(bool is_static_lib) { _is_static_lib = is_static_lib; } |
| 171 | bool valid() { return (_state == agent_valid); } |
| 172 | void set_valid() { _state = agent_valid; } |
| 173 | void set_invalid() { _state = agent_invalid; } |
| 174 | |
| 175 | // Constructor |
| 176 | AgentLibrary(const char* name, const char* options, bool is_absolute_path, |
| 177 | void* os_lib, bool instrument_lib=false); |
| 178 | }; |
| 179 | |
| 180 | // maintain an order of entry list of AgentLibrary |
| 181 | class AgentLibraryList { |
| 182 | private: |
| 183 | AgentLibrary* _first; |
| 184 | AgentLibrary* _last; |
| 185 | public: |
| 186 | bool is_empty() const { return _first == NULL__null; } |
| 187 | AgentLibrary* first() const { return _first; } |
| 188 | |
| 189 | // add to the end of the list |
| 190 | void add(AgentLibrary* lib) { |
| 191 | if (is_empty()) { |
| 192 | _first = _last = lib; |
| 193 | } else { |
| 194 | _last->_next = lib; |
| 195 | _last = lib; |
| 196 | } |
| 197 | lib->_next = NULL__null; |
| 198 | } |
| 199 | |
| 200 | // search for and remove a library known to be in the list |
| 201 | void remove(AgentLibrary* lib) { |
| 202 | AgentLibrary* curr; |
| 203 | AgentLibrary* prev = NULL__null; |
| 204 | for (curr = first(); curr != NULL__null; prev = curr, curr = curr->next()) { |
| 205 | if (curr == lib) { |
| 206 | break; |
| 207 | } |
| 208 | } |
| 209 | assert(curr != NULL, "always should be found")do { if (!(curr != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/arguments.hpp" , 209, "assert(" "curr != __null" ") failed", "always should be found" ); ::breakpoint(); } } while (0); |
| 210 | |
| 211 | if (curr != NULL__null) { |
| 212 | // it was found, by-pass this library |
| 213 | if (prev == NULL__null) { |
| 214 | _first = curr->_next; |
| 215 | } else { |
| 216 | prev->_next = curr->_next; |
| 217 | } |
| 218 | if (curr == _last) { |
| 219 | _last = prev; |
| 220 | } |
| 221 | curr->_next = NULL__null; |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | AgentLibraryList() { |
| 226 | _first = NULL__null; |
| 227 | _last = NULL__null; |
| 228 | } |
| 229 | }; |
| 230 | |
| 231 | // Helper class for controlling the lifetime of JavaVMInitArgs objects. |
| 232 | class ScopedVMInitArgs; |
| 233 | |
| 234 | class Arguments : AllStatic { |
| 235 | friend class VMStructs; |
| 236 | friend class JvmtiExport; |
| 237 | friend class CodeCacheExtensions; |
| 238 | friend class ArgumentsTest; |
| 239 | public: |
| 240 | // Operation modi |
| 241 | enum Mode { |
| 242 | _int, // corresponds to -Xint |
| 243 | _mixed, // corresponds to -Xmixed |
| 244 | _comp // corresponds to -Xcomp |
| 245 | }; |
| 246 | |
| 247 | enum ArgsRange { |
| 248 | arg_unreadable = -3, |
| 249 | arg_too_small = -2, |
| 250 | arg_too_big = -1, |
| 251 | arg_in_range = 0 |
| 252 | }; |
| 253 | |
| 254 | enum PropertyAppendable { |
| 255 | AppendProperty, |
| 256 | AddProperty |
| 257 | }; |
| 258 | |
| 259 | enum PropertyWriteable { |
| 260 | WriteableProperty, |
| 261 | UnwriteableProperty |
| 262 | }; |
| 263 | |
| 264 | enum PropertyInternal { |
| 265 | InternalProperty, |
| 266 | ExternalProperty |
| 267 | }; |
| 268 | |
| 269 | private: |
| 270 | |
| 271 | // a pointer to the flags file name if it is specified |
| 272 | static char* _jvm_flags_file; |
| 273 | // an array containing all flags specified in the .hotspotrc file |
| 274 | static char** _jvm_flags_array; |
| 275 | static int _num_jvm_flags; |
| 276 | // an array containing all jvm arguments specified in the command line |
| 277 | static char** _jvm_args_array; |
| 278 | static int _num_jvm_args; |
| 279 | // string containing all java command (class/jarfile name and app args) |
| 280 | static char* _java_command; |
| 281 | |
| 282 | // Property list |
| 283 | static SystemProperty* _system_properties; |
| 284 | |
| 285 | // Quick accessor to System properties in the list: |
| 286 | static SystemProperty *_sun_boot_library_path; |
| 287 | static SystemProperty *_java_library_path; |
| 288 | static SystemProperty *_java_home; |
| 289 | static SystemProperty *_java_class_path; |
| 290 | static SystemProperty *_jdk_boot_class_path_append; |
| 291 | static SystemProperty *_vm_info; |
| 292 | |
| 293 | // --patch-module=module=<file>(<pathsep><file>)* |
| 294 | // Each element contains the associated module name, path |
| 295 | // string pair as specified to --patch-module. |
| 296 | static GrowableArray<ModulePatchPath*>* _patch_mod_prefix; |
| 297 | |
| 298 | // The constructed value of the system class path after |
| 299 | // argument processing and JVMTI OnLoad additions via |
| 300 | // calls to AddToBootstrapClassLoaderSearch. This is the |
| 301 | // final form before ClassLoader::setup_bootstrap_search(). |
| 302 | // Note: since --patch-module is a module name/path pair, the |
| 303 | // system boot class path string no longer contains the "prefix" |
| 304 | // to the boot class path base piece as it did when |
| 305 | // -Xbootclasspath/p was supported. |
| 306 | static PathString *_system_boot_class_path; |
| 307 | |
| 308 | // Set if a modular java runtime image is present vs. a build with exploded modules |
| 309 | static bool _has_jimage; |
| 310 | |
| 311 | // temporary: to emit warning if the default ext dirs are not empty. |
| 312 | // remove this variable when the warning is no longer needed. |
| 313 | static char* _ext_dirs; |
| 314 | |
| 315 | // java.vendor.url.bug, bug reporting URL for fatal errors. |
| 316 | static const char* _java_vendor_url_bug; |
| 317 | |
| 318 | // sun.java.launcher, private property to provide information about |
| 319 | // java launcher |
| 320 | static const char* _sun_java_launcher; |
| 321 | |
| 322 | // was this VM created via the -XXaltjvm=<path> option |
| 323 | static bool _sun_java_launcher_is_altjvm; |
| 324 | |
| 325 | // for legacy gc options (-verbose:gc and -Xloggc:) |
| 326 | static LegacyGCLogging _legacyGCLogging; |
| 327 | |
| 328 | // Value of the conservative maximum heap alignment needed |
| 329 | static size_t _conservative_max_heap_alignment; |
| 330 | |
| 331 | // -Xrun arguments |
| 332 | static AgentLibraryList _libraryList; |
| 333 | static void add_init_library(const char* name, char* options); |
| 334 | |
| 335 | // -agentlib and -agentpath arguments |
| 336 | static AgentLibraryList _agentList; |
| 337 | static void add_init_agent(const char* name, char* options, bool absolute_path); |
| 338 | static void add_instrument_agent(const char* name, char* options, bool absolute_path); |
| 339 | |
| 340 | // Late-binding agents not started via arguments |
| 341 | static void add_loaded_agent(AgentLibrary *agentLib); |
| 342 | |
| 343 | // Operation modi |
| 344 | static Mode _mode; |
| 345 | static void set_mode_flags(Mode mode); |
| 346 | static bool _java_compiler; |
| 347 | static void set_java_compiler(bool arg) { _java_compiler = arg; } |
| 348 | static bool java_compiler() { return _java_compiler; } |
| 349 | |
| 350 | // -Xdebug flag |
| 351 | static bool _xdebug_mode; |
| 352 | static void set_xdebug_mode(bool arg) { _xdebug_mode = arg; } |
| 353 | static bool xdebug_mode() { return _xdebug_mode; } |
| 354 | |
| 355 | // preview features |
| 356 | static bool _enable_preview; |
| 357 | |
| 358 | // Used to save default settings |
| 359 | static bool _AlwaysCompileLoopMethods; |
| 360 | static bool _UseOnStackReplacement; |
| 361 | static bool _BackgroundCompilation; |
| 362 | static bool _ClipInlining; |
| 363 | |
| 364 | // GC ergonomics |
| 365 | static void set_conservative_max_heap_alignment(); |
| 366 | static void set_use_compressed_oops(); |
| 367 | static void set_use_compressed_klass_ptrs(); |
| 368 | static jint set_ergonomics_flags(); |
| 369 | static void set_shared_spaces_flags_and_archive_paths(); |
| 370 | // Limits the given heap size by the maximum amount of virtual |
| 371 | // memory this process is currently allowed to use. It also takes |
| 372 | // the virtual-to-physical ratio of the current GC into account. |
| 373 | static size_t limit_heap_by_allocatable_memory(size_t size); |
| 374 | // Setup heap size |
| 375 | static void set_heap_size(); |
| 376 | |
| 377 | // Bytecode rewriting |
| 378 | static void set_bytecode_flags(); |
| 379 | |
| 380 | // Invocation API hooks |
| 381 | static abort_hook_t _abort_hook; |
| 382 | static exit_hook_t _exit_hook; |
| 383 | static vfprintf_hook_t _vfprintf_hook; |
| 384 | |
| 385 | // System properties |
| 386 | static bool add_property(const char* prop, PropertyWriteable writeable=WriteableProperty, |
| 387 | PropertyInternal internal=ExternalProperty); |
| 388 | |
| 389 | // Used for module system related properties: converted from command-line flags. |
| 390 | // Basic properties are writeable as they operate as "last one wins" and will get overwritten. |
| 391 | // Numbered properties are never writeable, and always internal. |
| 392 | static bool create_module_property(const char* prop_name, const char* prop_value, PropertyInternal internal); |
| 393 | static bool create_numbered_module_property(const char* prop_base_name, const char* prop_value, unsigned int count); |
| 394 | |
| 395 | static int process_patch_mod_option(const char* patch_mod_tail, bool* patch_mod_javabase); |
| 396 | |
| 397 | // Aggressive optimization flags. |
| 398 | static jint set_aggressive_opts_flags(); |
| 399 | |
| 400 | static jint set_aggressive_heap_flags(); |
| 401 | |
| 402 | // Argument parsing |
| 403 | static bool parse_argument(const char* arg, JVMFlagOrigin origin); |
| 404 | static bool process_argument(const char* arg, jboolean ignore_unrecognized, JVMFlagOrigin origin); |
| 405 | static void process_java_launcher_argument(const char*, void*); |
| 406 | static void process_java_compiler_argument(const char* arg); |
| 407 | static jint parse_options_environment_variable(const char* name, ScopedVMInitArgs* vm_args); |
| 408 | static jint parse_java_tool_options_environment_variable(ScopedVMInitArgs* vm_args); |
| 409 | static jint parse_java_options_environment_variable(ScopedVMInitArgs* vm_args); |
| 410 | static jint parse_vm_options_file(const char* file_name, ScopedVMInitArgs* vm_args); |
| 411 | static jint parse_options_buffer(const char* name, char* buffer, const size_t buf_len, ScopedVMInitArgs* vm_args); |
| 412 | static jint parse_xss(const JavaVMOption* option, const char* tail, intx* out_ThreadStackSize); |
| 413 | static jint insert_vm_options_file(const JavaVMInitArgs* args, |
| 414 | const char* vm_options_file, |
| 415 | const int vm_options_file_pos, |
| 416 | ScopedVMInitArgs* vm_options_file_args, |
| 417 | ScopedVMInitArgs* args_out); |
| 418 | static bool args_contains_vm_options_file_arg(const JavaVMInitArgs* args); |
| 419 | static jint expand_vm_options_as_needed(const JavaVMInitArgs* args_in, |
| 420 | ScopedVMInitArgs* mod_args, |
| 421 | JavaVMInitArgs** args_out); |
| 422 | static jint match_special_option_and_act(const JavaVMInitArgs* args, |
| 423 | ScopedVMInitArgs* args_out); |
| 424 | |
| 425 | static bool handle_deprecated_print_gc_flags(); |
| 426 | |
| 427 | static jint parse_vm_init_args(const JavaVMInitArgs *vm_options_args, |
| 428 | const JavaVMInitArgs *java_tool_options_args, |
| 429 | const JavaVMInitArgs *java_options_args, |
| 430 | const JavaVMInitArgs *cmd_line_args); |
| 431 | static jint parse_each_vm_init_arg(const JavaVMInitArgs* args, bool* patch_mod_javabase, JVMFlagOrigin origin); |
| 432 | static jint finalize_vm_init_args(bool patch_mod_javabase); |
| 433 | static bool is_bad_option(const JavaVMOption* option, jboolean ignore, const char* option_type); |
| 434 | |
| 435 | static bool is_bad_option(const JavaVMOption* option, jboolean ignore) { |
| 436 | return is_bad_option(option, ignore, NULL__null); |
| 437 | } |
| 438 | |
| 439 | static void describe_range_error(ArgsRange errcode); |
| 440 | static ArgsRange check_memory_size(julong size, julong min_size, julong max_size); |
| 441 | static ArgsRange parse_memory_size(const char* s, julong* long_arg, |
| 442 | julong min_size, julong max_size = max_uintx); |
| 443 | |
| 444 | // methods to build strings from individual args |
| 445 | static void build_jvm_args(const char* arg); |
| 446 | static void build_jvm_flags(const char* arg); |
| 447 | static void add_string(char*** bldarray, int* count, const char* arg); |
| 448 | static const char* build_resource_string(char** args, int count); |
| 449 | |
| 450 | // Returns true if the flag is obsolete (and not yet expired). |
| 451 | // In this case the 'version' buffer is filled in with |
| 452 | // the version number when the flag became obsolete. |
| 453 | static bool is_obsolete_flag(const char* flag_name, JDK_Version* version); |
| 454 | |
| 455 | // Returns 1 if the flag is deprecated (and not yet obsolete or expired). |
| 456 | // In this case the 'version' buffer is filled in with the version number when |
| 457 | // the flag became deprecated. |
| 458 | // Returns -1 if the flag is expired or obsolete. |
| 459 | // Returns 0 otherwise. |
| 460 | static int is_deprecated_flag(const char* flag_name, JDK_Version* version); |
| 461 | |
| 462 | // Return the real name for the flag passed on the command line (either an alias name or "flag_name"). |
| 463 | static const char* real_flag_name(const char *flag_name); |
| 464 | |
| 465 | // Return the "real" name for option arg if arg is an alias, and print a warning if arg is deprecated. |
| 466 | // Return NULL if the arg has expired. |
| 467 | static const char* handle_aliases_and_deprecation(const char* arg, bool warn); |
| 468 | |
| 469 | static char* SharedArchivePath; |
| 470 | static char* SharedDynamicArchivePath; |
| 471 | static size_t _default_SharedBaseAddress; // The default value specified in globals.hpp |
| 472 | static int num_archives(const char* archive_path) NOT_CDS_RETURN_(0); |
| 473 | static void extract_shared_archive_paths(const char* archive_path, |
| 474 | char** base_archive_path, |
| 475 | char** top_archive_path) NOT_CDS_RETURN; |
| 476 | |
| 477 | public: |
| 478 | // Parses the arguments, first phase |
| 479 | static jint parse(const JavaVMInitArgs* args); |
| 480 | // Parse a string for a unsigned integer. Returns true if value |
| 481 | // is an unsigned integer greater than or equal to the minimum |
| 482 | // parameter passed and returns the value in uintx_arg. Returns |
| 483 | // false otherwise, with uintx_arg undefined. |
| 484 | static bool parse_uintx(const char* value, uintx* uintx_arg, |
| 485 | uintx min_size); |
| 486 | // Apply ergonomics |
| 487 | static jint apply_ergo(); |
| 488 | // Adjusts the arguments after the OS have adjusted the arguments |
| 489 | static jint adjust_after_os(); |
| 490 | |
| 491 | // Check consistency or otherwise of VM argument settings |
| 492 | static bool check_vm_args_consistency(); |
| 493 | // Used by os_solaris |
| 494 | static bool process_settings_file(const char* file_name, bool should_exist, jboolean ignore_unrecognized); |
| 495 | |
| 496 | static size_t conservative_max_heap_alignment() { return _conservative_max_heap_alignment; } |
| 497 | // Return the maximum size a heap with compressed oops can take |
| 498 | static size_t max_heap_for_compressed_oops(); |
| 499 | |
| 500 | // return a char* array containing all options |
| 501 | static char** jvm_flags_array() { return _jvm_flags_array; } |
| 502 | static char** jvm_args_array() { return _jvm_args_array; } |
| 503 | static int num_jvm_flags() { return _num_jvm_flags; } |
| 504 | static int num_jvm_args() { return _num_jvm_args; } |
| 505 | // return the arguments passed to the Java application |
| 506 | static const char* java_command() { return _java_command; } |
| 507 | |
| 508 | // print jvm_flags, jvm_args and java_command |
| 509 | static void print_on(outputStream* st); |
| 510 | static void print_summary_on(outputStream* st); |
| 511 | |
| 512 | // convenient methods to get and set jvm_flags_file |
| 513 | static const char* get_jvm_flags_file() { return _jvm_flags_file; } |
| 514 | static void set_jvm_flags_file(const char *value) { |
| 515 | if (_jvm_flags_file != NULL__null) { |
| 516 | os::free(_jvm_flags_file); |
| 517 | } |
| 518 | _jvm_flags_file = os::strdup_check_oom(value); |
| 519 | } |
| 520 | // convenient methods to obtain / print jvm_flags and jvm_args |
| 521 | static const char* jvm_flags() { return build_resource_string(_jvm_flags_array, _num_jvm_flags); } |
| 522 | static const char* jvm_args() { return build_resource_string(_jvm_args_array, _num_jvm_args); } |
| 523 | static void print_jvm_flags_on(outputStream* st); |
| 524 | static void print_jvm_args_on(outputStream* st); |
| 525 | |
| 526 | // -Dkey=value flags |
| 527 | static SystemProperty* system_properties() { return _system_properties; } |
| 528 | static const char* get_property(const char* key); |
| 529 | |
| 530 | // -Djava.vendor.url.bug |
| 531 | static const char* java_vendor_url_bug() { return _java_vendor_url_bug; } |
| 532 | |
| 533 | // -Dsun.java.launcher |
| 534 | static const char* sun_java_launcher() { return _sun_java_launcher; } |
| 535 | // Was VM created by a Java launcher? |
| 536 | static bool created_by_java_launcher(); |
| 537 | // -Dsun.java.launcher.is_altjvm |
| 538 | static bool sun_java_launcher_is_altjvm(); |
| 539 | |
| 540 | // -Xrun |
| 541 | static AgentLibrary* libraries() { return _libraryList.first(); } |
| 542 | static bool init_libraries_at_startup() { return !_libraryList.is_empty(); } |
| 543 | static void convert_library_to_agent(AgentLibrary* lib) |
| 544 | { _libraryList.remove(lib); |
| 545 | _agentList.add(lib); } |
| 546 | |
| 547 | // -agentlib -agentpath |
| 548 | static AgentLibrary* agents() { return _agentList.first(); } |
| 549 | static bool init_agents_at_startup() { return !_agentList.is_empty(); } |
| 550 | |
| 551 | // abort, exit, vfprintf hooks |
| 552 | static abort_hook_t abort_hook() { return _abort_hook; } |
| 553 | static exit_hook_t exit_hook() { return _exit_hook; } |
| 554 | static vfprintf_hook_t vfprintf_hook() { return _vfprintf_hook; } |
| 555 | |
| 556 | static const char* GetSharedArchivePath() { return SharedArchivePath; } |
| 557 | static const char* GetSharedDynamicArchivePath() { return SharedDynamicArchivePath; } |
| 558 | static size_t default_SharedBaseAddress() { return _default_SharedBaseAddress; } |
| 559 | // Java launcher properties |
| 560 | static void process_sun_java_launcher_properties(JavaVMInitArgs* args); |
| 561 | |
| 562 | // System properties |
| 563 | static void init_system_properties(); |
| 564 | |
| 565 | // Update/Initialize System properties after JDK version number is known |
| 566 | static void init_version_specific_system_properties(); |
| 567 | |
| 568 | // Update VM info property - called after argument parsing |
| 569 | static void update_vm_info_property(const char* vm_info) { |
| 570 | _vm_info->set_value(vm_info); |
| 571 | } |
| 572 | |
| 573 | // Property List manipulation |
| 574 | static void PropertyList_add(SystemProperty *element); |
| 575 | static void PropertyList_add(SystemProperty** plist, SystemProperty *element); |
| 576 | static void PropertyList_add(SystemProperty** plist, const char* k, const char* v, bool writeable, bool internal); |
| 577 | |
| 578 | static void PropertyList_unique_add(SystemProperty** plist, const char* k, const char* v, |
| 579 | PropertyAppendable append, PropertyWriteable writeable, |
| 580 | PropertyInternal internal); |
| 581 | static const char* PropertyList_get_value(SystemProperty* plist, const char* key); |
| 582 | static const char* PropertyList_get_readable_value(SystemProperty* plist, const char* key); |
| 583 | static int PropertyList_count(SystemProperty* pl); |
| 584 | static int PropertyList_readable_count(SystemProperty* pl); |
| 585 | static const char* PropertyList_get_key_at(SystemProperty* pl,int index); |
| 586 | static char* PropertyList_get_value_at(SystemProperty* pl,int index); |
| 587 | |
| 588 | static bool is_internal_module_property(const char* option); |
| 589 | |
| 590 | // Miscellaneous System property value getter and setters. |
| 591 | static void set_dll_dir(const char *value) { _sun_boot_library_path->set_value(value); } |
| 592 | static void set_java_home(const char *value) { _java_home->set_value(value); } |
| 593 | static void set_library_path(const char *value) { _java_library_path->set_value(value); } |
| 594 | static void set_ext_dirs(char *value) { _ext_dirs = os::strdup_check_oom(value); } |
| 595 | |
| 596 | // Set up the underlying pieces of the system boot class path |
| 597 | static void add_patch_mod_prefix(const char *module_name, const char *path, bool* patch_mod_javabase); |
| 598 | static void set_sysclasspath(const char *value, bool has_jimage) { |
| 599 | // During start up, set by os::set_boot_path() |
| 600 | assert(get_sysclasspath() == NULL, "System boot class path previously set")do { if (!(get_sysclasspath() == __null)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/arguments.hpp" , 600, "assert(" "get_sysclasspath() == __null" ") failed", "System boot class path previously set" ); ::breakpoint(); } } while (0); |
| 601 | _system_boot_class_path->set_value(value); |
| 602 | _has_jimage = has_jimage; |
| 603 | } |
| 604 | static void append_sysclasspath(const char *value) { |
| 605 | _system_boot_class_path->append_value(value); |
| 606 | _jdk_boot_class_path_append->append_value(value); |
| 607 | } |
| 608 | |
| 609 | static GrowableArray<ModulePatchPath*>* get_patch_mod_prefix() { return _patch_mod_prefix; } |
| 610 | static char* get_sysclasspath() { return _system_boot_class_path->value(); } |
| 611 | static char* get_jdk_boot_class_path_append() { return _jdk_boot_class_path_append->value(); } |
| 612 | static bool has_jimage() { return _has_jimage; } |
| 613 | |
| 614 | static char* get_java_home() { return _java_home->value(); } |
| 615 | static char* get_dll_dir() { return _sun_boot_library_path->value(); } |
| 616 | static char* get_ext_dirs() { return _ext_dirs; } |
| 617 | static char* get_appclasspath() { return _java_class_path->value(); } |
| 618 | static void fix_appclasspath(); |
| 619 | |
| 620 | static char* get_default_shared_archive_path() NOT_CDS_RETURN_(NULL); |
| 621 | static void init_shared_archive_paths() NOT_CDS_RETURN; |
| 622 | |
| 623 | // Operation modi |
| 624 | static Mode mode() { return _mode; } |
| 625 | static bool is_interpreter_only() { return mode() == _int; } |
| 626 | static bool is_compiler_only() { return mode() == _comp; } |
| 627 | |
| 628 | |
| 629 | // preview features |
| 630 | static void set_enable_preview() { _enable_preview = true; } |
| 631 | static bool enable_preview() { return _enable_preview; } |
| 632 | |
| 633 | // Utility: copies src into buf, replacing "%%" with "%" and "%p" with pid. |
| 634 | static bool copy_expand_pid(const char* src, size_t srclen, char* buf, size_t buflen); |
| 635 | |
| 636 | static void check_unsupported_dumping_properties() NOT_CDS_RETURN; |
| 637 | |
| 638 | static bool check_unsupported_cds_runtime_properties() NOT_CDS_RETURN0; |
| 639 | |
| 640 | static bool atojulong(const char *s, julong* result); |
| 641 | |
| 642 | static bool has_jfr_option() NOT_JFR_RETURN_(false); |
| 643 | |
| 644 | static bool is_dumping_archive() { return DumpSharedSpaces || DynamicDumpSharedSpaces; } |
| 645 | |
| 646 | static void assert_is_dumping_archive() { |
| 647 | assert(Arguments::is_dumping_archive(), "dump time only")do { if (!(Arguments::is_dumping_archive())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/arguments.hpp" , 647, "assert(" "Arguments::is_dumping_archive()" ") failed" , "dump time only"); ::breakpoint(); } } while (0); |
| 648 | } |
| 649 | |
| 650 | DEBUG_ONLY(static bool verify_special_jvm_flags(bool check_globals);)static bool verify_special_jvm_flags(bool check_globals); |
| 651 | }; |
| 652 | |
| 653 | // Disable options not supported in this release, with a warning if they |
| 654 | // were explicitly requested on the command-line |
| 655 | #define UNSUPPORTED_OPTION(opt)do { if (opt) { if (FLAG_IS_CMDLINE(opt)) { warning("-XX:+" "opt" " not supported in this VM"); } FLAG_SET_DEFAULT(opt, false) ; } } while(0) \ |
| 656 | do { \ |
| 657 | if (opt) { \ |
| 658 | if (FLAG_IS_CMDLINE(opt)) { \ |
| 659 | warning("-XX:+" #opt " not supported in this VM"); \ |
| 660 | } \ |
| 661 | FLAG_SET_DEFAULT(opt, false); \ |
| 662 | } \ |
| 663 | } while(0) |
| 664 | |
| 665 | // similar to UNSUPPORTED_OPTION but sets flag to NULL |
| 666 | #define UNSUPPORTED_OPTION_NULL(opt)do { if (opt) { if (FLAG_IS_CMDLINE(opt)) { warning("-XX flag " "opt" " not supported in this VM"); } FLAG_SET_DEFAULT(opt, __null ); } } while(0) \ |
| 667 | do { \ |
| 668 | if (opt) { \ |
| 669 | if (FLAG_IS_CMDLINE(opt)) { \ |
| 670 | warning("-XX flag " #opt " not supported in this VM"); \ |
| 671 | } \ |
| 672 | FLAG_SET_DEFAULT(opt, NULL__null); \ |
| 673 | } \ |
| 674 | } while(0) |
| 675 | |
| 676 | // Initialize options not supported in this release, with a warning |
| 677 | // if they were explicitly requested on the command-line |
| 678 | #define UNSUPPORTED_OPTION_INIT(opt, value)do { if (FLAG_IS_CMDLINE(opt)) { warning("-XX flag " "opt" " not supported in this VM" ); } FLAG_SET_DEFAULT(opt, value); } while(0) \ |
| 679 | do { \ |
| 680 | if (FLAG_IS_CMDLINE(opt)) { \ |
| 681 | warning("-XX flag " #opt " not supported in this VM"); \ |
| 682 | } \ |
| 683 | FLAG_SET_DEFAULT(opt, value); \ |
| 684 | } while(0) |
| 685 | |
| 686 | #endif // SHARE_RUNTIME_ARGUMENTS_HPP |
| 1 | /* | ||||||
| 2 | * Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved. | ||||||
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||||||
| 4 | * | ||||||
| 5 | * This code is free software; you can redistribute it and/or modify it | ||||||
| 6 | * under the terms of the GNU General Public License version 2 only, as | ||||||
| 7 | * published by the Free Software Foundation. | ||||||
| 8 | * | ||||||
| 9 | * This code is distributed in the hope that it will be useful, but WITHOUT | ||||||
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||||||
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||||||
| 12 | * version 2 for more details (a copy is included in the LICENSE file that | ||||||
| 13 | * accompanied this code). | ||||||
| 14 | * | ||||||
| 15 | * You should have received a copy of the GNU General Public License version | ||||||
| 16 | * 2 along with this work; if not, write to the Free Software Foundation, | ||||||
| 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||||||
| 18 | * | ||||||
| 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||||||
| 20 | * or visit www.oracle.com if you need additional information or have any | ||||||
| 21 | * questions. | ||||||
| 22 | * | ||||||
| 23 | */ | ||||||
| 24 | |||||||
| 25 | #ifndef SHARE_PRIMS_JVMTIENVBASE_HPP | ||||||
| 26 | #define SHARE_PRIMS_JVMTIENVBASE_HPP | ||||||
| 27 | |||||||
| 28 | #include "prims/jvmtiEnvThreadState.hpp" | ||||||
| 29 | #include "prims/jvmtiEventController.hpp" | ||||||
| 30 | #include "prims/jvmtiThreadState.hpp" | ||||||
| 31 | #include "oops/oopHandle.hpp" | ||||||
| 32 | #include "runtime/atomic.hpp" | ||||||
| 33 | #include "runtime/fieldDescriptor.hpp" | ||||||
| 34 | #include "runtime/frame.hpp" | ||||||
| 35 | #include "runtime/thread.hpp" | ||||||
| 36 | #include "runtime/vmOperation.hpp" | ||||||
| 37 | #include "utilities/growableArray.hpp" | ||||||
| 38 | #include "utilities/macros.hpp" | ||||||
| 39 | |||||||
| 40 | // | ||||||
| 41 | // Forward Declarations | ||||||
| 42 | // | ||||||
| 43 | |||||||
| 44 | class JvmtiEnv; | ||||||
| 45 | class JvmtiThreadState; | ||||||
| 46 | class JvmtiRawMonitor; // for jvmtiEnv.hpp | ||||||
| 47 | class JvmtiEventControllerPrivate; | ||||||
| 48 | class JvmtiTagMap; | ||||||
| 49 | |||||||
| 50 | |||||||
| 51 | |||||||
| 52 | // One JvmtiEnv object is created per jvmti attachment; | ||||||
| 53 | // done via JNI GetEnv() call. Multiple attachments are | ||||||
| 54 | // allowed in jvmti. | ||||||
| 55 | |||||||
| 56 | class JvmtiEnvBase : public CHeapObj<mtInternal> { | ||||||
| 57 | |||||||
| 58 | private: | ||||||
| 59 | |||||||
| 60 | #if INCLUDE_JVMTI1 | ||||||
| 61 | static JvmtiEnvBase* _head_environment; // head of environment list | ||||||
| 62 | #endif // INCLUDE_JVMTI | ||||||
| 63 | |||||||
| 64 | static bool _globally_initialized; | ||||||
| 65 | static jvmtiPhase _phase; | ||||||
| 66 | static volatile int _dying_thread_env_iteration_count; | ||||||
| 67 | |||||||
| 68 | public: | ||||||
| 69 | |||||||
| 70 | enum { | ||||||
| 71 | JDK15_JVMTI_VERSION = JVMTI_VERSION_1_0 + 33, /* version: 1.0.33 */ | ||||||
| 72 | JDK16_JVMTI_VERSION = JVMTI_VERSION_1_1 + 102, /* version: 1.1.102 */ | ||||||
| 73 | JDK17_JVMTI_VERSION = JVMTI_VERSION_1_2 + 2 /* version: 1.2.2 */ | ||||||
| 74 | }; | ||||||
| 75 | |||||||
| 76 | static jvmtiPhase get_phase() { return _phase; } | ||||||
| 77 | static jvmtiPhase get_phase(jvmtiEnv* env) { return ((JvmtiEnvBase*)JvmtiEnv_from_jvmti_env(env))->phase(); } | ||||||
| 78 | static void set_phase(jvmtiPhase phase) { _phase = phase; } | ||||||
| 79 | static bool is_vm_live() { return _phase == JVMTI_PHASE_LIVE; } | ||||||
| 80 | |||||||
| 81 | static void entering_dying_thread_env_iteration() { ++_dying_thread_env_iteration_count; } | ||||||
| 82 | static void leaving_dying_thread_env_iteration() { --_dying_thread_env_iteration_count; } | ||||||
| 83 | static bool is_inside_dying_thread_env_iteration(){ return _dying_thread_env_iteration_count > 0; } | ||||||
| 84 | |||||||
| 85 | private: | ||||||
| 86 | |||||||
| 87 | enum { | ||||||
| 88 | JVMTI_MAGIC = 0x71EE, | ||||||
| 89 | DISPOSED_MAGIC = 0xDEFC, | ||||||
| 90 | BAD_MAGIC = 0xDEAD | ||||||
| 91 | }; | ||||||
| 92 | |||||||
| 93 | jvmtiEnv _jvmti_external; | ||||||
| 94 | jint _magic; | ||||||
| 95 | jint _version; // version value passed to JNI GetEnv() | ||||||
| 96 | JvmtiEnvBase* _next; | ||||||
| 97 | bool _is_retransformable; | ||||||
| 98 | const void *_env_local_storage; // per env agent allocated data. | ||||||
| 99 | jvmtiEventCallbacks _event_callbacks; | ||||||
| 100 | jvmtiExtEventCallbacks _ext_event_callbacks; | ||||||
| 101 | JvmtiTagMap* volatile _tag_map; | ||||||
| 102 | JvmtiEnvEventEnable _env_event_enable; | ||||||
| 103 | jvmtiCapabilities _current_capabilities; | ||||||
| 104 | jvmtiCapabilities _prohibited_capabilities; | ||||||
| 105 | volatile bool _class_file_load_hook_ever_enabled; | ||||||
| 106 | static volatile bool _needs_clean_up; | ||||||
| 107 | char** _native_method_prefixes; | ||||||
| 108 | int _native_method_prefix_count; | ||||||
| 109 | |||||||
| 110 | protected: | ||||||
| 111 | JvmtiEnvBase(jint version); | ||||||
| 112 | ~JvmtiEnvBase(); | ||||||
| 113 | void dispose(); | ||||||
| 114 | void env_dispose(); | ||||||
| 115 | |||||||
| 116 | void set_env_local_storage(const void* data) { _env_local_storage = data; } | ||||||
| 117 | const void* get_env_local_storage() { return _env_local_storage; } | ||||||
| 118 | |||||||
| 119 | void record_class_file_load_hook_enabled(); | ||||||
| 120 | void record_first_time_class_file_load_hook_enabled(); | ||||||
| 121 | |||||||
| 122 | char** get_native_method_prefixes() { return _native_method_prefixes; } | ||||||
| 123 | int get_native_method_prefix_count() { return _native_method_prefix_count; } | ||||||
| 124 | jvmtiError set_native_method_prefixes(jint prefix_count, char** prefixes); | ||||||
| 125 | |||||||
| 126 | private: | ||||||
| 127 | friend class JvmtiEventControllerPrivate; | ||||||
| 128 | void initialize(); | ||||||
| 129 | void set_event_callbacks(const jvmtiEventCallbacks* callbacks, jint size_of_callbacks); | ||||||
| 130 | static void globally_initialize(); | ||||||
| 131 | static void periodic_clean_up(); | ||||||
| 132 | |||||||
| 133 | friend class JvmtiEnvIterator; | ||||||
| 134 | JvmtiEnv* next_environment() { return (JvmtiEnv*)_next; } | ||||||
| 135 | void set_next_environment(JvmtiEnvBase* env) { _next = env; } | ||||||
| 136 | static JvmtiEnv* head_environment() { | ||||||
| 137 | JVMTI_ONLY(return (JvmtiEnv*)_head_environment)return (JvmtiEnv*)_head_environment; | ||||||
| 138 | NOT_JVMTI(return NULL); | ||||||
| 139 | } | ||||||
| 140 | |||||||
| 141 | public: | ||||||
| 142 | |||||||
| 143 | jvmtiPhase phase(); | ||||||
| 144 | bool is_valid(); | ||||||
| 145 | |||||||
| 146 | bool use_version_1_0_semantics(); // agent asked for version 1.0 | ||||||
| 147 | bool use_version_1_1_semantics(); // agent asked for version 1.1 | ||||||
| 148 | bool use_version_1_2_semantics(); // agent asked for version 1.2 | ||||||
| 149 | |||||||
| 150 | bool is_retransformable() { return _is_retransformable; } | ||||||
| 151 | |||||||
| 152 | static ByteSize jvmti_external_offset() { | ||||||
| 153 | return byte_offset_of(JvmtiEnvBase, _jvmti_external)in_ByteSize((int)(size_t)((intx)&(((JvmtiEnvBase*)16)-> _jvmti_external) - 16)); | ||||||
| 154 | }; | ||||||
| 155 | |||||||
| 156 | static JvmtiEnv* JvmtiEnv_from_jvmti_env(jvmtiEnv *env) { | ||||||
| 157 | return (JvmtiEnv*)((intptr_t)env - in_bytes(jvmti_external_offset())); | ||||||
| 158 | }; | ||||||
| 159 | |||||||
| 160 | jvmtiCapabilities *get_capabilities() { return &_current_capabilities; } | ||||||
| 161 | |||||||
| 162 | jvmtiCapabilities *get_prohibited_capabilities() { return &_prohibited_capabilities; } | ||||||
| 163 | |||||||
| 164 | bool early_class_hook_env() { | ||||||
| 165 | return get_capabilities()->can_generate_early_class_hook_events != 0 | ||||||
| 166 | && get_capabilities()->can_generate_all_class_hook_events != 0; | ||||||
| 167 | } | ||||||
| 168 | |||||||
| 169 | bool early_vmstart_env() { | ||||||
| 170 | return get_capabilities()->can_generate_early_vmstart != 0; | ||||||
| 171 | } | ||||||
| 172 | |||||||
| 173 | static char** get_all_native_method_prefixes(int* count_ptr); | ||||||
| 174 | |||||||
| 175 | // This test will answer true when all environments have been disposed and some have | ||||||
| 176 | // not yet been deallocated. As a result, this test should only be used as an | ||||||
| 177 | // optimization for the no environment case. | ||||||
| 178 | static bool environments_might_exist() { | ||||||
| 179 | return head_environment() != NULL__null; | ||||||
| 180 | } | ||||||
| 181 | |||||||
| 182 | static void check_for_periodic_clean_up(); | ||||||
| 183 | |||||||
| 184 | JvmtiEnvEventEnable *env_event_enable() { | ||||||
| 185 | return &_env_event_enable; | ||||||
| 186 | } | ||||||
| 187 | |||||||
| 188 | jvmtiError allocate(jlong size, unsigned char** mem_ptr) { | ||||||
| 189 | if (size
| ||||||
| 190 | return JVMTI_ERROR_ILLEGAL_ARGUMENT; | ||||||
| 191 | } | ||||||
| 192 | if (size
| ||||||
| 193 | *mem_ptr = NULL__null; | ||||||
| 194 | } else { | ||||||
| 195 | *mem_ptr = (unsigned char *)os::malloc((size_t)size, mtInternal); | ||||||
| |||||||
| 196 | if (*mem_ptr == NULL__null) { | ||||||
| 197 | return JVMTI_ERROR_OUT_OF_MEMORY; | ||||||
| 198 | } | ||||||
| 199 | } | ||||||
| 200 | return JVMTI_ERROR_NONE; | ||||||
| 201 | } | ||||||
| 202 | |||||||
| 203 | jvmtiError deallocate(unsigned char* mem) { | ||||||
| 204 | if (mem != NULL__null) { | ||||||
| 205 | os::free(mem); | ||||||
| 206 | } | ||||||
| 207 | return JVMTI_ERROR_NONE; | ||||||
| 208 | } | ||||||
| 209 | |||||||
| 210 | |||||||
| 211 | // Memory functions | ||||||
| 212 | unsigned char* jvmtiMalloc(jlong size); // don't use this - call allocate | ||||||
| 213 | |||||||
| 214 | // method to create a local handle | ||||||
| 215 | jobject jni_reference(Handle hndl); | ||||||
| 216 | |||||||
| 217 | // method to create a local handle. | ||||||
| 218 | // This function allows caller to specify which | ||||||
| 219 | // threads local handle table to use. | ||||||
| 220 | jobject jni_reference(JavaThread *thread, Handle hndl); | ||||||
| 221 | |||||||
| 222 | // method to destroy a local handle | ||||||
| 223 | void destroy_jni_reference(jobject jobj); | ||||||
| 224 | |||||||
| 225 | // method to destroy a local handle. | ||||||
| 226 | // This function allows caller to specify which | ||||||
| 227 | // threads local handle table to use. | ||||||
| 228 | void destroy_jni_reference(JavaThread *thread, jobject jobj); | ||||||
| 229 | |||||||
| 230 | jvmtiEnv* jvmti_external() { return &_jvmti_external; }; | ||||||
| 231 | |||||||
| 232 | // Event Dispatch | ||||||
| 233 | |||||||
| 234 | bool has_callback(jvmtiEvent event_type) { | ||||||
| 235 | assert(event_type >= JVMTI_MIN_EVENT_TYPE_VAL &&do { if (!(event_type >= JVMTI_MIN_EVENT_TYPE_VAL && event_type <= JVMTI_MAX_EVENT_TYPE_VAL)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/prims/jvmtiEnvBase.hpp" , 236, "assert(" "event_type >= JVMTI_MIN_EVENT_TYPE_VAL && event_type <= JVMTI_MAX_EVENT_TYPE_VAL" ") failed", "checking"); ::breakpoint(); } } while (0) | ||||||
| 236 | event_type <= JVMTI_MAX_EVENT_TYPE_VAL, "checking")do { if (!(event_type >= JVMTI_MIN_EVENT_TYPE_VAL && event_type <= JVMTI_MAX_EVENT_TYPE_VAL)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/prims/jvmtiEnvBase.hpp" , 236, "assert(" "event_type >= JVMTI_MIN_EVENT_TYPE_VAL && event_type <= JVMTI_MAX_EVENT_TYPE_VAL" ") failed", "checking"); ::breakpoint(); } } while (0); | ||||||
| 237 | return ((void**)&_event_callbacks)[event_type-JVMTI_MIN_EVENT_TYPE_VAL] != NULL__null; | ||||||
| 238 | } | ||||||
| 239 | |||||||
| 240 | jvmtiEventCallbacks* callbacks() { | ||||||
| 241 | return &_event_callbacks; | ||||||
| 242 | } | ||||||
| 243 | |||||||
| 244 | jvmtiExtEventCallbacks* ext_callbacks() { | ||||||
| 245 | return &_ext_event_callbacks; | ||||||
| 246 | } | ||||||
| 247 | |||||||
| 248 | void set_tag_map(JvmtiTagMap* tag_map) { | ||||||
| 249 | _tag_map = tag_map; | ||||||
| 250 | } | ||||||
| 251 | |||||||
| 252 | JvmtiTagMap* tag_map() { | ||||||
| 253 | return _tag_map; | ||||||
| 254 | } | ||||||
| 255 | |||||||
| 256 | JvmtiTagMap* tag_map_acquire() { | ||||||
| 257 | return Atomic::load_acquire(&_tag_map); | ||||||
| 258 | } | ||||||
| 259 | |||||||
| 260 | void release_set_tag_map(JvmtiTagMap* tag_map) { | ||||||
| 261 | Atomic::release_store(&_tag_map, tag_map); | ||||||
| 262 | } | ||||||
| 263 | |||||||
| 264 | // return true if event is enabled globally or for any thread | ||||||
| 265 | // True only if there is a callback for it. | ||||||
| 266 | bool is_enabled(jvmtiEvent event_type) { | ||||||
| 267 | return _env_event_enable.is_enabled(event_type); | ||||||
| 268 | } | ||||||
| 269 | |||||||
| 270 | // Random Utilities | ||||||
| 271 | |||||||
| 272 | protected: | ||||||
| 273 | // helper methods for creating arrays of global JNI Handles from local Handles | ||||||
| 274 | // allocated into environment specific storage | ||||||
| 275 | jobject * new_jobjectArray(int length, Handle *handles); | ||||||
| 276 | jthread * new_jthreadArray(int length, Handle *handles); | ||||||
| 277 | jthreadGroup * new_jthreadGroupArray(int length, Handle *handles); | ||||||
| 278 | |||||||
| 279 | // convert to a jni jclass from a non-null Klass* | ||||||
| 280 | jclass get_jni_class_non_null(Klass* k); | ||||||
| 281 | |||||||
| 282 | jint count_locked_objects(JavaThread *java_thread, Handle hobj); | ||||||
| 283 | jvmtiError get_locked_objects_in_frame(JavaThread *calling_thread, | ||||||
| 284 | JavaThread* java_thread, | ||||||
| 285 | javaVFrame *jvf, | ||||||
| 286 | GrowableArray<jvmtiMonitorStackDepthInfo*>* owned_monitors_list, | ||||||
| 287 | jint depth); | ||||||
| 288 | public: | ||||||
| 289 | static vframe* vframeForNoProcess(JavaThread* java_thread, jint depth); | ||||||
| 290 | |||||||
| 291 | // get a field descriptor for the specified class and field | ||||||
| 292 | static bool get_field_descriptor(Klass* k, jfieldID field, fieldDescriptor* fd); | ||||||
| 293 | |||||||
| 294 | // JVMTI API helper functions which are called when target thread is suspended | ||||||
| 295 | // or at safepoint / thread local handshake. | ||||||
| 296 | jvmtiError get_frame_count(JvmtiThreadState *state, jint *count_ptr); | ||||||
| 297 | jvmtiError get_frame_location(JavaThread* java_thread, jint depth, | ||||||
| 298 | jmethodID* method_ptr, jlocation* location_ptr); | ||||||
| 299 | jvmtiError get_object_monitor_usage(JavaThread *calling_thread, | ||||||
| 300 | jobject object, jvmtiMonitorUsage* info_ptr); | ||||||
| 301 | jvmtiError get_stack_trace(JavaThread *java_thread, | ||||||
| 302 | jint stack_depth, jint max_count, | ||||||
| 303 | jvmtiFrameInfo* frame_buffer, jint* count_ptr); | ||||||
| 304 | jvmtiError get_current_contended_monitor(JavaThread *calling_thread, JavaThread *java_thread, | ||||||
| 305 | jobject *monitor_ptr); | ||||||
| 306 | jvmtiError get_owned_monitors(JavaThread *calling_thread, JavaThread* java_thread, | ||||||
| 307 | GrowableArray<jvmtiMonitorStackDepthInfo*> *owned_monitors_list); | ||||||
| 308 | static jvmtiError check_top_frame(Thread* current_thread, JavaThread* java_thread, | ||||||
| 309 | jvalue value, TosState tos, Handle* ret_ob_h); | ||||||
| 310 | jvmtiError force_early_return(JavaThread* java_thread, jvalue value, TosState tos); | ||||||
| 311 | }; | ||||||
| 312 | |||||||
| 313 | // This class is the only safe means of iterating through environments. | ||||||
| 314 | // Note that this iteratation includes invalid environments pending | ||||||
| 315 | // deallocation -- in fact, some uses depend on this behavior. | ||||||
| 316 | |||||||
| 317 | class JvmtiEnvIterator : public StackObj { | ||||||
| 318 | private: | ||||||
| 319 | bool _entry_was_marked; | ||||||
| 320 | public: | ||||||
| 321 | JvmtiEnvIterator() { | ||||||
| 322 | if (Threads::number_of_threads() == 0) { | ||||||
| 323 | _entry_was_marked = false; // we are single-threaded, no need | ||||||
| 324 | } else { | ||||||
| 325 | Thread::current()->entering_jvmti_env_iteration(); | ||||||
| 326 | _entry_was_marked = true; | ||||||
| 327 | } | ||||||
| 328 | } | ||||||
| 329 | ~JvmtiEnvIterator() { | ||||||
| 330 | if (_entry_was_marked) { | ||||||
| 331 | Thread::current()->leaving_jvmti_env_iteration(); | ||||||
| 332 | } | ||||||
| 333 | } | ||||||
| 334 | JvmtiEnv* first() { return JvmtiEnvBase::head_environment(); } | ||||||
| 335 | JvmtiEnv* next(JvmtiEnvBase* env) { return env->next_environment(); } | ||||||
| 336 | }; | ||||||
| 337 | |||||||
| 338 | class JvmtiHandshakeClosure : public HandshakeClosure { | ||||||
| 339 | protected: | ||||||
| 340 | jvmtiError _result; | ||||||
| 341 | public: | ||||||
| 342 | JvmtiHandshakeClosure(const char* name) | ||||||
| 343 | : HandshakeClosure(name), | ||||||
| 344 | _result(JVMTI_ERROR_THREAD_NOT_ALIVE) {} | ||||||
| 345 | jvmtiError result() { return _result; } | ||||||
| 346 | }; | ||||||
| 347 | |||||||
| 348 | class SetForceEarlyReturn : public JvmtiHandshakeClosure { | ||||||
| 349 | private: | ||||||
| 350 | JvmtiThreadState* _state; | ||||||
| 351 | jvalue _value; | ||||||
| 352 | TosState _tos; | ||||||
| 353 | public: | ||||||
| 354 | SetForceEarlyReturn(JvmtiThreadState* state, jvalue value, TosState tos) | ||||||
| 355 | : JvmtiHandshakeClosure("SetForceEarlyReturn"), | ||||||
| 356 | _state(state), | ||||||
| 357 | _value(value), | ||||||
| 358 | _tos(tos) {} | ||||||
| 359 | void do_thread(Thread *target) { | ||||||
| 360 | doit(target, false /* self */); | ||||||
| 361 | } | ||||||
| 362 | void doit(Thread *target, bool self); | ||||||
| 363 | }; | ||||||
| 364 | |||||||
| 365 | // HandshakeClosure to update for pop top frame. | ||||||
| 366 | class UpdateForPopTopFrameClosure : public JvmtiHandshakeClosure { | ||||||
| 367 | private: | ||||||
| 368 | JvmtiThreadState* _state; | ||||||
| 369 | |||||||
| 370 | public: | ||||||
| 371 | UpdateForPopTopFrameClosure(JvmtiThreadState* state) | ||||||
| 372 | : JvmtiHandshakeClosure("UpdateForPopTopFrame"), | ||||||
| 373 | _state(state) {} | ||||||
| 374 | void do_thread(Thread *target) { | ||||||
| 375 | doit(target, false /* self */); | ||||||
| 376 | } | ||||||
| 377 | void doit(Thread *target, bool self); | ||||||
| 378 | }; | ||||||
| 379 | |||||||
| 380 | // HandshakeClosure to set frame pop. | ||||||
| 381 | class SetFramePopClosure : public JvmtiHandshakeClosure { | ||||||
| 382 | private: | ||||||
| 383 | JvmtiEnv *_env; | ||||||
| 384 | JvmtiThreadState* _state; | ||||||
| 385 | jint _depth; | ||||||
| 386 | |||||||
| 387 | public: | ||||||
| 388 | SetFramePopClosure(JvmtiEnv *env, JvmtiThreadState* state, jint depth) | ||||||
| 389 | : JvmtiHandshakeClosure("SetFramePop"), | ||||||
| 390 | _env(env), | ||||||
| 391 | _state(state), | ||||||
| 392 | _depth(depth) {} | ||||||
| 393 | void do_thread(Thread *target) { | ||||||
| 394 | doit(target, false /* self */); | ||||||
| 395 | } | ||||||
| 396 | void doit(Thread *target, bool self); | ||||||
| 397 | }; | ||||||
| 398 | |||||||
| 399 | // HandshakeClosure to get monitor information with stack depth. | ||||||
| 400 | class GetOwnedMonitorInfoClosure : public JvmtiHandshakeClosure { | ||||||
| 401 | private: | ||||||
| 402 | JavaThread* _calling_thread; | ||||||
| 403 | JvmtiEnv *_env; | ||||||
| 404 | GrowableArray<jvmtiMonitorStackDepthInfo*> *_owned_monitors_list; | ||||||
| 405 | |||||||
| 406 | public: | ||||||
| 407 | GetOwnedMonitorInfoClosure(JavaThread* calling_thread, JvmtiEnv* env, | ||||||
| 408 | GrowableArray<jvmtiMonitorStackDepthInfo*>* owned_monitor_list) | ||||||
| 409 | : JvmtiHandshakeClosure("GetOwnedMonitorInfo"), | ||||||
| 410 | _calling_thread(calling_thread), | ||||||
| 411 | _env(env), | ||||||
| 412 | _owned_monitors_list(owned_monitor_list) {} | ||||||
| 413 | void do_thread(Thread *target); | ||||||
| 414 | }; | ||||||
| 415 | |||||||
| 416 | |||||||
| 417 | // VM operation to get object monitor usage. | ||||||
| 418 | class VM_GetObjectMonitorUsage : public VM_Operation { | ||||||
| 419 | private: | ||||||
| 420 | JvmtiEnv *_env; | ||||||
| 421 | jobject _object; | ||||||
| 422 | JavaThread* _calling_thread; | ||||||
| 423 | jvmtiMonitorUsage* _info_ptr; | ||||||
| 424 | jvmtiError _result; | ||||||
| 425 | |||||||
| 426 | public: | ||||||
| 427 | VM_GetObjectMonitorUsage(JvmtiEnv *env, JavaThread* calling_thread, jobject object, jvmtiMonitorUsage* info_ptr) { | ||||||
| 428 | _env = env; | ||||||
| 429 | _object = object; | ||||||
| 430 | _calling_thread = calling_thread; | ||||||
| 431 | _info_ptr = info_ptr; | ||||||
| 432 | } | ||||||
| 433 | VMOp_Type type() const { return VMOp_GetObjectMonitorUsage; } | ||||||
| 434 | jvmtiError result() { return _result; } | ||||||
| 435 | void doit() { | ||||||
| 436 | _result = ((JvmtiEnvBase*) _env)->get_object_monitor_usage(_calling_thread, _object, _info_ptr); | ||||||
| 437 | } | ||||||
| 438 | |||||||
| 439 | }; | ||||||
| 440 | |||||||
| 441 | // HandshakeClosure to get current contended monitor. | ||||||
| 442 | class GetCurrentContendedMonitorClosure : public JvmtiHandshakeClosure { | ||||||
| 443 | private: | ||||||
| 444 | JavaThread *_calling_thread; | ||||||
| 445 | JvmtiEnv *_env; | ||||||
| 446 | jobject *_owned_monitor_ptr; | ||||||
| 447 | |||||||
| 448 | public: | ||||||
| 449 | GetCurrentContendedMonitorClosure(JavaThread* calling_thread, JvmtiEnv *env, jobject *mon_ptr) | ||||||
| 450 | : JvmtiHandshakeClosure("GetCurrentContendedMonitor"), | ||||||
| 451 | _calling_thread(calling_thread), | ||||||
| 452 | _env(env), | ||||||
| 453 | _owned_monitor_ptr(mon_ptr) {} | ||||||
| 454 | void do_thread(Thread *target); | ||||||
| 455 | }; | ||||||
| 456 | |||||||
| 457 | // HandshakeClosure to get stack trace. | ||||||
| 458 | class GetStackTraceClosure : public JvmtiHandshakeClosure { | ||||||
| 459 | private: | ||||||
| 460 | JvmtiEnv *_env; | ||||||
| 461 | jint _start_depth; | ||||||
| 462 | jint _max_count; | ||||||
| 463 | jvmtiFrameInfo *_frame_buffer; | ||||||
| 464 | jint *_count_ptr; | ||||||
| 465 | |||||||
| 466 | public: | ||||||
| 467 | GetStackTraceClosure(JvmtiEnv *env, jint start_depth, jint max_count, | ||||||
| 468 | jvmtiFrameInfo* frame_buffer, jint* count_ptr) | ||||||
| 469 | : JvmtiHandshakeClosure("GetStackTrace"), | ||||||
| 470 | _env(env), | ||||||
| 471 | _start_depth(start_depth), | ||||||
| 472 | _max_count(max_count), | ||||||
| 473 | _frame_buffer(frame_buffer), | ||||||
| 474 | _count_ptr(count_ptr) {} | ||||||
| 475 | void do_thread(Thread *target); | ||||||
| 476 | }; | ||||||
| 477 | |||||||
| 478 | // forward declaration | ||||||
| 479 | struct StackInfoNode; | ||||||
| 480 | |||||||
| 481 | // Get stack trace at safepoint or at direct handshake. | ||||||
| 482 | class MultipleStackTracesCollector { | ||||||
| 483 | private: | ||||||
| 484 | JvmtiEnv *_env; | ||||||
| 485 | jint _max_frame_count; | ||||||
| 486 | jvmtiStackInfo *_stack_info; | ||||||
| 487 | jvmtiError _result; | ||||||
| 488 | int _frame_count_total; | ||||||
| 489 | struct StackInfoNode *_head; | ||||||
| 490 | |||||||
| 491 | JvmtiEnvBase *env() { return (JvmtiEnvBase *)_env; } | ||||||
| 492 | jint max_frame_count() { return _max_frame_count; } | ||||||
| 493 | struct StackInfoNode *head() { return _head; } | ||||||
| 494 | void set_head(StackInfoNode *head) { _head = head; } | ||||||
| 495 | |||||||
| 496 | public: | ||||||
| 497 | MultipleStackTracesCollector(JvmtiEnv *env, jint max_frame_count) | ||||||
| 498 | : _env(env), | ||||||
| 499 | _max_frame_count(max_frame_count), | ||||||
| 500 | _stack_info(NULL__null), | ||||||
| 501 | _result(JVMTI_ERROR_NONE), | ||||||
| 502 | _frame_count_total(0), | ||||||
| 503 | _head(NULL__null) { | ||||||
| 504 | } | ||||||
| 505 | void set_result(jvmtiError result) { _result = result; } | ||||||
| 506 | void fill_frames(jthread jt, JavaThread *thr, oop thread_oop); | ||||||
| 507 | void allocate_and_fill_stacks(jint thread_count); | ||||||
| 508 | jvmtiStackInfo *stack_info() { return _stack_info; } | ||||||
| 509 | jvmtiError result() { return _result; } | ||||||
| 510 | }; | ||||||
| 511 | |||||||
| 512 | |||||||
| 513 | // VM operation to get stack trace at safepoint. | ||||||
| 514 | class VM_GetAllStackTraces : public VM_Operation { | ||||||
| 515 | private: | ||||||
| 516 | JavaThread *_calling_thread; | ||||||
| 517 | jint _final_thread_count; | ||||||
| 518 | MultipleStackTracesCollector _collector; | ||||||
| 519 | |||||||
| 520 | public: | ||||||
| 521 | VM_GetAllStackTraces(JvmtiEnv *env, JavaThread *calling_thread, | ||||||
| 522 | jint max_frame_count) | ||||||
| 523 | : _calling_thread(calling_thread), | ||||||
| 524 | _final_thread_count(0), | ||||||
| 525 | _collector(env, max_frame_count) { | ||||||
| 526 | } | ||||||
| 527 | VMOp_Type type() const { return VMOp_GetAllStackTraces; } | ||||||
| 528 | void doit(); | ||||||
| 529 | jint final_thread_count() { return _final_thread_count; } | ||||||
| 530 | jvmtiStackInfo *stack_info() { return _collector.stack_info(); } | ||||||
| 531 | jvmtiError result() { return _collector.result(); } | ||||||
| 532 | }; | ||||||
| 533 | |||||||
| 534 | // VM operation to get stack trace at safepoint. | ||||||
| 535 | class VM_GetThreadListStackTraces : public VM_Operation { | ||||||
| 536 | private: | ||||||
| 537 | jint _thread_count; | ||||||
| 538 | const jthread* _thread_list; | ||||||
| 539 | MultipleStackTracesCollector _collector; | ||||||
| 540 | |||||||
| 541 | public: | ||||||
| 542 | VM_GetThreadListStackTraces(JvmtiEnv *env, jint thread_count, const jthread* thread_list, jint max_frame_count) | ||||||
| 543 | : _thread_count(thread_count), | ||||||
| 544 | _thread_list(thread_list), | ||||||
| 545 | _collector(env, max_frame_count) { | ||||||
| 546 | } | ||||||
| 547 | VMOp_Type type() const { return VMOp_GetThreadListStackTraces; } | ||||||
| 548 | void doit(); | ||||||
| 549 | jvmtiStackInfo *stack_info() { return _collector.stack_info(); } | ||||||
| 550 | jvmtiError result() { return _collector.result(); } | ||||||
| 551 | }; | ||||||
| 552 | |||||||
| 553 | // HandshakeClosure to get single stack trace. | ||||||
| 554 | class GetSingleStackTraceClosure : public HandshakeClosure { | ||||||
| 555 | private: | ||||||
| 556 | JavaThread *_calling_thread; | ||||||
| 557 | jthread _jthread; | ||||||
| 558 | MultipleStackTracesCollector _collector; | ||||||
| 559 | |||||||
| 560 | public: | ||||||
| 561 | GetSingleStackTraceClosure(JvmtiEnv *env, JavaThread *calling_thread, | ||||||
| 562 | jthread thread, jint max_frame_count) | ||||||
| 563 | : HandshakeClosure("GetSingleStackTrace"), | ||||||
| 564 | _calling_thread(calling_thread), | ||||||
| 565 | _jthread(thread), | ||||||
| 566 | _collector(env, max_frame_count) { | ||||||
| 567 | } | ||||||
| 568 | void do_thread(Thread *target); | ||||||
| 569 | jvmtiStackInfo *stack_info() { return _collector.stack_info(); } | ||||||
| 570 | jvmtiError result() { return _collector.result(); } | ||||||
| 571 | }; | ||||||
| 572 | |||||||
| 573 | // HandshakeClosure to count stack frames. | ||||||
| 574 | class GetFrameCountClosure : public JvmtiHandshakeClosure { | ||||||
| 575 | private: | ||||||
| 576 | JvmtiEnv *_env; | ||||||
| 577 | JvmtiThreadState *_state; | ||||||
| 578 | jint *_count_ptr; | ||||||
| 579 | |||||||
| 580 | public: | ||||||
| 581 | GetFrameCountClosure(JvmtiEnv *env, JvmtiThreadState *state, jint *count_ptr) | ||||||
| 582 | : JvmtiHandshakeClosure("GetFrameCount"), | ||||||
| 583 | _env(env), | ||||||
| 584 | _state(state), | ||||||
| 585 | _count_ptr(count_ptr) {} | ||||||
| 586 | void do_thread(Thread *target); | ||||||
| 587 | }; | ||||||
| 588 | |||||||
| 589 | // HandshakeClosure to get frame location. | ||||||
| 590 | class GetFrameLocationClosure : public JvmtiHandshakeClosure { | ||||||
| 591 | private: | ||||||
| 592 | JvmtiEnv *_env; | ||||||
| 593 | jint _depth; | ||||||
| 594 | jmethodID* _method_ptr; | ||||||
| 595 | jlocation* _location_ptr; | ||||||
| 596 | |||||||
| 597 | public: | ||||||
| 598 | GetFrameLocationClosure(JvmtiEnv *env, jint depth, | ||||||
| 599 | jmethodID* method_ptr, jlocation* location_ptr) | ||||||
| 600 | : JvmtiHandshakeClosure("GetFrameLocation"), | ||||||
| 601 | _env(env), | ||||||
| 602 | _depth(depth), | ||||||
| 603 | _method_ptr(method_ptr), | ||||||
| 604 | _location_ptr(location_ptr) {} | ||||||
| 605 | void do_thread(Thread *target); | ||||||
| 606 | }; | ||||||
| 607 | |||||||
| 608 | |||||||
| 609 | // ResourceTracker | ||||||
| 610 | // | ||||||
| 611 | // ResourceTracker works a little like a ResourceMark. All allocates | ||||||
| 612 | // using the resource tracker are recorded. If an allocate using the | ||||||
| 613 | // resource tracker fails the destructor will free any resources | ||||||
| 614 | // that were allocated using the tracker. | ||||||
| 615 | // The motive for this class is to avoid messy error recovery code | ||||||
| 616 | // in situations where multiple allocations are done in sequence. If | ||||||
| 617 | // the second or subsequent allocation fails it avoids any code to | ||||||
| 618 | // release memory allocated in the previous calls. | ||||||
| 619 | // | ||||||
| 620 | // Usage :- | ||||||
| 621 | // ResourceTracker rt(env); | ||||||
| 622 | // : | ||||||
| 623 | // err = rt.allocate(1024, &ptr); | ||||||
| 624 | |||||||
| 625 | class ResourceTracker : public StackObj { | ||||||
| 626 | private: | ||||||
| 627 | JvmtiEnv* _env; | ||||||
| 628 | GrowableArray<unsigned char*> *_allocations; | ||||||
| 629 | bool _failed; | ||||||
| 630 | public: | ||||||
| 631 | ResourceTracker(JvmtiEnv* env); | ||||||
| 632 | ~ResourceTracker(); | ||||||
| 633 | jvmtiError allocate(jlong size, unsigned char** mem_ptr); | ||||||
| 634 | unsigned char* allocate(jlong size); | ||||||
| 635 | char* strdup(const char* str); | ||||||
| 636 | }; | ||||||
| 637 | |||||||
| 638 | |||||||
| 639 | // Jvmti monitor closure to collect off stack monitors. | ||||||
| 640 | class JvmtiMonitorClosure: public MonitorClosure { | ||||||
| 641 | private: | ||||||
| 642 | JavaThread *_calling_thread; | ||||||
| 643 | GrowableArray<jvmtiMonitorStackDepthInfo*> *_owned_monitors_list; | ||||||
| 644 | jvmtiError _error; | ||||||
| 645 | JvmtiEnvBase *_env; | ||||||
| 646 | |||||||
| 647 | public: | ||||||
| 648 | JvmtiMonitorClosure(JavaThread *calling_thread, | ||||||
| 649 | GrowableArray<jvmtiMonitorStackDepthInfo*> *owned_monitors, | ||||||
| 650 | JvmtiEnvBase *env) { | ||||||
| 651 | _calling_thread = calling_thread; | ||||||
| 652 | _owned_monitors_list = owned_monitors; | ||||||
| 653 | _error = JVMTI_ERROR_NONE; | ||||||
| 654 | _env = env; | ||||||
| 655 | } | ||||||
| 656 | void do_monitor(ObjectMonitor* mon); | ||||||
| 657 | jvmtiError error() { return _error;} | ||||||
| 658 | }; | ||||||
| 659 | |||||||
| 660 | |||||||
| 661 | // Jvmti module closure to collect all modules loaded to the system. | ||||||
| 662 | class JvmtiModuleClosure : public StackObj { | ||||||
| 663 | private: | ||||||
| 664 | static GrowableArray<OopHandle> *_tbl; // Protected with Module_lock | ||||||
| 665 | |||||||
| 666 | static void do_module(ModuleEntry* entry); | ||||||
| 667 | public: | ||||||
| 668 | jvmtiError get_all_modules(JvmtiEnv* env, jint* module_count_ptr, jobject** modules_ptr); | ||||||
| 669 | }; | ||||||
| 670 | |||||||
| 671 | #endif // SHARE_PRIMS_JVMTIENVBASE_HPP |