src/share/vm/prims/jvmtiEnv.cpp

Wed, 03 Jul 2019 20:42:37 +0800

author
aoqi
date
Wed, 03 Jul 2019 20:42:37 +0800
changeset 9637
eef07cd490d4
parent 9572
624a0741915c
child 9703
2fdf635bcf28
permissions
-rw-r--r--

Merge

aoqi@0 1 /*
fmatte@9511 2 * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #include "precompiled.hpp"
iklam@7381 26 #include "classfile/classLoaderExt.hpp"
aoqi@0 27 #include "classfile/systemDictionary.hpp"
aoqi@0 28 #include "classfile/vmSymbols.hpp"
aoqi@0 29 #include "interpreter/bytecodeStream.hpp"
aoqi@0 30 #include "interpreter/interpreter.hpp"
aoqi@0 31 #include "jvmtifiles/jvmtiEnv.hpp"
aoqi@0 32 #include "memory/resourceArea.hpp"
aoqi@0 33 #include "memory/universe.inline.hpp"
aoqi@0 34 #include "oops/instanceKlass.hpp"
aoqi@0 35 #include "prims/jniCheck.hpp"
aoqi@0 36 #include "prims/jvm_misc.hpp"
aoqi@0 37 #include "prims/jvmtiAgentThread.hpp"
aoqi@0 38 #include "prims/jvmtiClassFileReconstituter.hpp"
aoqi@0 39 #include "prims/jvmtiCodeBlobEvents.hpp"
aoqi@0 40 #include "prims/jvmtiExtensions.hpp"
aoqi@0 41 #include "prims/jvmtiGetLoadedClasses.hpp"
aoqi@0 42 #include "prims/jvmtiImpl.hpp"
aoqi@0 43 #include "prims/jvmtiManageCapabilities.hpp"
aoqi@0 44 #include "prims/jvmtiRawMonitor.hpp"
aoqi@0 45 #include "prims/jvmtiRedefineClasses.hpp"
aoqi@0 46 #include "prims/jvmtiTagMap.hpp"
aoqi@0 47 #include "prims/jvmtiThreadState.inline.hpp"
aoqi@0 48 #include "prims/jvmtiUtil.hpp"
aoqi@0 49 #include "runtime/arguments.hpp"
aoqi@0 50 #include "runtime/deoptimization.hpp"
aoqi@0 51 #include "runtime/interfaceSupport.hpp"
aoqi@0 52 #include "runtime/javaCalls.hpp"
aoqi@0 53 #include "runtime/jfieldIDWorkaround.hpp"
aoqi@0 54 #include "runtime/osThread.hpp"
aoqi@0 55 #include "runtime/reflectionUtils.hpp"
aoqi@0 56 #include "runtime/signature.hpp"
aoqi@0 57 #include "runtime/thread.inline.hpp"
aoqi@0 58 #include "runtime/vframe.hpp"
aoqi@0 59 #include "runtime/vmThread.hpp"
aoqi@0 60 #include "services/threadService.hpp"
aoqi@0 61 #include "utilities/exceptions.hpp"
aoqi@0 62 #include "utilities/preserveException.hpp"
aoqi@0 63
aoqi@0 64
aoqi@0 65 #define FIXLATER 0 // REMOVE this when completed.
aoqi@0 66
aoqi@0 67 // FIXLATER: hook into JvmtiTrace
aoqi@0 68 #define TraceJVMTICalls false
aoqi@0 69
aoqi@0 70 JvmtiEnv::JvmtiEnv(jint version) : JvmtiEnvBase(version) {
aoqi@0 71 }
aoqi@0 72
aoqi@0 73 JvmtiEnv::~JvmtiEnv() {
aoqi@0 74 }
aoqi@0 75
aoqi@0 76 JvmtiEnv*
aoqi@0 77 JvmtiEnv::create_a_jvmti(jint version) {
aoqi@0 78 return new JvmtiEnv(version);
aoqi@0 79 }
aoqi@0 80
aoqi@0 81 // VM operation class to copy jni function table at safepoint.
aoqi@0 82 // More than one java threads or jvmti agents may be reading/
aoqi@0 83 // modifying jni function tables. To reduce the risk of bad
aoqi@0 84 // interaction b/w these threads it is copied at safepoint.
aoqi@0 85 class VM_JNIFunctionTableCopier : public VM_Operation {
aoqi@0 86 private:
aoqi@0 87 const struct JNINativeInterface_ *_function_table;
aoqi@0 88 public:
aoqi@0 89 VM_JNIFunctionTableCopier(const struct JNINativeInterface_ *func_tbl) {
aoqi@0 90 _function_table = func_tbl;
aoqi@0 91 };
aoqi@0 92
aoqi@0 93 VMOp_Type type() const { return VMOp_JNIFunctionTableCopier; }
aoqi@0 94 void doit() {
aoqi@0 95 copy_jni_function_table(_function_table);
aoqi@0 96 };
aoqi@0 97 };
aoqi@0 98
aoqi@0 99 //
aoqi@0 100 // Do not change the "prefix" marker below, everything above it is copied
aoqi@0 101 // unchanged into the filled stub, everything below is controlled by the
aoqi@0 102 // stub filler (only method bodies are carried forward, and then only for
aoqi@0 103 // functionality still in the spec).
aoqi@0 104 //
aoqi@0 105 // end file prefix
aoqi@0 106
aoqi@0 107 //
aoqi@0 108 // Memory Management functions
aoqi@0 109 //
aoqi@0 110
aoqi@0 111 // mem_ptr - pre-checked for NULL
aoqi@0 112 jvmtiError
aoqi@0 113 JvmtiEnv::Allocate(jlong size, unsigned char** mem_ptr) {
aoqi@0 114 return allocate(size, mem_ptr);
aoqi@0 115 } /* end Allocate */
aoqi@0 116
aoqi@0 117
aoqi@0 118 // mem - NULL is a valid value, must be checked
aoqi@0 119 jvmtiError
aoqi@0 120 JvmtiEnv::Deallocate(unsigned char* mem) {
aoqi@0 121 return deallocate(mem);
aoqi@0 122 } /* end Deallocate */
aoqi@0 123
aoqi@0 124 // Threads_lock NOT held, java_thread not protected by lock
aoqi@0 125 // java_thread - pre-checked
aoqi@0 126 // data - NULL is a valid value, must be checked
aoqi@0 127 jvmtiError
aoqi@0 128 JvmtiEnv::SetThreadLocalStorage(JavaThread* java_thread, const void* data) {
aoqi@0 129 JvmtiThreadState* state = java_thread->jvmti_thread_state();
aoqi@0 130 if (state == NULL) {
aoqi@0 131 if (data == NULL) {
aoqi@0 132 // leaving state unset same as data set to NULL
aoqi@0 133 return JVMTI_ERROR_NONE;
aoqi@0 134 }
aoqi@0 135 // otherwise, create the state
aoqi@0 136 state = JvmtiThreadState::state_for(java_thread);
aoqi@0 137 if (state == NULL) {
aoqi@0 138 return JVMTI_ERROR_THREAD_NOT_ALIVE;
aoqi@0 139 }
aoqi@0 140 }
aoqi@0 141 state->env_thread_state(this)->set_agent_thread_local_storage_data((void*)data);
aoqi@0 142 return JVMTI_ERROR_NONE;
aoqi@0 143 } /* end SetThreadLocalStorage */
aoqi@0 144
aoqi@0 145
aoqi@0 146 // Threads_lock NOT held
aoqi@0 147 // thread - NOT pre-checked
aoqi@0 148 // data_ptr - pre-checked for NULL
aoqi@0 149 jvmtiError
aoqi@0 150 JvmtiEnv::GetThreadLocalStorage(jthread thread, void** data_ptr) {
aoqi@0 151 JavaThread* current_thread = JavaThread::current();
aoqi@0 152 if (thread == NULL) {
aoqi@0 153 JvmtiThreadState* state = current_thread->jvmti_thread_state();
aoqi@0 154 *data_ptr = (state == NULL) ? NULL :
aoqi@0 155 state->env_thread_state(this)->get_agent_thread_local_storage_data();
aoqi@0 156 } else {
aoqi@0 157
aoqi@0 158 // jvmti_GetThreadLocalStorage is "in native" and doesn't transition
aoqi@0 159 // the thread to _thread_in_vm. However, when the TLS for a thread
aoqi@0 160 // other than the current thread is required we need to transition
aoqi@0 161 // from native so as to resolve the jthread.
aoqi@0 162
aoqi@0 163 ThreadInVMfromNative __tiv(current_thread);
aoqi@0 164 VM_ENTRY_BASE(jvmtiError, JvmtiEnv::GetThreadLocalStorage , current_thread)
aoqi@0 165 debug_only(VMNativeEntryWrapper __vew;)
aoqi@0 166
aoqi@0 167 oop thread_oop = JNIHandles::resolve_external_guard(thread);
aoqi@0 168 if (thread_oop == NULL) {
aoqi@0 169 return JVMTI_ERROR_INVALID_THREAD;
aoqi@0 170 }
aoqi@0 171 if (!thread_oop->is_a(SystemDictionary::Thread_klass())) {
aoqi@0 172 return JVMTI_ERROR_INVALID_THREAD;
aoqi@0 173 }
aoqi@0 174 JavaThread* java_thread = java_lang_Thread::thread(thread_oop);
aoqi@0 175 if (java_thread == NULL) {
aoqi@0 176 return JVMTI_ERROR_THREAD_NOT_ALIVE;
aoqi@0 177 }
aoqi@0 178 JvmtiThreadState* state = java_thread->jvmti_thread_state();
aoqi@0 179 *data_ptr = (state == NULL) ? NULL :
aoqi@0 180 state->env_thread_state(this)->get_agent_thread_local_storage_data();
aoqi@0 181 }
aoqi@0 182 return JVMTI_ERROR_NONE;
aoqi@0 183 } /* end GetThreadLocalStorage */
aoqi@0 184
aoqi@0 185 //
aoqi@0 186 // Class functions
aoqi@0 187 //
aoqi@0 188
aoqi@0 189 // class_count_ptr - pre-checked for NULL
aoqi@0 190 // classes_ptr - pre-checked for NULL
aoqi@0 191 jvmtiError
aoqi@0 192 JvmtiEnv::GetLoadedClasses(jint* class_count_ptr, jclass** classes_ptr) {
aoqi@0 193 return JvmtiGetLoadedClasses::getLoadedClasses(this, class_count_ptr, classes_ptr);
aoqi@0 194 } /* end GetLoadedClasses */
aoqi@0 195
aoqi@0 196
aoqi@0 197 // initiating_loader - NULL is a valid value, must be checked
aoqi@0 198 // class_count_ptr - pre-checked for NULL
aoqi@0 199 // classes_ptr - pre-checked for NULL
aoqi@0 200 jvmtiError
aoqi@0 201 JvmtiEnv::GetClassLoaderClasses(jobject initiating_loader, jint* class_count_ptr, jclass** classes_ptr) {
aoqi@0 202 return JvmtiGetLoadedClasses::getClassLoaderClasses(this, initiating_loader,
aoqi@0 203 class_count_ptr, classes_ptr);
aoqi@0 204 } /* end GetClassLoaderClasses */
aoqi@0 205
aoqi@0 206 // k_mirror - may be primitive, this must be checked
aoqi@0 207 // is_modifiable_class_ptr - pre-checked for NULL
aoqi@0 208 jvmtiError
aoqi@0 209 JvmtiEnv::IsModifiableClass(oop k_mirror, jboolean* is_modifiable_class_ptr) {
aoqi@0 210 *is_modifiable_class_ptr = VM_RedefineClasses::is_modifiable_class(k_mirror)?
aoqi@0 211 JNI_TRUE : JNI_FALSE;
aoqi@0 212 return JVMTI_ERROR_NONE;
aoqi@0 213 } /* end IsModifiableClass */
aoqi@0 214
aoqi@0 215 // class_count - pre-checked to be greater than or equal to 0
aoqi@0 216 // classes - pre-checked for NULL
aoqi@0 217 jvmtiError
aoqi@0 218 JvmtiEnv::RetransformClasses(jint class_count, const jclass* classes) {
aoqi@0 219 //TODO: add locking
aoqi@0 220
aoqi@0 221 int index;
aoqi@0 222 JavaThread* current_thread = JavaThread::current();
aoqi@0 223 ResourceMark rm(current_thread);
aoqi@0 224
aoqi@0 225 jvmtiClassDefinition* class_definitions =
aoqi@0 226 NEW_RESOURCE_ARRAY(jvmtiClassDefinition, class_count);
aoqi@0 227 NULL_CHECK(class_definitions, JVMTI_ERROR_OUT_OF_MEMORY);
aoqi@0 228
aoqi@0 229 for (index = 0; index < class_count; index++) {
aoqi@0 230 HandleMark hm(current_thread);
aoqi@0 231
aoqi@0 232 jclass jcls = classes[index];
aoqi@0 233 oop k_mirror = JNIHandles::resolve_external_guard(jcls);
aoqi@0 234 if (k_mirror == NULL) {
aoqi@0 235 return JVMTI_ERROR_INVALID_CLASS;
aoqi@0 236 }
aoqi@0 237 if (!k_mirror->is_a(SystemDictionary::Class_klass())) {
aoqi@0 238 return JVMTI_ERROR_INVALID_CLASS;
aoqi@0 239 }
aoqi@0 240
aoqi@0 241 if (java_lang_Class::is_primitive(k_mirror)) {
aoqi@0 242 return JVMTI_ERROR_UNMODIFIABLE_CLASS;
aoqi@0 243 }
aoqi@0 244
aoqi@0 245 Klass* k_oop = java_lang_Class::as_Klass(k_mirror);
aoqi@0 246 KlassHandle klass(current_thread, k_oop);
aoqi@0 247
aoqi@0 248 jint status = klass->jvmti_class_status();
aoqi@0 249 if (status & (JVMTI_CLASS_STATUS_ERROR)) {
aoqi@0 250 return JVMTI_ERROR_INVALID_CLASS;
aoqi@0 251 }
aoqi@0 252 if (status & (JVMTI_CLASS_STATUS_ARRAY)) {
aoqi@0 253 return JVMTI_ERROR_UNMODIFIABLE_CLASS;
aoqi@0 254 }
aoqi@0 255
aoqi@0 256 instanceKlassHandle ikh(current_thread, k_oop);
aoqi@0 257 if (ikh->get_cached_class_file_bytes() == NULL) {
aoqi@0 258 // Not cached, we need to reconstitute the class file from the
aoqi@0 259 // VM representation. We don't attach the reconstituted class
aoqi@0 260 // bytes to the InstanceKlass here because they have not been
aoqi@0 261 // validated and we're not at a safepoint.
aoqi@0 262 constantPoolHandle constants(current_thread, ikh->constants());
aoqi@0 263 MonitorLockerEx ml(constants->lock()); // lock constant pool while we query it
aoqi@0 264
aoqi@0 265 JvmtiClassFileReconstituter reconstituter(ikh);
aoqi@0 266 if (reconstituter.get_error() != JVMTI_ERROR_NONE) {
aoqi@0 267 return reconstituter.get_error();
aoqi@0 268 }
aoqi@0 269
aoqi@0 270 class_definitions[index].class_byte_count = (jint)reconstituter.class_file_size();
aoqi@0 271 class_definitions[index].class_bytes = (unsigned char*)
aoqi@0 272 reconstituter.class_file_bytes();
aoqi@0 273 } else {
aoqi@0 274 // it is cached, get it from the cache
aoqi@0 275 class_definitions[index].class_byte_count = ikh->get_cached_class_file_len();
aoqi@0 276 class_definitions[index].class_bytes = ikh->get_cached_class_file_bytes();
aoqi@0 277 }
aoqi@0 278 class_definitions[index].klass = jcls;
aoqi@0 279 }
aoqi@0 280 VM_RedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_retransform);
aoqi@0 281 VMThread::execute(&op);
aoqi@0 282 return (op.check_error());
aoqi@0 283 } /* end RetransformClasses */
aoqi@0 284
aoqi@0 285
aoqi@0 286 // class_count - pre-checked to be greater than or equal to 0
aoqi@0 287 // class_definitions - pre-checked for NULL
aoqi@0 288 jvmtiError
aoqi@0 289 JvmtiEnv::RedefineClasses(jint class_count, const jvmtiClassDefinition* class_definitions) {
aoqi@0 290 //TODO: add locking
aoqi@0 291 VM_RedefineClasses op(class_count, class_definitions, jvmti_class_load_kind_redefine);
aoqi@0 292 VMThread::execute(&op);
aoqi@0 293 return (op.check_error());
aoqi@0 294 } /* end RedefineClasses */
aoqi@0 295
aoqi@0 296
aoqi@0 297 //
aoqi@0 298 // Object functions
aoqi@0 299 //
aoqi@0 300
aoqi@0 301 // size_ptr - pre-checked for NULL
aoqi@0 302 jvmtiError
aoqi@0 303 JvmtiEnv::GetObjectSize(jobject object, jlong* size_ptr) {
aoqi@0 304 oop mirror = JNIHandles::resolve_external_guard(object);
aoqi@0 305 NULL_CHECK(mirror, JVMTI_ERROR_INVALID_OBJECT);
aoqi@0 306
aoqi@0 307 if (mirror->klass() == SystemDictionary::Class_klass() &&
aoqi@0 308 !java_lang_Class::is_primitive(mirror)) {
aoqi@0 309 Klass* k = java_lang_Class::as_Klass(mirror);
aoqi@0 310 assert(k != NULL, "class for non-primitive mirror must exist");
aoqi@0 311 *size_ptr = (jlong)k->size() * wordSize;
aoqi@0 312 } else {
aoqi@0 313 *size_ptr = (jlong)mirror->size() * wordSize;
aoqi@0 314 }
aoqi@0 315 return JVMTI_ERROR_NONE;
aoqi@0 316 } /* end GetObjectSize */
aoqi@0 317
aoqi@0 318 //
aoqi@0 319 // Method functions
aoqi@0 320 //
aoqi@0 321
aoqi@0 322 // prefix - NULL is a valid value, must be checked
aoqi@0 323 jvmtiError
aoqi@0 324 JvmtiEnv::SetNativeMethodPrefix(const char* prefix) {
aoqi@0 325 return prefix == NULL?
aoqi@0 326 SetNativeMethodPrefixes(0, NULL) :
aoqi@0 327 SetNativeMethodPrefixes(1, (char**)&prefix);
aoqi@0 328 } /* end SetNativeMethodPrefix */
aoqi@0 329
aoqi@0 330
aoqi@0 331 // prefix_count - pre-checked to be greater than or equal to 0
aoqi@0 332 // prefixes - pre-checked for NULL
aoqi@0 333 jvmtiError
aoqi@0 334 JvmtiEnv::SetNativeMethodPrefixes(jint prefix_count, char** prefixes) {
aoqi@0 335 // Have to grab JVMTI thread state lock to be sure that some thread
aoqi@0 336 // isn't accessing the prefixes at the same time we are setting them.
aoqi@0 337 // No locks during VM bring-up.
aoqi@0 338 if (Threads::number_of_threads() == 0) {
aoqi@0 339 return set_native_method_prefixes(prefix_count, prefixes);
aoqi@0 340 } else {
aoqi@0 341 MutexLocker mu(JvmtiThreadState_lock);
aoqi@0 342 return set_native_method_prefixes(prefix_count, prefixes);
aoqi@0 343 }
aoqi@0 344 } /* end SetNativeMethodPrefixes */
aoqi@0 345
aoqi@0 346 //
aoqi@0 347 // Event Management functions
aoqi@0 348 //
aoqi@0 349
aoqi@0 350 // callbacks - NULL is a valid value, must be checked
aoqi@0 351 // size_of_callbacks - pre-checked to be greater than or equal to 0
aoqi@0 352 jvmtiError
aoqi@0 353 JvmtiEnv::SetEventCallbacks(const jvmtiEventCallbacks* callbacks, jint size_of_callbacks) {
aoqi@0 354 JvmtiEventController::set_event_callbacks(this, callbacks, size_of_callbacks);
aoqi@0 355 return JVMTI_ERROR_NONE;
aoqi@0 356 } /* end SetEventCallbacks */
aoqi@0 357
aoqi@0 358
aoqi@0 359 // event_thread - NULL is a valid value, must be checked
aoqi@0 360 jvmtiError
aoqi@0 361 JvmtiEnv::SetEventNotificationMode(jvmtiEventMode mode, jvmtiEvent event_type, jthread event_thread, ...) {
aoqi@0 362 JavaThread* java_thread = NULL;
aoqi@0 363 if (event_thread != NULL) {
aoqi@0 364 oop thread_oop = JNIHandles::resolve_external_guard(event_thread);
aoqi@0 365 if (thread_oop == NULL) {
aoqi@0 366 return JVMTI_ERROR_INVALID_THREAD;
aoqi@0 367 }
aoqi@0 368 if (!thread_oop->is_a(SystemDictionary::Thread_klass())) {
aoqi@0 369 return JVMTI_ERROR_INVALID_THREAD;
aoqi@0 370 }
aoqi@0 371 java_thread = java_lang_Thread::thread(thread_oop);
aoqi@0 372 if (java_thread == NULL) {
aoqi@0 373 return JVMTI_ERROR_THREAD_NOT_ALIVE;
aoqi@0 374 }
aoqi@0 375 }
aoqi@0 376
aoqi@0 377 // event_type must be valid
aoqi@0 378 if (!JvmtiEventController::is_valid_event_type(event_type)) {
aoqi@0 379 return JVMTI_ERROR_INVALID_EVENT_TYPE;
aoqi@0 380 }
aoqi@0 381
aoqi@0 382 // global events cannot be controlled at thread level.
aoqi@0 383 if (java_thread != NULL && JvmtiEventController::is_global_event(event_type)) {
aoqi@0 384 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
aoqi@0 385 }
aoqi@0 386
aoqi@0 387 bool enabled = (mode == JVMTI_ENABLE);
aoqi@0 388
aoqi@0 389 // assure that needed capabilities are present
aoqi@0 390 if (enabled && !JvmtiUtil::has_event_capability(event_type, get_capabilities())) {
aoqi@0 391 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
aoqi@0 392 }
aoqi@0 393
aoqi@0 394 if (event_type == JVMTI_EVENT_CLASS_FILE_LOAD_HOOK && enabled) {
aoqi@0 395 record_class_file_load_hook_enabled();
aoqi@0 396 }
aoqi@0 397 JvmtiEventController::set_user_enabled(this, java_thread, event_type, enabled);
aoqi@0 398
aoqi@0 399 return JVMTI_ERROR_NONE;
aoqi@0 400 } /* end SetEventNotificationMode */
aoqi@0 401
aoqi@0 402 //
aoqi@0 403 // Capability functions
aoqi@0 404 //
aoqi@0 405
aoqi@0 406 // capabilities_ptr - pre-checked for NULL
aoqi@0 407 jvmtiError
aoqi@0 408 JvmtiEnv::GetPotentialCapabilities(jvmtiCapabilities* capabilities_ptr) {
aoqi@0 409 JvmtiManageCapabilities::get_potential_capabilities(get_capabilities(),
aoqi@0 410 get_prohibited_capabilities(),
aoqi@0 411 capabilities_ptr);
aoqi@0 412 return JVMTI_ERROR_NONE;
aoqi@0 413 } /* end GetPotentialCapabilities */
aoqi@0 414
aoqi@0 415
aoqi@0 416 // capabilities_ptr - pre-checked for NULL
aoqi@0 417 jvmtiError
aoqi@0 418 JvmtiEnv::AddCapabilities(const jvmtiCapabilities* capabilities_ptr) {
aoqi@0 419 return JvmtiManageCapabilities::add_capabilities(get_capabilities(),
aoqi@0 420 get_prohibited_capabilities(),
aoqi@0 421 capabilities_ptr,
aoqi@0 422 get_capabilities());
aoqi@0 423 } /* end AddCapabilities */
aoqi@0 424
aoqi@0 425
aoqi@0 426 // capabilities_ptr - pre-checked for NULL
aoqi@0 427 jvmtiError
aoqi@0 428 JvmtiEnv::RelinquishCapabilities(const jvmtiCapabilities* capabilities_ptr) {
aoqi@0 429 JvmtiManageCapabilities::relinquish_capabilities(get_capabilities(), capabilities_ptr, get_capabilities());
aoqi@0 430 return JVMTI_ERROR_NONE;
aoqi@0 431 } /* end RelinquishCapabilities */
aoqi@0 432
aoqi@0 433
aoqi@0 434 // capabilities_ptr - pre-checked for NULL
aoqi@0 435 jvmtiError
aoqi@0 436 JvmtiEnv::GetCapabilities(jvmtiCapabilities* capabilities_ptr) {
aoqi@0 437 JvmtiManageCapabilities::copy_capabilities(get_capabilities(), capabilities_ptr);
aoqi@0 438 return JVMTI_ERROR_NONE;
aoqi@0 439 } /* end GetCapabilities */
aoqi@0 440
aoqi@0 441 //
aoqi@0 442 // Class Loader Search functions
aoqi@0 443 //
aoqi@0 444
aoqi@0 445 // segment - pre-checked for NULL
aoqi@0 446 jvmtiError
aoqi@0 447 JvmtiEnv::AddToBootstrapClassLoaderSearch(const char* segment) {
aoqi@0 448 jvmtiPhase phase = get_phase();
aoqi@0 449 if (phase == JVMTI_PHASE_ONLOAD) {
aoqi@0 450 Arguments::append_sysclasspath(segment);
aoqi@0 451 return JVMTI_ERROR_NONE;
aoqi@0 452 } else if (use_version_1_0_semantics()) {
aoqi@0 453 // This JvmtiEnv requested version 1.0 semantics and this function
aoqi@0 454 // is only allowed in the ONLOAD phase in version 1.0 so we need to
aoqi@0 455 // return an error here.
aoqi@0 456 return JVMTI_ERROR_WRONG_PHASE;
aoqi@0 457 } else if (phase == JVMTI_PHASE_LIVE) {
aoqi@0 458 // The phase is checked by the wrapper that called this function,
aoqi@0 459 // but this thread could be racing with the thread that is
aoqi@0 460 // terminating the VM so we check one more time.
aoqi@0 461
aoqi@0 462 // create the zip entry
aoqi@0 463 ClassPathZipEntry* zip_entry = ClassLoader::create_class_path_zip_entry(segment);
aoqi@0 464 if (zip_entry == NULL) {
aoqi@0 465 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
aoqi@0 466 }
aoqi@0 467
aoqi@0 468 // lock the loader
aoqi@0 469 Thread* thread = Thread::current();
aoqi@0 470 HandleMark hm;
aoqi@0 471 Handle loader_lock = Handle(thread, SystemDictionary::system_loader_lock());
aoqi@0 472
aoqi@0 473 ObjectLocker ol(loader_lock, thread);
aoqi@0 474
aoqi@0 475 // add the jar file to the bootclasspath
aoqi@0 476 if (TraceClassLoading) {
aoqi@0 477 tty->print_cr("[Opened %s]", zip_entry->name());
aoqi@0 478 }
iklam@7381 479 ClassLoaderExt::append_boot_classpath(zip_entry);
aoqi@0 480 return JVMTI_ERROR_NONE;
aoqi@0 481 } else {
aoqi@0 482 return JVMTI_ERROR_WRONG_PHASE;
aoqi@0 483 }
aoqi@0 484
aoqi@0 485 } /* end AddToBootstrapClassLoaderSearch */
aoqi@0 486
aoqi@0 487
aoqi@0 488 // segment - pre-checked for NULL
aoqi@0 489 jvmtiError
aoqi@0 490 JvmtiEnv::AddToSystemClassLoaderSearch(const char* segment) {
aoqi@0 491 jvmtiPhase phase = get_phase();
aoqi@0 492
aoqi@0 493 if (phase == JVMTI_PHASE_ONLOAD) {
aoqi@0 494 for (SystemProperty* p = Arguments::system_properties(); p != NULL; p = p->next()) {
aoqi@0 495 if (strcmp("java.class.path", p->key()) == 0) {
aoqi@0 496 p->append_value(segment);
aoqi@0 497 break;
aoqi@0 498 }
aoqi@0 499 }
aoqi@0 500 return JVMTI_ERROR_NONE;
aoqi@0 501 } else if (phase == JVMTI_PHASE_LIVE) {
aoqi@0 502 // The phase is checked by the wrapper that called this function,
aoqi@0 503 // but this thread could be racing with the thread that is
aoqi@0 504 // terminating the VM so we check one more time.
aoqi@0 505 HandleMark hm;
aoqi@0 506
aoqi@0 507 // create the zip entry (which will open the zip file and hence
aoqi@0 508 // check that the segment is indeed a zip file).
aoqi@0 509 ClassPathZipEntry* zip_entry = ClassLoader::create_class_path_zip_entry(segment);
aoqi@0 510 if (zip_entry == NULL) {
aoqi@0 511 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
aoqi@0 512 }
aoqi@0 513 delete zip_entry; // no longer needed
aoqi@0 514
aoqi@0 515 // lock the loader
aoqi@0 516 Thread* THREAD = Thread::current();
aoqi@0 517 Handle loader = Handle(THREAD, SystemDictionary::java_system_loader());
aoqi@0 518
aoqi@0 519 ObjectLocker ol(loader, THREAD);
aoqi@0 520
aoqi@0 521 // need the path as java.lang.String
aoqi@0 522 Handle path = java_lang_String::create_from_platform_dependent_str(segment, THREAD);
aoqi@0 523 if (HAS_PENDING_EXCEPTION) {
aoqi@0 524 CLEAR_PENDING_EXCEPTION;
aoqi@0 525 return JVMTI_ERROR_INTERNAL;
aoqi@0 526 }
aoqi@0 527
aoqi@0 528 instanceKlassHandle loader_ik(THREAD, loader->klass());
aoqi@0 529
aoqi@0 530 // Invoke the appendToClassPathForInstrumentation method - if the method
aoqi@0 531 // is not found it means the loader doesn't support adding to the class path
aoqi@0 532 // in the live phase.
aoqi@0 533 {
aoqi@0 534 JavaValue res(T_VOID);
aoqi@0 535 JavaCalls::call_special(&res,
aoqi@0 536 loader,
aoqi@0 537 loader_ik,
aoqi@0 538 vmSymbols::appendToClassPathForInstrumentation_name(),
aoqi@0 539 vmSymbols::appendToClassPathForInstrumentation_signature(),
aoqi@0 540 path,
aoqi@0 541 THREAD);
aoqi@0 542 if (HAS_PENDING_EXCEPTION) {
aoqi@0 543 Symbol* ex_name = PENDING_EXCEPTION->klass()->name();
aoqi@0 544 CLEAR_PENDING_EXCEPTION;
aoqi@0 545
aoqi@0 546 if (ex_name == vmSymbols::java_lang_NoSuchMethodError()) {
aoqi@0 547 return JVMTI_ERROR_CLASS_LOADER_UNSUPPORTED;
aoqi@0 548 } else {
aoqi@0 549 return JVMTI_ERROR_INTERNAL;
aoqi@0 550 }
aoqi@0 551 }
aoqi@0 552 }
aoqi@0 553
aoqi@0 554 return JVMTI_ERROR_NONE;
aoqi@0 555 } else {
aoqi@0 556 return JVMTI_ERROR_WRONG_PHASE;
aoqi@0 557 }
aoqi@0 558 } /* end AddToSystemClassLoaderSearch */
aoqi@0 559
aoqi@0 560 //
aoqi@0 561 // General functions
aoqi@0 562 //
aoqi@0 563
aoqi@0 564 // phase_ptr - pre-checked for NULL
aoqi@0 565 jvmtiError
aoqi@0 566 JvmtiEnv::GetPhase(jvmtiPhase* phase_ptr) {
aoqi@0 567 *phase_ptr = get_phase();
aoqi@0 568 return JVMTI_ERROR_NONE;
aoqi@0 569 } /* end GetPhase */
aoqi@0 570
aoqi@0 571
aoqi@0 572 jvmtiError
aoqi@0 573 JvmtiEnv::DisposeEnvironment() {
aoqi@0 574 dispose();
aoqi@0 575 return JVMTI_ERROR_NONE;
aoqi@0 576 } /* end DisposeEnvironment */
aoqi@0 577
aoqi@0 578
aoqi@0 579 // data - NULL is a valid value, must be checked
aoqi@0 580 jvmtiError
aoqi@0 581 JvmtiEnv::SetEnvironmentLocalStorage(const void* data) {
aoqi@0 582 set_env_local_storage(data);
aoqi@0 583 return JVMTI_ERROR_NONE;
aoqi@0 584 } /* end SetEnvironmentLocalStorage */
aoqi@0 585
aoqi@0 586
aoqi@0 587 // data_ptr - pre-checked for NULL
aoqi@0 588 jvmtiError
aoqi@0 589 JvmtiEnv::GetEnvironmentLocalStorage(void** data_ptr) {
aoqi@0 590 *data_ptr = (void*)get_env_local_storage();
aoqi@0 591 return JVMTI_ERROR_NONE;
aoqi@0 592 } /* end GetEnvironmentLocalStorage */
aoqi@0 593
aoqi@0 594 // version_ptr - pre-checked for NULL
aoqi@0 595 jvmtiError
aoqi@0 596 JvmtiEnv::GetVersionNumber(jint* version_ptr) {
aoqi@0 597 *version_ptr = JVMTI_VERSION;
aoqi@0 598 return JVMTI_ERROR_NONE;
aoqi@0 599 } /* end GetVersionNumber */
aoqi@0 600
aoqi@0 601
aoqi@0 602 // name_ptr - pre-checked for NULL
aoqi@0 603 jvmtiError
aoqi@0 604 JvmtiEnv::GetErrorName(jvmtiError error, char** name_ptr) {
aoqi@0 605 if (error < JVMTI_ERROR_NONE || error > JVMTI_ERROR_MAX) {
aoqi@0 606 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
aoqi@0 607 }
aoqi@0 608 const char *name = JvmtiUtil::error_name(error);
aoqi@0 609 if (name == NULL) {
aoqi@0 610 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
aoqi@0 611 }
aoqi@0 612 size_t len = strlen(name) + 1;
aoqi@0 613 jvmtiError err = allocate(len, (unsigned char**)name_ptr);
aoqi@0 614 if (err == JVMTI_ERROR_NONE) {
aoqi@0 615 memcpy(*name_ptr, name, len);
aoqi@0 616 }
aoqi@0 617 return err;
aoqi@0 618 } /* end GetErrorName */
aoqi@0 619
aoqi@0 620
aoqi@0 621 jvmtiError
aoqi@0 622 JvmtiEnv::SetVerboseFlag(jvmtiVerboseFlag flag, jboolean value) {
aoqi@0 623 switch (flag) {
aoqi@0 624 case JVMTI_VERBOSE_OTHER:
aoqi@0 625 // ignore
aoqi@0 626 break;
aoqi@0 627 case JVMTI_VERBOSE_CLASS:
aoqi@0 628 TraceClassLoading = value != 0;
aoqi@0 629 TraceClassUnloading = value != 0;
aoqi@0 630 break;
aoqi@0 631 case JVMTI_VERBOSE_GC:
aoqi@0 632 PrintGC = value != 0;
aoqi@0 633 break;
aoqi@0 634 case JVMTI_VERBOSE_JNI:
aoqi@0 635 PrintJNIResolving = value != 0;
aoqi@0 636 break;
aoqi@0 637 default:
aoqi@0 638 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
aoqi@0 639 };
aoqi@0 640 return JVMTI_ERROR_NONE;
aoqi@0 641 } /* end SetVerboseFlag */
aoqi@0 642
aoqi@0 643
aoqi@0 644 // format_ptr - pre-checked for NULL
aoqi@0 645 jvmtiError
aoqi@0 646 JvmtiEnv::GetJLocationFormat(jvmtiJlocationFormat* format_ptr) {
aoqi@0 647 *format_ptr = JVMTI_JLOCATION_JVMBCI;
aoqi@0 648 return JVMTI_ERROR_NONE;
aoqi@0 649 } /* end GetJLocationFormat */
aoqi@0 650
aoqi@0 651 //
aoqi@0 652 // Thread functions
aoqi@0 653 //
aoqi@0 654
aoqi@0 655 // Threads_lock NOT held
aoqi@0 656 // thread - NOT pre-checked
aoqi@0 657 // thread_state_ptr - pre-checked for NULL
aoqi@0 658 jvmtiError
aoqi@0 659 JvmtiEnv::GetThreadState(jthread thread, jint* thread_state_ptr) {
aoqi@0 660 jint state;
aoqi@0 661 oop thread_oop;
aoqi@0 662 JavaThread* thr;
aoqi@0 663
aoqi@0 664 if (thread == NULL) {
aoqi@0 665 thread_oop = JavaThread::current()->threadObj();
aoqi@0 666 } else {
aoqi@0 667 thread_oop = JNIHandles::resolve_external_guard(thread);
aoqi@0 668 }
aoqi@0 669
aoqi@0 670 if (thread_oop == NULL || !thread_oop->is_a(SystemDictionary::Thread_klass())) {
aoqi@0 671 return JVMTI_ERROR_INVALID_THREAD;
aoqi@0 672 }
aoqi@0 673
aoqi@0 674 // get most state bits
aoqi@0 675 state = (jint)java_lang_Thread::get_thread_status(thread_oop);
aoqi@0 676
aoqi@0 677 // add more state bits
aoqi@0 678 thr = java_lang_Thread::thread(thread_oop);
aoqi@0 679 if (thr != NULL) {
aoqi@0 680 JavaThreadState jts = thr->thread_state();
aoqi@0 681
aoqi@0 682 if (thr->is_being_ext_suspended()) {
aoqi@0 683 state |= JVMTI_THREAD_STATE_SUSPENDED;
aoqi@0 684 }
aoqi@0 685 if (jts == _thread_in_native) {
aoqi@0 686 state |= JVMTI_THREAD_STATE_IN_NATIVE;
aoqi@0 687 }
aoqi@0 688 OSThread* osThread = thr->osthread();
aoqi@0 689 if (osThread != NULL && osThread->interrupted()) {
aoqi@0 690 state |= JVMTI_THREAD_STATE_INTERRUPTED;
aoqi@0 691 }
aoqi@0 692 }
aoqi@0 693
aoqi@0 694 *thread_state_ptr = state;
aoqi@0 695 return JVMTI_ERROR_NONE;
aoqi@0 696 } /* end GetThreadState */
aoqi@0 697
aoqi@0 698
aoqi@0 699 // thread_ptr - pre-checked for NULL
aoqi@0 700 jvmtiError
aoqi@0 701 JvmtiEnv::GetCurrentThread(jthread* thread_ptr) {
aoqi@0 702 JavaThread* current_thread = JavaThread::current();
aoqi@0 703 *thread_ptr = (jthread)JNIHandles::make_local(current_thread, current_thread->threadObj());
aoqi@0 704 return JVMTI_ERROR_NONE;
aoqi@0 705 } /* end GetCurrentThread */
aoqi@0 706
aoqi@0 707
aoqi@0 708 // threads_count_ptr - pre-checked for NULL
aoqi@0 709 // threads_ptr - pre-checked for NULL
aoqi@0 710 jvmtiError
aoqi@0 711 JvmtiEnv::GetAllThreads(jint* threads_count_ptr, jthread** threads_ptr) {
aoqi@0 712 int nthreads = 0;
aoqi@0 713 Handle *thread_objs = NULL;
aoqi@0 714 ResourceMark rm;
aoqi@0 715 HandleMark hm;
aoqi@0 716
aoqi@0 717 // enumerate threads (including agent threads)
aoqi@0 718 ThreadsListEnumerator tle(Thread::current(), true);
aoqi@0 719 nthreads = tle.num_threads();
aoqi@0 720 *threads_count_ptr = nthreads;
aoqi@0 721
aoqi@0 722 if (nthreads == 0) {
aoqi@0 723 *threads_ptr = NULL;
aoqi@0 724 return JVMTI_ERROR_NONE;
aoqi@0 725 }
aoqi@0 726
aoqi@0 727 thread_objs = NEW_RESOURCE_ARRAY(Handle, nthreads);
aoqi@0 728 NULL_CHECK(thread_objs, JVMTI_ERROR_OUT_OF_MEMORY);
aoqi@0 729
fmatte@9511 730 for (int i = 0; i < nthreads; i++) {
aoqi@0 731 thread_objs[i] = Handle(tle.get_threadObj(i));
aoqi@0 732 }
aoqi@0 733
aoqi@0 734 // have to make global handles outside of Threads_lock
aoqi@0 735 jthread *jthreads = new_jthreadArray(nthreads, thread_objs);
aoqi@0 736 NULL_CHECK(jthreads, JVMTI_ERROR_OUT_OF_MEMORY);
aoqi@0 737
aoqi@0 738 *threads_ptr = jthreads;
aoqi@0 739 return JVMTI_ERROR_NONE;
aoqi@0 740 } /* end GetAllThreads */
aoqi@0 741
aoqi@0 742
aoqi@0 743 // Threads_lock NOT held, java_thread not protected by lock
aoqi@0 744 // java_thread - pre-checked
aoqi@0 745 jvmtiError
aoqi@0 746 JvmtiEnv::SuspendThread(JavaThread* java_thread) {
aoqi@0 747 // don't allow hidden thread suspend request.
aoqi@0 748 if (java_thread->is_hidden_from_external_view()) {
aoqi@0 749 return (JVMTI_ERROR_NONE);
aoqi@0 750 }
aoqi@0 751
aoqi@0 752 {
aoqi@0 753 MutexLockerEx ml(java_thread->SR_lock(), Mutex::_no_safepoint_check_flag);
aoqi@0 754 if (java_thread->is_external_suspend()) {
aoqi@0 755 // don't allow nested external suspend requests.
aoqi@0 756 return (JVMTI_ERROR_THREAD_SUSPENDED);
aoqi@0 757 }
aoqi@0 758 if (java_thread->is_exiting()) { // thread is in the process of exiting
aoqi@0 759 return (JVMTI_ERROR_THREAD_NOT_ALIVE);
aoqi@0 760 }
aoqi@0 761 java_thread->set_external_suspend();
aoqi@0 762 }
aoqi@0 763
aoqi@0 764 if (!JvmtiSuspendControl::suspend(java_thread)) {
aoqi@0 765 // the thread was in the process of exiting
aoqi@0 766 return (JVMTI_ERROR_THREAD_NOT_ALIVE);
aoqi@0 767 }
aoqi@0 768 return JVMTI_ERROR_NONE;
aoqi@0 769 } /* end SuspendThread */
aoqi@0 770
aoqi@0 771
aoqi@0 772 // request_count - pre-checked to be greater than or equal to 0
aoqi@0 773 // request_list - pre-checked for NULL
aoqi@0 774 // results - pre-checked for NULL
aoqi@0 775 jvmtiError
aoqi@0 776 JvmtiEnv::SuspendThreadList(jint request_count, const jthread* request_list, jvmtiError* results) {
aoqi@0 777 int needSafepoint = 0; // > 0 if we need a safepoint
aoqi@0 778 for (int i = 0; i < request_count; i++) {
aoqi@0 779 JavaThread *java_thread = get_JavaThread(request_list[i]);
aoqi@0 780 if (java_thread == NULL) {
aoqi@0 781 results[i] = JVMTI_ERROR_INVALID_THREAD;
aoqi@0 782 continue;
aoqi@0 783 }
aoqi@0 784 // the thread has not yet run or has exited (not on threads list)
aoqi@0 785 if (java_thread->threadObj() == NULL) {
aoqi@0 786 results[i] = JVMTI_ERROR_THREAD_NOT_ALIVE;
aoqi@0 787 continue;
aoqi@0 788 }
aoqi@0 789 if (java_lang_Thread::thread(java_thread->threadObj()) == NULL) {
aoqi@0 790 results[i] = JVMTI_ERROR_THREAD_NOT_ALIVE;
aoqi@0 791 continue;
aoqi@0 792 }
aoqi@0 793 // don't allow hidden thread suspend request.
aoqi@0 794 if (java_thread->is_hidden_from_external_view()) {
aoqi@0 795 results[i] = JVMTI_ERROR_NONE; // indicate successful suspend
aoqi@0 796 continue;
aoqi@0 797 }
aoqi@0 798
aoqi@0 799 {
aoqi@0 800 MutexLockerEx ml(java_thread->SR_lock(), Mutex::_no_safepoint_check_flag);
aoqi@0 801 if (java_thread->is_external_suspend()) {
aoqi@0 802 // don't allow nested external suspend requests.
aoqi@0 803 results[i] = JVMTI_ERROR_THREAD_SUSPENDED;
aoqi@0 804 continue;
aoqi@0 805 }
aoqi@0 806 if (java_thread->is_exiting()) { // thread is in the process of exiting
aoqi@0 807 results[i] = JVMTI_ERROR_THREAD_NOT_ALIVE;
aoqi@0 808 continue;
aoqi@0 809 }
aoqi@0 810 java_thread->set_external_suspend();
aoqi@0 811 }
aoqi@0 812 if (java_thread->thread_state() == _thread_in_native) {
aoqi@0 813 // We need to try and suspend native threads here. Threads in
aoqi@0 814 // other states will self-suspend on their next transition.
aoqi@0 815 if (!JvmtiSuspendControl::suspend(java_thread)) {
aoqi@0 816 // The thread was in the process of exiting. Force another
aoqi@0 817 // safepoint to make sure that this thread transitions.
aoqi@0 818 needSafepoint++;
aoqi@0 819 results[i] = JVMTI_ERROR_THREAD_NOT_ALIVE;
aoqi@0 820 continue;
aoqi@0 821 }
aoqi@0 822 } else {
aoqi@0 823 needSafepoint++;
aoqi@0 824 }
aoqi@0 825 results[i] = JVMTI_ERROR_NONE; // indicate successful suspend
aoqi@0 826 }
aoqi@0 827 if (needSafepoint > 0) {
aoqi@0 828 VM_ForceSafepoint vfs;
aoqi@0 829 VMThread::execute(&vfs);
aoqi@0 830 }
aoqi@0 831 // per-thread suspend results returned via results parameter
aoqi@0 832 return JVMTI_ERROR_NONE;
aoqi@0 833 } /* end SuspendThreadList */
aoqi@0 834
aoqi@0 835
aoqi@0 836 // Threads_lock NOT held, java_thread not protected by lock
aoqi@0 837 // java_thread - pre-checked
aoqi@0 838 jvmtiError
aoqi@0 839 JvmtiEnv::ResumeThread(JavaThread* java_thread) {
aoqi@0 840 // don't allow hidden thread resume request.
aoqi@0 841 if (java_thread->is_hidden_from_external_view()) {
aoqi@0 842 return JVMTI_ERROR_NONE;
aoqi@0 843 }
aoqi@0 844
aoqi@0 845 if (!java_thread->is_being_ext_suspended()) {
aoqi@0 846 return JVMTI_ERROR_THREAD_NOT_SUSPENDED;
aoqi@0 847 }
aoqi@0 848
aoqi@0 849 if (!JvmtiSuspendControl::resume(java_thread)) {
aoqi@0 850 return JVMTI_ERROR_INTERNAL;
aoqi@0 851 }
aoqi@0 852 return JVMTI_ERROR_NONE;
aoqi@0 853 } /* end ResumeThread */
aoqi@0 854
aoqi@0 855
aoqi@0 856 // request_count - pre-checked to be greater than or equal to 0
aoqi@0 857 // request_list - pre-checked for NULL
aoqi@0 858 // results - pre-checked for NULL
aoqi@0 859 jvmtiError
aoqi@0 860 JvmtiEnv::ResumeThreadList(jint request_count, const jthread* request_list, jvmtiError* results) {
aoqi@0 861 for (int i = 0; i < request_count; i++) {
aoqi@0 862 JavaThread *java_thread = get_JavaThread(request_list[i]);
aoqi@0 863 if (java_thread == NULL) {
aoqi@0 864 results[i] = JVMTI_ERROR_INVALID_THREAD;
aoqi@0 865 continue;
aoqi@0 866 }
aoqi@0 867 // don't allow hidden thread resume request.
aoqi@0 868 if (java_thread->is_hidden_from_external_view()) {
aoqi@0 869 results[i] = JVMTI_ERROR_NONE; // indicate successful resume
aoqi@0 870 continue;
aoqi@0 871 }
aoqi@0 872 if (!java_thread->is_being_ext_suspended()) {
aoqi@0 873 results[i] = JVMTI_ERROR_THREAD_NOT_SUSPENDED;
aoqi@0 874 continue;
aoqi@0 875 }
aoqi@0 876
aoqi@0 877 if (!JvmtiSuspendControl::resume(java_thread)) {
aoqi@0 878 results[i] = JVMTI_ERROR_INTERNAL;
aoqi@0 879 continue;
aoqi@0 880 }
aoqi@0 881
aoqi@0 882 results[i] = JVMTI_ERROR_NONE; // indicate successful suspend
aoqi@0 883 }
aoqi@0 884 // per-thread resume results returned via results parameter
aoqi@0 885 return JVMTI_ERROR_NONE;
aoqi@0 886 } /* end ResumeThreadList */
aoqi@0 887
aoqi@0 888
aoqi@0 889 // Threads_lock NOT held, java_thread not protected by lock
aoqi@0 890 // java_thread - pre-checked
aoqi@0 891 jvmtiError
aoqi@0 892 JvmtiEnv::StopThread(JavaThread* java_thread, jobject exception) {
aoqi@0 893 oop e = JNIHandles::resolve_external_guard(exception);
aoqi@0 894 NULL_CHECK(e, JVMTI_ERROR_NULL_POINTER);
aoqi@0 895
aoqi@0 896 JavaThread::send_async_exception(java_thread->threadObj(), e);
aoqi@0 897
aoqi@0 898 return JVMTI_ERROR_NONE;
aoqi@0 899
aoqi@0 900 } /* end StopThread */
aoqi@0 901
aoqi@0 902
aoqi@0 903 // Threads_lock NOT held
aoqi@0 904 // thread - NOT pre-checked
aoqi@0 905 jvmtiError
aoqi@0 906 JvmtiEnv::InterruptThread(jthread thread) {
aoqi@0 907 oop thread_oop = JNIHandles::resolve_external_guard(thread);
aoqi@0 908 if (thread_oop == NULL || !thread_oop->is_a(SystemDictionary::Thread_klass()))
aoqi@0 909 return JVMTI_ERROR_INVALID_THREAD;
aoqi@0 910
aoqi@0 911 JavaThread* current_thread = JavaThread::current();
aoqi@0 912
aoqi@0 913 // Todo: this is a duplicate of JVM_Interrupt; share code in future
aoqi@0 914 // Ensure that the C++ Thread and OSThread structures aren't freed before we operate
aoqi@0 915 MutexLockerEx ml(current_thread->threadObj() == thread_oop ? NULL : Threads_lock);
aoqi@0 916 // We need to re-resolve the java_thread, since a GC might have happened during the
aoqi@0 917 // acquire of the lock
aoqi@0 918
aoqi@0 919 JavaThread* java_thread = java_lang_Thread::thread(JNIHandles::resolve_external_guard(thread));
aoqi@0 920 NULL_CHECK(java_thread, JVMTI_ERROR_THREAD_NOT_ALIVE);
aoqi@0 921
aoqi@0 922 Thread::interrupt(java_thread);
aoqi@0 923
aoqi@0 924 return JVMTI_ERROR_NONE;
aoqi@0 925 } /* end InterruptThread */
aoqi@0 926
aoqi@0 927
aoqi@0 928 // Threads_lock NOT held
aoqi@0 929 // thread - NOT pre-checked
aoqi@0 930 // info_ptr - pre-checked for NULL
aoqi@0 931 jvmtiError
aoqi@0 932 JvmtiEnv::GetThreadInfo(jthread thread, jvmtiThreadInfo* info_ptr) {
aoqi@0 933 ResourceMark rm;
aoqi@0 934 HandleMark hm;
aoqi@0 935
aoqi@0 936 JavaThread* current_thread = JavaThread::current();
aoqi@0 937
aoqi@0 938 // if thread is NULL the current thread is used
aoqi@0 939 oop thread_oop;
aoqi@0 940 if (thread == NULL) {
aoqi@0 941 thread_oop = current_thread->threadObj();
aoqi@0 942 } else {
aoqi@0 943 thread_oop = JNIHandles::resolve_external_guard(thread);
aoqi@0 944 }
aoqi@0 945 if (thread_oop == NULL || !thread_oop->is_a(SystemDictionary::Thread_klass()))
aoqi@0 946 return JVMTI_ERROR_INVALID_THREAD;
aoqi@0 947
aoqi@0 948 Handle thread_obj(current_thread, thread_oop);
shade@8288 949 Handle name;
aoqi@0 950 ThreadPriority priority;
aoqi@0 951 Handle thread_group;
aoqi@0 952 Handle context_class_loader;
aoqi@0 953 bool is_daemon;
aoqi@0 954
fmatte@9511 955 name = Handle(current_thread, java_lang_Thread::name(thread_obj()));
fmatte@9511 956 priority = java_lang_Thread::priority(thread_obj());
fmatte@9511 957 thread_group = Handle(current_thread, java_lang_Thread::threadGroup(thread_obj()));
fmatte@9511 958 is_daemon = java_lang_Thread::is_daemon(thread_obj());
fmatte@9511 959
fmatte@9511 960 oop loader = java_lang_Thread::context_class_loader(thread_obj());
fmatte@9511 961 context_class_loader = Handle(current_thread, loader);
fmatte@9511 962
aoqi@0 963 { const char *n;
aoqi@0 964
aoqi@0 965 if (name() != NULL) {
shade@8288 966 n = java_lang_String::as_utf8_string(name());
aoqi@0 967 } else {
aoqi@0 968 n = UNICODE::as_utf8(NULL, 0);
aoqi@0 969 }
aoqi@0 970
aoqi@0 971 info_ptr->name = (char *) jvmtiMalloc(strlen(n)+1);
aoqi@0 972 if (info_ptr->name == NULL)
aoqi@0 973 return JVMTI_ERROR_OUT_OF_MEMORY;
aoqi@0 974
aoqi@0 975 strcpy(info_ptr->name, n);
aoqi@0 976 }
aoqi@0 977 info_ptr->is_daemon = is_daemon;
aoqi@0 978 info_ptr->priority = priority;
aoqi@0 979
aoqi@0 980 info_ptr->context_class_loader = (context_class_loader.is_null()) ? NULL :
aoqi@0 981 jni_reference(context_class_loader);
aoqi@0 982 info_ptr->thread_group = jni_reference(thread_group);
aoqi@0 983
aoqi@0 984 return JVMTI_ERROR_NONE;
aoqi@0 985 } /* end GetThreadInfo */
aoqi@0 986
aoqi@0 987
aoqi@0 988 // Threads_lock NOT held, java_thread not protected by lock
aoqi@0 989 // java_thread - pre-checked
aoqi@0 990 // owned_monitor_count_ptr - pre-checked for NULL
aoqi@0 991 // owned_monitors_ptr - pre-checked for NULL
aoqi@0 992 jvmtiError
aoqi@0 993 JvmtiEnv::GetOwnedMonitorInfo(JavaThread* java_thread, jint* owned_monitor_count_ptr, jobject** owned_monitors_ptr) {
aoqi@0 994 jvmtiError err = JVMTI_ERROR_NONE;
aoqi@0 995 JavaThread* calling_thread = JavaThread::current();
aoqi@0 996
aoqi@0 997 // growable array of jvmti monitors info on the C-heap
aoqi@0 998 GrowableArray<jvmtiMonitorStackDepthInfo*> *owned_monitors_list =
aoqi@0 999 new (ResourceObj::C_HEAP, mtInternal) GrowableArray<jvmtiMonitorStackDepthInfo*>(1, true);
aoqi@0 1000
sspitsyn@8714 1001 // It is only safe to perform the direct operation on the current
sspitsyn@8714 1002 // thread. All other usage needs to use a vm-safepoint-op for safety.
sspitsyn@8714 1003 if (java_thread == calling_thread) {
aoqi@0 1004 err = get_owned_monitors(calling_thread, java_thread, owned_monitors_list);
aoqi@0 1005 } else {
aoqi@0 1006 // JVMTI get monitors info at safepoint. Do not require target thread to
aoqi@0 1007 // be suspended.
aoqi@0 1008 VM_GetOwnedMonitorInfo op(this, calling_thread, java_thread, owned_monitors_list);
aoqi@0 1009 VMThread::execute(&op);
aoqi@0 1010 err = op.result();
aoqi@0 1011 }
aoqi@0 1012 jint owned_monitor_count = owned_monitors_list->length();
aoqi@0 1013 if (err == JVMTI_ERROR_NONE) {
aoqi@0 1014 if ((err = allocate(owned_monitor_count * sizeof(jobject *),
aoqi@0 1015 (unsigned char**)owned_monitors_ptr)) == JVMTI_ERROR_NONE) {
aoqi@0 1016 // copy into the returned array
aoqi@0 1017 for (int i = 0; i < owned_monitor_count; i++) {
aoqi@0 1018 (*owned_monitors_ptr)[i] =
aoqi@0 1019 ((jvmtiMonitorStackDepthInfo*)owned_monitors_list->at(i))->monitor;
aoqi@0 1020 }
aoqi@0 1021 *owned_monitor_count_ptr = owned_monitor_count;
aoqi@0 1022 }
aoqi@0 1023 }
aoqi@0 1024 // clean up.
aoqi@0 1025 for (int i = 0; i < owned_monitor_count; i++) {
aoqi@0 1026 deallocate((unsigned char*)owned_monitors_list->at(i));
aoqi@0 1027 }
aoqi@0 1028 delete owned_monitors_list;
aoqi@0 1029
aoqi@0 1030 return err;
aoqi@0 1031 } /* end GetOwnedMonitorInfo */
aoqi@0 1032
aoqi@0 1033
aoqi@0 1034 // Threads_lock NOT held, java_thread not protected by lock
aoqi@0 1035 // java_thread - pre-checked
aoqi@0 1036 // monitor_info_count_ptr - pre-checked for NULL
aoqi@0 1037 // monitor_info_ptr - pre-checked for NULL
aoqi@0 1038 jvmtiError
aoqi@0 1039 JvmtiEnv::GetOwnedMonitorStackDepthInfo(JavaThread* java_thread, jint* monitor_info_count_ptr, jvmtiMonitorStackDepthInfo** monitor_info_ptr) {
aoqi@0 1040 jvmtiError err = JVMTI_ERROR_NONE;
aoqi@0 1041 JavaThread* calling_thread = JavaThread::current();
aoqi@0 1042
aoqi@0 1043 // growable array of jvmti monitors info on the C-heap
aoqi@0 1044 GrowableArray<jvmtiMonitorStackDepthInfo*> *owned_monitors_list =
aoqi@0 1045 new (ResourceObj::C_HEAP, mtInternal) GrowableArray<jvmtiMonitorStackDepthInfo*>(1, true);
aoqi@0 1046
sspitsyn@8714 1047 // It is only safe to perform the direct operation on the current
sspitsyn@8714 1048 // thread. All other usage needs to use a vm-safepoint-op for safety.
sspitsyn@8714 1049 if (java_thread == calling_thread) {
aoqi@0 1050 err = get_owned_monitors(calling_thread, java_thread, owned_monitors_list);
aoqi@0 1051 } else {
aoqi@0 1052 // JVMTI get owned monitors info at safepoint. Do not require target thread to
aoqi@0 1053 // be suspended.
aoqi@0 1054 VM_GetOwnedMonitorInfo op(this, calling_thread, java_thread, owned_monitors_list);
aoqi@0 1055 VMThread::execute(&op);
aoqi@0 1056 err = op.result();
aoqi@0 1057 }
aoqi@0 1058
aoqi@0 1059 jint owned_monitor_count = owned_monitors_list->length();
aoqi@0 1060 if (err == JVMTI_ERROR_NONE) {
aoqi@0 1061 if ((err = allocate(owned_monitor_count * sizeof(jvmtiMonitorStackDepthInfo),
aoqi@0 1062 (unsigned char**)monitor_info_ptr)) == JVMTI_ERROR_NONE) {
aoqi@0 1063 // copy to output array.
aoqi@0 1064 for (int i = 0; i < owned_monitor_count; i++) {
aoqi@0 1065 (*monitor_info_ptr)[i].monitor =
aoqi@0 1066 ((jvmtiMonitorStackDepthInfo*)owned_monitors_list->at(i))->monitor;
aoqi@0 1067 (*monitor_info_ptr)[i].stack_depth =
aoqi@0 1068 ((jvmtiMonitorStackDepthInfo*)owned_monitors_list->at(i))->stack_depth;
aoqi@0 1069 }
aoqi@0 1070 }
aoqi@0 1071 *monitor_info_count_ptr = owned_monitor_count;
aoqi@0 1072 }
aoqi@0 1073
aoqi@0 1074 // clean up.
aoqi@0 1075 for (int i = 0; i < owned_monitor_count; i++) {
aoqi@0 1076 deallocate((unsigned char*)owned_monitors_list->at(i));
aoqi@0 1077 }
aoqi@0 1078 delete owned_monitors_list;
aoqi@0 1079
aoqi@0 1080 return err;
aoqi@0 1081 } /* end GetOwnedMonitorStackDepthInfo */
aoqi@0 1082
aoqi@0 1083
aoqi@0 1084 // Threads_lock NOT held, java_thread not protected by lock
aoqi@0 1085 // java_thread - pre-checked
aoqi@0 1086 // monitor_ptr - pre-checked for NULL
aoqi@0 1087 jvmtiError
aoqi@0 1088 JvmtiEnv::GetCurrentContendedMonitor(JavaThread* java_thread, jobject* monitor_ptr) {
aoqi@0 1089 jvmtiError err = JVMTI_ERROR_NONE;
aoqi@0 1090 JavaThread* calling_thread = JavaThread::current();
sspitsyn@8714 1091
sspitsyn@8714 1092 // It is only safe to perform the direct operation on the current
sspitsyn@8714 1093 // thread. All other usage needs to use a vm-safepoint-op for safety.
sspitsyn@8714 1094 if (java_thread == calling_thread) {
aoqi@0 1095 err = get_current_contended_monitor(calling_thread, java_thread, monitor_ptr);
aoqi@0 1096 } else {
aoqi@0 1097 // get contended monitor information at safepoint.
aoqi@0 1098 VM_GetCurrentContendedMonitor op(this, calling_thread, java_thread, monitor_ptr);
aoqi@0 1099 VMThread::execute(&op);
aoqi@0 1100 err = op.result();
aoqi@0 1101 }
aoqi@0 1102 return err;
aoqi@0 1103 } /* end GetCurrentContendedMonitor */
aoqi@0 1104
aoqi@0 1105
aoqi@0 1106 // Threads_lock NOT held
aoqi@0 1107 // thread - NOT pre-checked
aoqi@0 1108 // proc - pre-checked for NULL
aoqi@0 1109 // arg - NULL is a valid value, must be checked
aoqi@0 1110 jvmtiError
aoqi@0 1111 JvmtiEnv::RunAgentThread(jthread thread, jvmtiStartFunction proc, const void* arg, jint priority) {
aoqi@0 1112 oop thread_oop = JNIHandles::resolve_external_guard(thread);
aoqi@0 1113 if (thread_oop == NULL || !thread_oop->is_a(SystemDictionary::Thread_klass())) {
aoqi@0 1114 return JVMTI_ERROR_INVALID_THREAD;
aoqi@0 1115 }
aoqi@0 1116 if (priority < JVMTI_THREAD_MIN_PRIORITY || priority > JVMTI_THREAD_MAX_PRIORITY) {
aoqi@0 1117 return JVMTI_ERROR_INVALID_PRIORITY;
aoqi@0 1118 }
aoqi@0 1119
aoqi@0 1120 //Thread-self
aoqi@0 1121 JavaThread* current_thread = JavaThread::current();
aoqi@0 1122
aoqi@0 1123 Handle thread_hndl(current_thread, thread_oop);
aoqi@0 1124 {
aoqi@0 1125 MutexLocker mu(Threads_lock); // grab Threads_lock
aoqi@0 1126
aoqi@0 1127 JvmtiAgentThread *new_thread = new JvmtiAgentThread(this, proc, arg);
aoqi@0 1128
aoqi@0 1129 // At this point it may be possible that no osthread was created for the
aoqi@0 1130 // JavaThread due to lack of memory.
aoqi@0 1131 if (new_thread == NULL || new_thread->osthread() == NULL) {
aoqi@0 1132 if (new_thread) delete new_thread;
aoqi@0 1133 return JVMTI_ERROR_OUT_OF_MEMORY;
aoqi@0 1134 }
aoqi@0 1135
aoqi@0 1136 java_lang_Thread::set_thread(thread_hndl(), new_thread);
aoqi@0 1137 java_lang_Thread::set_priority(thread_hndl(), (ThreadPriority)priority);
aoqi@0 1138 java_lang_Thread::set_daemon(thread_hndl());
aoqi@0 1139
aoqi@0 1140 new_thread->set_threadObj(thread_hndl());
aoqi@0 1141 Threads::add(new_thread);
aoqi@0 1142 Thread::start(new_thread);
aoqi@0 1143 } // unlock Threads_lock
aoqi@0 1144
aoqi@0 1145 return JVMTI_ERROR_NONE;
aoqi@0 1146 } /* end RunAgentThread */
aoqi@0 1147
aoqi@0 1148 //
aoqi@0 1149 // Thread Group functions
aoqi@0 1150 //
aoqi@0 1151
aoqi@0 1152 // group_count_ptr - pre-checked for NULL
aoqi@0 1153 // groups_ptr - pre-checked for NULL
aoqi@0 1154 jvmtiError
aoqi@0 1155 JvmtiEnv::GetTopThreadGroups(jint* group_count_ptr, jthreadGroup** groups_ptr) {
aoqi@0 1156 JavaThread* current_thread = JavaThread::current();
aoqi@0 1157
aoqi@0 1158 // Only one top level thread group now.
aoqi@0 1159 *group_count_ptr = 1;
aoqi@0 1160
aoqi@0 1161 // Allocate memory to store global-refs to the thread groups.
aoqi@0 1162 // Assume this area is freed by caller.
aoqi@0 1163 *groups_ptr = (jthreadGroup *) jvmtiMalloc((sizeof(jthreadGroup)) * (*group_count_ptr));
aoqi@0 1164
aoqi@0 1165 NULL_CHECK(*groups_ptr, JVMTI_ERROR_OUT_OF_MEMORY);
aoqi@0 1166
aoqi@0 1167 // Convert oop to Handle, then convert Handle to global-ref.
aoqi@0 1168 {
aoqi@0 1169 HandleMark hm(current_thread);
aoqi@0 1170 Handle system_thread_group(current_thread, Universe::system_thread_group());
aoqi@0 1171 *groups_ptr[0] = jni_reference(system_thread_group);
aoqi@0 1172 }
aoqi@0 1173
aoqi@0 1174 return JVMTI_ERROR_NONE;
aoqi@0 1175 } /* end GetTopThreadGroups */
aoqi@0 1176
aoqi@0 1177
aoqi@0 1178 // info_ptr - pre-checked for NULL
aoqi@0 1179 jvmtiError
aoqi@0 1180 JvmtiEnv::GetThreadGroupInfo(jthreadGroup group, jvmtiThreadGroupInfo* info_ptr) {
aoqi@0 1181 ResourceMark rm;
aoqi@0 1182 HandleMark hm;
aoqi@0 1183
aoqi@0 1184 JavaThread* current_thread = JavaThread::current();
aoqi@0 1185
aoqi@0 1186 Handle group_obj (current_thread, JNIHandles::resolve_external_guard(group));
aoqi@0 1187 NULL_CHECK(group_obj(), JVMTI_ERROR_INVALID_THREAD_GROUP);
aoqi@0 1188
aoqi@0 1189 typeArrayHandle name;
aoqi@0 1190 Handle parent_group;
aoqi@0 1191 bool is_daemon;
aoqi@0 1192 ThreadPriority max_priority;
aoqi@0 1193
fmatte@9511 1194 name = typeArrayHandle(current_thread,
fmatte@9511 1195 java_lang_ThreadGroup::name(group_obj()));
fmatte@9511 1196 parent_group = Handle(current_thread, java_lang_ThreadGroup::parent(group_obj()));
fmatte@9511 1197 is_daemon = java_lang_ThreadGroup::is_daemon(group_obj());
fmatte@9511 1198 max_priority = java_lang_ThreadGroup::maxPriority(group_obj());
aoqi@0 1199
aoqi@0 1200 info_ptr->is_daemon = is_daemon;
aoqi@0 1201 info_ptr->max_priority = max_priority;
aoqi@0 1202 info_ptr->parent = jni_reference(parent_group);
aoqi@0 1203
aoqi@0 1204 if (name() != NULL) {
aoqi@0 1205 const char* n = UNICODE::as_utf8((jchar*) name->base(T_CHAR), name->length());
aoqi@0 1206 info_ptr->name = (char *)jvmtiMalloc(strlen(n)+1);
aoqi@0 1207 NULL_CHECK(info_ptr->name, JVMTI_ERROR_OUT_OF_MEMORY);
aoqi@0 1208 strcpy(info_ptr->name, n);
aoqi@0 1209 } else {
aoqi@0 1210 info_ptr->name = NULL;
aoqi@0 1211 }
aoqi@0 1212
aoqi@0 1213 return JVMTI_ERROR_NONE;
aoqi@0 1214 } /* end GetThreadGroupInfo */
aoqi@0 1215
aoqi@0 1216
aoqi@0 1217 // thread_count_ptr - pre-checked for NULL
aoqi@0 1218 // threads_ptr - pre-checked for NULL
aoqi@0 1219 // group_count_ptr - pre-checked for NULL
aoqi@0 1220 // groups_ptr - pre-checked for NULL
aoqi@0 1221 jvmtiError
aoqi@0 1222 JvmtiEnv::GetThreadGroupChildren(jthreadGroup group, jint* thread_count_ptr, jthread** threads_ptr, jint* group_count_ptr, jthreadGroup** groups_ptr) {
aoqi@0 1223 JavaThread* current_thread = JavaThread::current();
aoqi@0 1224 oop group_obj = (oop) JNIHandles::resolve_external_guard(group);
aoqi@0 1225 NULL_CHECK(group_obj, JVMTI_ERROR_INVALID_THREAD_GROUP);
aoqi@0 1226
aoqi@0 1227 Handle *thread_objs = NULL;
aoqi@0 1228 Handle *group_objs = NULL;
aoqi@0 1229 int nthreads = 0;
aoqi@0 1230 int ngroups = 0;
aoqi@0 1231 int hidden_threads = 0;
aoqi@0 1232
aoqi@0 1233 ResourceMark rm;
aoqi@0 1234 HandleMark hm;
aoqi@0 1235
aoqi@0 1236 Handle group_hdl(current_thread, group_obj);
aoqi@0 1237
fmatte@9511 1238 {
fmatte@9511 1239 ObjectLocker ol(group_hdl, current_thread);
aoqi@0 1240 nthreads = java_lang_ThreadGroup::nthreads(group_hdl());
aoqi@0 1241 ngroups = java_lang_ThreadGroup::ngroups(group_hdl());
aoqi@0 1242
aoqi@0 1243 if (nthreads > 0) {
aoqi@0 1244 objArrayOop threads = java_lang_ThreadGroup::threads(group_hdl());
aoqi@0 1245 assert(nthreads <= threads->length(), "too many threads");
aoqi@0 1246 thread_objs = NEW_RESOURCE_ARRAY(Handle,nthreads);
fmatte@9511 1247 for (int i = 0, j = 0; i < nthreads; i++) {
aoqi@0 1248 oop thread_obj = threads->obj_at(i);
aoqi@0 1249 assert(thread_obj != NULL, "thread_obj is NULL");
aoqi@0 1250 JavaThread *javathread = java_lang_Thread::thread(thread_obj);
aoqi@0 1251 // Filter out hidden java threads.
aoqi@0 1252 if (javathread != NULL && javathread->is_hidden_from_external_view()) {
aoqi@0 1253 hidden_threads++;
aoqi@0 1254 continue;
aoqi@0 1255 }
aoqi@0 1256 thread_objs[j++] = Handle(current_thread, thread_obj);
aoqi@0 1257 }
aoqi@0 1258 nthreads -= hidden_threads;
aoqi@0 1259 }
aoqi@0 1260 if (ngroups > 0) {
aoqi@0 1261 objArrayOop groups = java_lang_ThreadGroup::groups(group_hdl());
aoqi@0 1262 assert(ngroups <= groups->length(), "too many threads");
aoqi@0 1263 group_objs = NEW_RESOURCE_ARRAY(Handle,ngroups);
fmatte@9511 1264 for (int i = 0; i < ngroups; i++) {
aoqi@0 1265 oop group_obj = groups->obj_at(i);
aoqi@0 1266 assert(group_obj != NULL, "group_obj != NULL");
aoqi@0 1267 group_objs[i] = Handle(current_thread, group_obj);
aoqi@0 1268 }
aoqi@0 1269 }
fmatte@9511 1270 } // ThreadGroup unlocked here
fmatte@9511 1271
aoqi@0 1272 *group_count_ptr = ngroups;
aoqi@0 1273 *thread_count_ptr = nthreads;
aoqi@0 1274 *threads_ptr = new_jthreadArray(nthreads, thread_objs);
aoqi@0 1275 *groups_ptr = new_jthreadGroupArray(ngroups, group_objs);
aoqi@0 1276 if ((nthreads > 0) && (*threads_ptr == NULL)) {
aoqi@0 1277 return JVMTI_ERROR_OUT_OF_MEMORY;
aoqi@0 1278 }
aoqi@0 1279 if ((ngroups > 0) && (*groups_ptr == NULL)) {
aoqi@0 1280 return JVMTI_ERROR_OUT_OF_MEMORY;
aoqi@0 1281 }
aoqi@0 1282
aoqi@0 1283 return JVMTI_ERROR_NONE;
aoqi@0 1284 } /* end GetThreadGroupChildren */
aoqi@0 1285
aoqi@0 1286
aoqi@0 1287 //
aoqi@0 1288 // Stack Frame functions
aoqi@0 1289 //
aoqi@0 1290
aoqi@0 1291 // Threads_lock NOT held, java_thread not protected by lock
aoqi@0 1292 // java_thread - pre-checked
aoqi@0 1293 // max_frame_count - pre-checked to be greater than or equal to 0
aoqi@0 1294 // frame_buffer - pre-checked for NULL
aoqi@0 1295 // count_ptr - pre-checked for NULL
aoqi@0 1296 jvmtiError
aoqi@0 1297 JvmtiEnv::GetStackTrace(JavaThread* java_thread, jint start_depth, jint max_frame_count, jvmtiFrameInfo* frame_buffer, jint* count_ptr) {
aoqi@0 1298 jvmtiError err = JVMTI_ERROR_NONE;
sspitsyn@8714 1299
sspitsyn@8714 1300 // It is only safe to perform the direct operation on the current
sspitsyn@8714 1301 // thread. All other usage needs to use a vm-safepoint-op for safety.
sspitsyn@8714 1302 if (java_thread == JavaThread::current()) {
aoqi@0 1303 err = get_stack_trace(java_thread, start_depth, max_frame_count, frame_buffer, count_ptr);
aoqi@0 1304 } else {
aoqi@0 1305 // JVMTI get stack trace at safepoint. Do not require target thread to
aoqi@0 1306 // be suspended.
aoqi@0 1307 VM_GetStackTrace op(this, java_thread, start_depth, max_frame_count, frame_buffer, count_ptr);
aoqi@0 1308 VMThread::execute(&op);
aoqi@0 1309 err = op.result();
aoqi@0 1310 }
aoqi@0 1311
aoqi@0 1312 return err;
aoqi@0 1313 } /* end GetStackTrace */
aoqi@0 1314
aoqi@0 1315
aoqi@0 1316 // max_frame_count - pre-checked to be greater than or equal to 0
aoqi@0 1317 // stack_info_ptr - pre-checked for NULL
aoqi@0 1318 // thread_count_ptr - pre-checked for NULL
aoqi@0 1319 jvmtiError
aoqi@0 1320 JvmtiEnv::GetAllStackTraces(jint max_frame_count, jvmtiStackInfo** stack_info_ptr, jint* thread_count_ptr) {
aoqi@0 1321 jvmtiError err = JVMTI_ERROR_NONE;
aoqi@0 1322 JavaThread* calling_thread = JavaThread::current();
aoqi@0 1323
aoqi@0 1324 // JVMTI get stack traces at safepoint.
aoqi@0 1325 VM_GetAllStackTraces op(this, calling_thread, max_frame_count);
aoqi@0 1326 VMThread::execute(&op);
aoqi@0 1327 *thread_count_ptr = op.final_thread_count();
aoqi@0 1328 *stack_info_ptr = op.stack_info();
aoqi@0 1329 err = op.result();
aoqi@0 1330 return err;
aoqi@0 1331 } /* end GetAllStackTraces */
aoqi@0 1332
aoqi@0 1333
aoqi@0 1334 // thread_count - pre-checked to be greater than or equal to 0
aoqi@0 1335 // thread_list - pre-checked for NULL
aoqi@0 1336 // max_frame_count - pre-checked to be greater than or equal to 0
aoqi@0 1337 // stack_info_ptr - pre-checked for NULL
aoqi@0 1338 jvmtiError
aoqi@0 1339 JvmtiEnv::GetThreadListStackTraces(jint thread_count, const jthread* thread_list, jint max_frame_count, jvmtiStackInfo** stack_info_ptr) {
aoqi@0 1340 jvmtiError err = JVMTI_ERROR_NONE;
aoqi@0 1341 // JVMTI get stack traces at safepoint.
aoqi@0 1342 VM_GetThreadListStackTraces op(this, thread_count, thread_list, max_frame_count);
aoqi@0 1343 VMThread::execute(&op);
aoqi@0 1344 err = op.result();
aoqi@0 1345 if (err == JVMTI_ERROR_NONE) {
aoqi@0 1346 *stack_info_ptr = op.stack_info();
aoqi@0 1347 }
aoqi@0 1348 return err;
aoqi@0 1349 } /* end GetThreadListStackTraces */
aoqi@0 1350
aoqi@0 1351
aoqi@0 1352 // Threads_lock NOT held, java_thread not protected by lock
aoqi@0 1353 // java_thread - pre-checked
aoqi@0 1354 // count_ptr - pre-checked for NULL
aoqi@0 1355 jvmtiError
aoqi@0 1356 JvmtiEnv::GetFrameCount(JavaThread* java_thread, jint* count_ptr) {
aoqi@0 1357 jvmtiError err = JVMTI_ERROR_NONE;
aoqi@0 1358
aoqi@0 1359 // retrieve or create JvmtiThreadState.
aoqi@0 1360 JvmtiThreadState* state = JvmtiThreadState::state_for(java_thread);
aoqi@0 1361 if (state == NULL) {
aoqi@0 1362 return JVMTI_ERROR_THREAD_NOT_ALIVE;
aoqi@0 1363 }
aoqi@0 1364 uint32_t debug_bits = 0;
aoqi@0 1365 if (is_thread_fully_suspended(java_thread, true, &debug_bits)) {
aoqi@0 1366 err = get_frame_count(state, count_ptr);
aoqi@0 1367 } else {
aoqi@0 1368 // get java stack frame count at safepoint.
aoqi@0 1369 VM_GetFrameCount op(this, state, count_ptr);
aoqi@0 1370 VMThread::execute(&op);
aoqi@0 1371 err = op.result();
aoqi@0 1372 }
aoqi@0 1373 return err;
aoqi@0 1374 } /* end GetFrameCount */
aoqi@0 1375
aoqi@0 1376
aoqi@0 1377 // Threads_lock NOT held, java_thread not protected by lock
aoqi@0 1378 // java_thread - pre-checked
aoqi@0 1379 jvmtiError
aoqi@0 1380 JvmtiEnv::PopFrame(JavaThread* java_thread) {
aoqi@0 1381 JavaThread* current_thread = JavaThread::current();
aoqi@0 1382 HandleMark hm(current_thread);
aoqi@0 1383 uint32_t debug_bits = 0;
aoqi@0 1384
aoqi@0 1385 // retrieve or create the state
aoqi@0 1386 JvmtiThreadState* state = JvmtiThreadState::state_for(java_thread);
aoqi@0 1387 if (state == NULL) {
aoqi@0 1388 return JVMTI_ERROR_THREAD_NOT_ALIVE;
aoqi@0 1389 }
aoqi@0 1390
aoqi@0 1391 // Check if java_thread is fully suspended
aoqi@0 1392 if (!is_thread_fully_suspended(java_thread, true /* wait for suspend completion */, &debug_bits)) {
aoqi@0 1393 return JVMTI_ERROR_THREAD_NOT_SUSPENDED;
aoqi@0 1394 }
aoqi@0 1395 // Check to see if a PopFrame was already in progress
aoqi@0 1396 if (java_thread->popframe_condition() != JavaThread::popframe_inactive) {
aoqi@0 1397 // Probably possible for JVMTI clients to trigger this, but the
aoqi@0 1398 // JPDA backend shouldn't allow this to happen
aoqi@0 1399 return JVMTI_ERROR_INTERNAL;
aoqi@0 1400 }
aoqi@0 1401
aoqi@0 1402 {
aoqi@0 1403 // Was workaround bug
aoqi@0 1404 // 4812902: popFrame hangs if the method is waiting at a synchronize
aoqi@0 1405 // Catch this condition and return an error to avoid hanging.
aoqi@0 1406 // Now JVMTI spec allows an implementation to bail out with an opaque frame error.
aoqi@0 1407 OSThread* osThread = java_thread->osthread();
aoqi@0 1408 if (osThread->get_state() == MONITOR_WAIT) {
aoqi@0 1409 return JVMTI_ERROR_OPAQUE_FRAME;
aoqi@0 1410 }
aoqi@0 1411 }
aoqi@0 1412
aoqi@0 1413 {
aoqi@0 1414 ResourceMark rm(current_thread);
aoqi@0 1415 // Check if there are more than one Java frame in this thread, that the top two frames
aoqi@0 1416 // are Java (not native) frames, and that there is no intervening VM frame
aoqi@0 1417 int frame_count = 0;
aoqi@0 1418 bool is_interpreted[2];
aoqi@0 1419 intptr_t *frame_sp[2];
aoqi@0 1420 // The 2-nd arg of constructor is needed to stop iterating at java entry frame.
aoqi@0 1421 for (vframeStream vfs(java_thread, true); !vfs.at_end(); vfs.next()) {
aoqi@0 1422 methodHandle mh(current_thread, vfs.method());
aoqi@0 1423 if (mh->is_native()) return(JVMTI_ERROR_OPAQUE_FRAME);
aoqi@0 1424 is_interpreted[frame_count] = vfs.is_interpreted_frame();
aoqi@0 1425 frame_sp[frame_count] = vfs.frame_id();
aoqi@0 1426 if (++frame_count > 1) break;
aoqi@0 1427 }
aoqi@0 1428 if (frame_count < 2) {
aoqi@0 1429 // We haven't found two adjacent non-native Java frames on the top.
aoqi@0 1430 // There can be two situations here:
aoqi@0 1431 // 1. There are no more java frames
aoqi@0 1432 // 2. Two top java frames are separated by non-java native frames
aoqi@0 1433 if(vframeFor(java_thread, 1) == NULL) {
aoqi@0 1434 return JVMTI_ERROR_NO_MORE_FRAMES;
aoqi@0 1435 } else {
aoqi@0 1436 // Intervening non-java native or VM frames separate java frames.
aoqi@0 1437 // Current implementation does not support this. See bug #5031735.
aoqi@0 1438 // In theory it is possible to pop frames in such cases.
aoqi@0 1439 return JVMTI_ERROR_OPAQUE_FRAME;
aoqi@0 1440 }
aoqi@0 1441 }
aoqi@0 1442
aoqi@0 1443 // If any of the top 2 frames is a compiled one, need to deoptimize it
aoqi@0 1444 for (int i = 0; i < 2; i++) {
aoqi@0 1445 if (!is_interpreted[i]) {
aoqi@0 1446 Deoptimization::deoptimize_frame(java_thread, frame_sp[i]);
aoqi@0 1447 }
aoqi@0 1448 }
aoqi@0 1449
aoqi@0 1450 // Update the thread state to reflect that the top frame is popped
aoqi@0 1451 // so that cur_stack_depth is maintained properly and all frameIDs
aoqi@0 1452 // are invalidated.
aoqi@0 1453 // The current frame will be popped later when the suspended thread
aoqi@0 1454 // is resumed and right before returning from VM to Java.
aoqi@0 1455 // (see call_VM_base() in assembler_<cpu>.cpp).
aoqi@0 1456
aoqi@0 1457 // It's fine to update the thread state here because no JVMTI events
aoqi@0 1458 // shall be posted for this PopFrame.
aoqi@0 1459
aoqi@0 1460 state->update_for_pop_top_frame();
aoqi@0 1461 java_thread->set_popframe_condition(JavaThread::popframe_pending_bit);
aoqi@0 1462 // Set pending step flag for this popframe and it is cleared when next
aoqi@0 1463 // step event is posted.
aoqi@0 1464 state->set_pending_step_for_popframe();
aoqi@0 1465 }
aoqi@0 1466
aoqi@0 1467 return JVMTI_ERROR_NONE;
aoqi@0 1468 } /* end PopFrame */
aoqi@0 1469
aoqi@0 1470
aoqi@0 1471 // Threads_lock NOT held, java_thread not protected by lock
aoqi@0 1472 // java_thread - pre-checked
aoqi@0 1473 // java_thread - unchecked
aoqi@0 1474 // depth - pre-checked as non-negative
aoqi@0 1475 // method_ptr - pre-checked for NULL
aoqi@0 1476 // location_ptr - pre-checked for NULL
aoqi@0 1477 jvmtiError
aoqi@0 1478 JvmtiEnv::GetFrameLocation(JavaThread* java_thread, jint depth, jmethodID* method_ptr, jlocation* location_ptr) {
aoqi@0 1479 jvmtiError err = JVMTI_ERROR_NONE;
aoqi@0 1480 uint32_t debug_bits = 0;
aoqi@0 1481
aoqi@0 1482 if (is_thread_fully_suspended(java_thread, true, &debug_bits)) {
aoqi@0 1483 err = get_frame_location(java_thread, depth, method_ptr, location_ptr);
aoqi@0 1484 } else {
aoqi@0 1485 // JVMTI get java stack frame location at safepoint.
aoqi@0 1486 VM_GetFrameLocation op(this, java_thread, depth, method_ptr, location_ptr);
aoqi@0 1487 VMThread::execute(&op);
aoqi@0 1488 err = op.result();
aoqi@0 1489 }
aoqi@0 1490 return err;
aoqi@0 1491 } /* end GetFrameLocation */
aoqi@0 1492
aoqi@0 1493
aoqi@0 1494 // Threads_lock NOT held, java_thread not protected by lock
aoqi@0 1495 // java_thread - pre-checked
aoqi@0 1496 // java_thread - unchecked
aoqi@0 1497 // depth - pre-checked as non-negative
aoqi@0 1498 jvmtiError
aoqi@0 1499 JvmtiEnv::NotifyFramePop(JavaThread* java_thread, jint depth) {
aoqi@0 1500 ResourceMark rm;
aoqi@0 1501 uint32_t debug_bits = 0;
aoqi@0 1502
aoqi@0 1503 JvmtiThreadState *state = JvmtiThreadState::state_for(java_thread);
aoqi@0 1504 if (state == NULL) {
aoqi@0 1505 return JVMTI_ERROR_THREAD_NOT_ALIVE;
aoqi@0 1506 }
aoqi@0 1507
aoqi@0 1508 if (!JvmtiEnv::is_thread_fully_suspended(java_thread, true, &debug_bits)) {
aoqi@0 1509 return JVMTI_ERROR_THREAD_NOT_SUSPENDED;
aoqi@0 1510 }
aoqi@0 1511
aoqi@0 1512 if (TraceJVMTICalls) {
aoqi@0 1513 JvmtiSuspendControl::print();
aoqi@0 1514 }
aoqi@0 1515
aoqi@0 1516 vframe *vf = vframeFor(java_thread, depth);
aoqi@0 1517 if (vf == NULL) {
aoqi@0 1518 return JVMTI_ERROR_NO_MORE_FRAMES;
aoqi@0 1519 }
aoqi@0 1520
aoqi@0 1521 if (!vf->is_java_frame() || ((javaVFrame*) vf)->method()->is_native()) {
aoqi@0 1522 return JVMTI_ERROR_OPAQUE_FRAME;
aoqi@0 1523 }
aoqi@0 1524
aoqi@0 1525 assert(vf->frame_pointer() != NULL, "frame pointer mustn't be NULL");
aoqi@0 1526
aoqi@0 1527 int frame_number = state->count_frames() - depth;
aoqi@0 1528 state->env_thread_state(this)->set_frame_pop(frame_number);
aoqi@0 1529
aoqi@0 1530 return JVMTI_ERROR_NONE;
aoqi@0 1531 } /* end NotifyFramePop */
aoqi@0 1532
aoqi@0 1533
aoqi@0 1534 //
aoqi@0 1535 // Force Early Return functions
aoqi@0 1536 //
aoqi@0 1537
aoqi@0 1538 // Threads_lock NOT held, java_thread not protected by lock
aoqi@0 1539 // java_thread - pre-checked
aoqi@0 1540 jvmtiError
aoqi@0 1541 JvmtiEnv::ForceEarlyReturnObject(JavaThread* java_thread, jobject value) {
aoqi@0 1542 jvalue val;
aoqi@0 1543 val.l = value;
aoqi@0 1544 return force_early_return(java_thread, val, atos);
aoqi@0 1545 } /* end ForceEarlyReturnObject */
aoqi@0 1546
aoqi@0 1547
aoqi@0 1548 // Threads_lock NOT held, java_thread not protected by lock
aoqi@0 1549 // java_thread - pre-checked
aoqi@0 1550 jvmtiError
aoqi@0 1551 JvmtiEnv::ForceEarlyReturnInt(JavaThread* java_thread, jint value) {
aoqi@0 1552 jvalue val;
aoqi@0 1553 val.i = value;
aoqi@0 1554 return force_early_return(java_thread, val, itos);
aoqi@0 1555 } /* end ForceEarlyReturnInt */
aoqi@0 1556
aoqi@0 1557
aoqi@0 1558 // Threads_lock NOT held, java_thread not protected by lock
aoqi@0 1559 // java_thread - pre-checked
aoqi@0 1560 jvmtiError
aoqi@0 1561 JvmtiEnv::ForceEarlyReturnLong(JavaThread* java_thread, jlong value) {
aoqi@0 1562 jvalue val;
aoqi@0 1563 val.j = value;
aoqi@0 1564 return force_early_return(java_thread, val, ltos);
aoqi@0 1565 } /* end ForceEarlyReturnLong */
aoqi@0 1566
aoqi@0 1567
aoqi@0 1568 // Threads_lock NOT held, java_thread not protected by lock
aoqi@0 1569 // java_thread - pre-checked
aoqi@0 1570 jvmtiError
aoqi@0 1571 JvmtiEnv::ForceEarlyReturnFloat(JavaThread* java_thread, jfloat value) {
aoqi@0 1572 jvalue val;
aoqi@0 1573 val.f = value;
aoqi@0 1574 return force_early_return(java_thread, val, ftos);
aoqi@0 1575 } /* end ForceEarlyReturnFloat */
aoqi@0 1576
aoqi@0 1577
aoqi@0 1578 // Threads_lock NOT held, java_thread not protected by lock
aoqi@0 1579 // java_thread - pre-checked
aoqi@0 1580 jvmtiError
aoqi@0 1581 JvmtiEnv::ForceEarlyReturnDouble(JavaThread* java_thread, jdouble value) {
aoqi@0 1582 jvalue val;
aoqi@0 1583 val.d = value;
aoqi@0 1584 return force_early_return(java_thread, val, dtos);
aoqi@0 1585 } /* end ForceEarlyReturnDouble */
aoqi@0 1586
aoqi@0 1587
aoqi@0 1588 // Threads_lock NOT held, java_thread not protected by lock
aoqi@0 1589 // java_thread - pre-checked
aoqi@0 1590 jvmtiError
aoqi@0 1591 JvmtiEnv::ForceEarlyReturnVoid(JavaThread* java_thread) {
aoqi@0 1592 jvalue val;
aoqi@0 1593 val.j = 0L;
aoqi@0 1594 return force_early_return(java_thread, val, vtos);
aoqi@0 1595 } /* end ForceEarlyReturnVoid */
aoqi@0 1596
aoqi@0 1597
aoqi@0 1598 //
aoqi@0 1599 // Heap functions
aoqi@0 1600 //
aoqi@0 1601
aoqi@0 1602 // klass - NULL is a valid value, must be checked
aoqi@0 1603 // initial_object - NULL is a valid value, must be checked
aoqi@0 1604 // callbacks - pre-checked for NULL
aoqi@0 1605 // user_data - NULL is a valid value, must be checked
aoqi@0 1606 jvmtiError
aoqi@0 1607 JvmtiEnv::FollowReferences(jint heap_filter, jclass klass, jobject initial_object, const jvmtiHeapCallbacks* callbacks, const void* user_data) {
aoqi@0 1608 // check klass if provided
aoqi@0 1609 Klass* k_oop = NULL;
aoqi@0 1610 if (klass != NULL) {
aoqi@0 1611 oop k_mirror = JNIHandles::resolve_external_guard(klass);
aoqi@0 1612 if (k_mirror == NULL) {
aoqi@0 1613 return JVMTI_ERROR_INVALID_CLASS;
aoqi@0 1614 }
aoqi@0 1615 if (java_lang_Class::is_primitive(k_mirror)) {
aoqi@0 1616 return JVMTI_ERROR_NONE;
aoqi@0 1617 }
aoqi@0 1618 k_oop = java_lang_Class::as_Klass(k_mirror);
aoqi@0 1619 if (k_oop == NULL) {
aoqi@0 1620 return JVMTI_ERROR_INVALID_CLASS;
aoqi@0 1621 }
aoqi@0 1622 }
aoqi@0 1623
aoqi@0 1624 Thread *thread = Thread::current();
aoqi@0 1625 HandleMark hm(thread);
aoqi@0 1626 KlassHandle kh (thread, k_oop);
aoqi@0 1627
aoqi@0 1628 TraceTime t("FollowReferences", TraceJVMTIObjectTagging);
aoqi@0 1629 JvmtiTagMap::tag_map_for(this)->follow_references(heap_filter, kh, initial_object, callbacks, user_data);
aoqi@0 1630 return JVMTI_ERROR_NONE;
aoqi@0 1631 } /* end FollowReferences */
aoqi@0 1632
aoqi@0 1633
aoqi@0 1634 // klass - NULL is a valid value, must be checked
aoqi@0 1635 // callbacks - pre-checked for NULL
aoqi@0 1636 // user_data - NULL is a valid value, must be checked
aoqi@0 1637 jvmtiError
aoqi@0 1638 JvmtiEnv::IterateThroughHeap(jint heap_filter, jclass klass, const jvmtiHeapCallbacks* callbacks, const void* user_data) {
aoqi@0 1639 // check klass if provided
aoqi@0 1640 Klass* k_oop = NULL;
aoqi@0 1641 if (klass != NULL) {
aoqi@0 1642 oop k_mirror = JNIHandles::resolve_external_guard(klass);
aoqi@0 1643 if (k_mirror == NULL) {
aoqi@0 1644 return JVMTI_ERROR_INVALID_CLASS;
aoqi@0 1645 }
aoqi@0 1646 if (java_lang_Class::is_primitive(k_mirror)) {
aoqi@0 1647 return JVMTI_ERROR_NONE;
aoqi@0 1648 }
aoqi@0 1649 k_oop = java_lang_Class::as_Klass(k_mirror);
aoqi@0 1650 if (k_oop == NULL) {
aoqi@0 1651 return JVMTI_ERROR_INVALID_CLASS;
aoqi@0 1652 }
aoqi@0 1653 }
aoqi@0 1654
aoqi@0 1655 Thread *thread = Thread::current();
aoqi@0 1656 HandleMark hm(thread);
aoqi@0 1657 KlassHandle kh (thread, k_oop);
aoqi@0 1658
aoqi@0 1659 TraceTime t("IterateThroughHeap", TraceJVMTIObjectTagging);
aoqi@0 1660 JvmtiTagMap::tag_map_for(this)->iterate_through_heap(heap_filter, kh, callbacks, user_data);
aoqi@0 1661 return JVMTI_ERROR_NONE;
aoqi@0 1662 } /* end IterateThroughHeap */
aoqi@0 1663
aoqi@0 1664
aoqi@0 1665 // tag_ptr - pre-checked for NULL
aoqi@0 1666 jvmtiError
aoqi@0 1667 JvmtiEnv::GetTag(jobject object, jlong* tag_ptr) {
aoqi@0 1668 oop o = JNIHandles::resolve_external_guard(object);
aoqi@0 1669 NULL_CHECK(o, JVMTI_ERROR_INVALID_OBJECT);
aoqi@0 1670 *tag_ptr = JvmtiTagMap::tag_map_for(this)->get_tag(object);
aoqi@0 1671 return JVMTI_ERROR_NONE;
aoqi@0 1672 } /* end GetTag */
aoqi@0 1673
aoqi@0 1674
aoqi@0 1675 jvmtiError
aoqi@0 1676 JvmtiEnv::SetTag(jobject object, jlong tag) {
aoqi@0 1677 oop o = JNIHandles::resolve_external_guard(object);
aoqi@0 1678 NULL_CHECK(o, JVMTI_ERROR_INVALID_OBJECT);
aoqi@0 1679 JvmtiTagMap::tag_map_for(this)->set_tag(object, tag);
aoqi@0 1680 return JVMTI_ERROR_NONE;
aoqi@0 1681 } /* end SetTag */
aoqi@0 1682
aoqi@0 1683
aoqi@0 1684 // tag_count - pre-checked to be greater than or equal to 0
aoqi@0 1685 // tags - pre-checked for NULL
aoqi@0 1686 // count_ptr - pre-checked for NULL
aoqi@0 1687 // object_result_ptr - NULL is a valid value, must be checked
aoqi@0 1688 // tag_result_ptr - NULL is a valid value, must be checked
aoqi@0 1689 jvmtiError
aoqi@0 1690 JvmtiEnv::GetObjectsWithTags(jint tag_count, const jlong* tags, jint* count_ptr, jobject** object_result_ptr, jlong** tag_result_ptr) {
aoqi@0 1691 TraceTime t("GetObjectsWithTags", TraceJVMTIObjectTagging);
aoqi@0 1692 return JvmtiTagMap::tag_map_for(this)->get_objects_with_tags((jlong*)tags, tag_count, count_ptr, object_result_ptr, tag_result_ptr);
aoqi@0 1693 } /* end GetObjectsWithTags */
aoqi@0 1694
aoqi@0 1695
aoqi@0 1696 jvmtiError
aoqi@0 1697 JvmtiEnv::ForceGarbageCollection() {
aoqi@0 1698 Universe::heap()->collect(GCCause::_jvmti_force_gc);
aoqi@0 1699 return JVMTI_ERROR_NONE;
aoqi@0 1700 } /* end ForceGarbageCollection */
aoqi@0 1701
aoqi@0 1702
aoqi@0 1703 //
aoqi@0 1704 // Heap (1.0) functions
aoqi@0 1705 //
aoqi@0 1706
aoqi@0 1707 // object_reference_callback - pre-checked for NULL
aoqi@0 1708 // user_data - NULL is a valid value, must be checked
aoqi@0 1709 jvmtiError
aoqi@0 1710 JvmtiEnv::IterateOverObjectsReachableFromObject(jobject object, jvmtiObjectReferenceCallback object_reference_callback, const void* user_data) {
aoqi@0 1711 oop o = JNIHandles::resolve_external_guard(object);
aoqi@0 1712 NULL_CHECK(o, JVMTI_ERROR_INVALID_OBJECT);
aoqi@0 1713 JvmtiTagMap::tag_map_for(this)->iterate_over_objects_reachable_from_object(object, object_reference_callback, user_data);
aoqi@0 1714 return JVMTI_ERROR_NONE;
aoqi@0 1715 } /* end IterateOverObjectsReachableFromObject */
aoqi@0 1716
aoqi@0 1717
aoqi@0 1718 // heap_root_callback - NULL is a valid value, must be checked
aoqi@0 1719 // stack_ref_callback - NULL is a valid value, must be checked
aoqi@0 1720 // object_ref_callback - NULL is a valid value, must be checked
aoqi@0 1721 // user_data - NULL is a valid value, must be checked
aoqi@0 1722 jvmtiError
aoqi@0 1723 JvmtiEnv::IterateOverReachableObjects(jvmtiHeapRootCallback heap_root_callback, jvmtiStackReferenceCallback stack_ref_callback, jvmtiObjectReferenceCallback object_ref_callback, const void* user_data) {
aoqi@0 1724 TraceTime t("IterateOverReachableObjects", TraceJVMTIObjectTagging);
aoqi@0 1725 JvmtiTagMap::tag_map_for(this)->iterate_over_reachable_objects(heap_root_callback, stack_ref_callback, object_ref_callback, user_data);
aoqi@0 1726 return JVMTI_ERROR_NONE;
aoqi@0 1727 } /* end IterateOverReachableObjects */
aoqi@0 1728
aoqi@0 1729
aoqi@0 1730 // heap_object_callback - pre-checked for NULL
aoqi@0 1731 // user_data - NULL is a valid value, must be checked
aoqi@0 1732 jvmtiError
aoqi@0 1733 JvmtiEnv::IterateOverHeap(jvmtiHeapObjectFilter object_filter, jvmtiHeapObjectCallback heap_object_callback, const void* user_data) {
aoqi@0 1734 TraceTime t("IterateOverHeap", TraceJVMTIObjectTagging);
aoqi@0 1735 Thread *thread = Thread::current();
aoqi@0 1736 HandleMark hm(thread);
aoqi@0 1737 JvmtiTagMap::tag_map_for(this)->iterate_over_heap(object_filter, KlassHandle(), heap_object_callback, user_data);
aoqi@0 1738 return JVMTI_ERROR_NONE;
aoqi@0 1739 } /* end IterateOverHeap */
aoqi@0 1740
aoqi@0 1741
aoqi@0 1742 // k_mirror - may be primitive, this must be checked
aoqi@0 1743 // heap_object_callback - pre-checked for NULL
aoqi@0 1744 // user_data - NULL is a valid value, must be checked
aoqi@0 1745 jvmtiError
aoqi@0 1746 JvmtiEnv::IterateOverInstancesOfClass(oop k_mirror, jvmtiHeapObjectFilter object_filter, jvmtiHeapObjectCallback heap_object_callback, const void* user_data) {
aoqi@0 1747 if (java_lang_Class::is_primitive(k_mirror)) {
aoqi@0 1748 // DO PRIMITIVE CLASS PROCESSING
aoqi@0 1749 return JVMTI_ERROR_NONE;
aoqi@0 1750 }
aoqi@0 1751 Klass* k_oop = java_lang_Class::as_Klass(k_mirror);
aoqi@0 1752 if (k_oop == NULL) {
aoqi@0 1753 return JVMTI_ERROR_INVALID_CLASS;
aoqi@0 1754 }
aoqi@0 1755 Thread *thread = Thread::current();
aoqi@0 1756 HandleMark hm(thread);
aoqi@0 1757 KlassHandle klass (thread, k_oop);
aoqi@0 1758 TraceTime t("IterateOverInstancesOfClass", TraceJVMTIObjectTagging);
aoqi@0 1759 JvmtiTagMap::tag_map_for(this)->iterate_over_heap(object_filter, klass, heap_object_callback, user_data);
aoqi@0 1760 return JVMTI_ERROR_NONE;
aoqi@0 1761 } /* end IterateOverInstancesOfClass */
aoqi@0 1762
aoqi@0 1763
aoqi@0 1764 //
aoqi@0 1765 // Local Variable functions
aoqi@0 1766 //
aoqi@0 1767
aoqi@0 1768 // Threads_lock NOT held, java_thread not protected by lock
aoqi@0 1769 // java_thread - pre-checked
aoqi@0 1770 // java_thread - unchecked
aoqi@0 1771 // depth - pre-checked as non-negative
aoqi@0 1772 // value_ptr - pre-checked for NULL
aoqi@0 1773 jvmtiError
aoqi@0 1774 JvmtiEnv::GetLocalObject(JavaThread* java_thread, jint depth, jint slot, jobject* value_ptr) {
aoqi@0 1775 JavaThread* current_thread = JavaThread::current();
aoqi@0 1776 // rm object is created to clean up the javaVFrame created in
aoqi@0 1777 // doit_prologue(), but after doit() is finished with it.
aoqi@0 1778 ResourceMark rm(current_thread);
aoqi@0 1779
aoqi@0 1780 VM_GetOrSetLocal op(java_thread, current_thread, depth, slot);
aoqi@0 1781 VMThread::execute(&op);
aoqi@0 1782 jvmtiError err = op.result();
aoqi@0 1783 if (err != JVMTI_ERROR_NONE) {
aoqi@0 1784 return err;
aoqi@0 1785 } else {
aoqi@0 1786 *value_ptr = op.value().l;
aoqi@0 1787 return JVMTI_ERROR_NONE;
aoqi@0 1788 }
aoqi@0 1789 } /* end GetLocalObject */
aoqi@0 1790
aoqi@0 1791 // Threads_lock NOT held, java_thread not protected by lock
aoqi@0 1792 // java_thread - pre-checked
aoqi@0 1793 // java_thread - unchecked
aoqi@0 1794 // depth - pre-checked as non-negative
aoqi@0 1795 // value - pre-checked for NULL
aoqi@0 1796 jvmtiError
aoqi@0 1797 JvmtiEnv::GetLocalInstance(JavaThread* java_thread, jint depth, jobject* value_ptr){
aoqi@0 1798 JavaThread* current_thread = JavaThread::current();
aoqi@0 1799 // rm object is created to clean up the javaVFrame created in
aoqi@0 1800 // doit_prologue(), but after doit() is finished with it.
aoqi@0 1801 ResourceMark rm(current_thread);
aoqi@0 1802
aoqi@0 1803 VM_GetReceiver op(java_thread, current_thread, depth);
aoqi@0 1804 VMThread::execute(&op);
aoqi@0 1805 jvmtiError err = op.result();
aoqi@0 1806 if (err != JVMTI_ERROR_NONE) {
aoqi@0 1807 return err;
aoqi@0 1808 } else {
aoqi@0 1809 *value_ptr = op.value().l;
aoqi@0 1810 return JVMTI_ERROR_NONE;
aoqi@0 1811 }
aoqi@0 1812 } /* end GetLocalInstance */
aoqi@0 1813
aoqi@0 1814
aoqi@0 1815 // Threads_lock NOT held, java_thread not protected by lock
aoqi@0 1816 // java_thread - pre-checked
aoqi@0 1817 // java_thread - unchecked
aoqi@0 1818 // depth - pre-checked as non-negative
aoqi@0 1819 // value_ptr - pre-checked for NULL
aoqi@0 1820 jvmtiError
aoqi@0 1821 JvmtiEnv::GetLocalInt(JavaThread* java_thread, jint depth, jint slot, jint* value_ptr) {
aoqi@0 1822 // rm object is created to clean up the javaVFrame created in
aoqi@0 1823 // doit_prologue(), but after doit() is finished with it.
aoqi@0 1824 ResourceMark rm;
aoqi@0 1825
aoqi@0 1826 VM_GetOrSetLocal op(java_thread, depth, slot, T_INT);
aoqi@0 1827 VMThread::execute(&op);
aoqi@0 1828 *value_ptr = op.value().i;
aoqi@0 1829 return op.result();
aoqi@0 1830 } /* end GetLocalInt */
aoqi@0 1831
aoqi@0 1832
aoqi@0 1833 // Threads_lock NOT held, java_thread not protected by lock
aoqi@0 1834 // java_thread - pre-checked
aoqi@0 1835 // java_thread - unchecked
aoqi@0 1836 // depth - pre-checked as non-negative
aoqi@0 1837 // value_ptr - pre-checked for NULL
aoqi@0 1838 jvmtiError
aoqi@0 1839 JvmtiEnv::GetLocalLong(JavaThread* java_thread, jint depth, jint slot, jlong* value_ptr) {
aoqi@0 1840 // rm object is created to clean up the javaVFrame created in
aoqi@0 1841 // doit_prologue(), but after doit() is finished with it.
aoqi@0 1842 ResourceMark rm;
aoqi@0 1843
aoqi@0 1844 VM_GetOrSetLocal op(java_thread, depth, slot, T_LONG);
aoqi@0 1845 VMThread::execute(&op);
aoqi@0 1846 *value_ptr = op.value().j;
aoqi@0 1847 return op.result();
aoqi@0 1848 } /* end GetLocalLong */
aoqi@0 1849
aoqi@0 1850
aoqi@0 1851 // Threads_lock NOT held, java_thread not protected by lock
aoqi@0 1852 // java_thread - pre-checked
aoqi@0 1853 // java_thread - unchecked
aoqi@0 1854 // depth - pre-checked as non-negative
aoqi@0 1855 // value_ptr - pre-checked for NULL
aoqi@0 1856 jvmtiError
aoqi@0 1857 JvmtiEnv::GetLocalFloat(JavaThread* java_thread, jint depth, jint slot, jfloat* value_ptr) {
aoqi@0 1858 // rm object is created to clean up the javaVFrame created in
aoqi@0 1859 // doit_prologue(), but after doit() is finished with it.
aoqi@0 1860 ResourceMark rm;
aoqi@0 1861
aoqi@0 1862 VM_GetOrSetLocal op(java_thread, depth, slot, T_FLOAT);
aoqi@0 1863 VMThread::execute(&op);
aoqi@0 1864 *value_ptr = op.value().f;
aoqi@0 1865 return op.result();
aoqi@0 1866 } /* end GetLocalFloat */
aoqi@0 1867
aoqi@0 1868
aoqi@0 1869 // Threads_lock NOT held, java_thread not protected by lock
aoqi@0 1870 // java_thread - pre-checked
aoqi@0 1871 // java_thread - unchecked
aoqi@0 1872 // depth - pre-checked as non-negative
aoqi@0 1873 // value_ptr - pre-checked for NULL
aoqi@0 1874 jvmtiError
aoqi@0 1875 JvmtiEnv::GetLocalDouble(JavaThread* java_thread, jint depth, jint slot, jdouble* value_ptr) {
aoqi@0 1876 // rm object is created to clean up the javaVFrame created in
aoqi@0 1877 // doit_prologue(), but after doit() is finished with it.
aoqi@0 1878 ResourceMark rm;
aoqi@0 1879
aoqi@0 1880 VM_GetOrSetLocal op(java_thread, depth, slot, T_DOUBLE);
aoqi@0 1881 VMThread::execute(&op);
aoqi@0 1882 *value_ptr = op.value().d;
aoqi@0 1883 return op.result();
aoqi@0 1884 } /* end GetLocalDouble */
aoqi@0 1885
aoqi@0 1886
aoqi@0 1887 // Threads_lock NOT held, java_thread not protected by lock
aoqi@0 1888 // java_thread - pre-checked
aoqi@0 1889 // java_thread - unchecked
aoqi@0 1890 // depth - pre-checked as non-negative
aoqi@0 1891 jvmtiError
aoqi@0 1892 JvmtiEnv::SetLocalObject(JavaThread* java_thread, jint depth, jint slot, jobject value) {
aoqi@0 1893 // rm object is created to clean up the javaVFrame created in
aoqi@0 1894 // doit_prologue(), but after doit() is finished with it.
aoqi@0 1895 ResourceMark rm;
aoqi@0 1896 jvalue val;
aoqi@0 1897 val.l = value;
aoqi@0 1898 VM_GetOrSetLocal op(java_thread, depth, slot, T_OBJECT, val);
aoqi@0 1899 VMThread::execute(&op);
aoqi@0 1900 return op.result();
aoqi@0 1901 } /* end SetLocalObject */
aoqi@0 1902
aoqi@0 1903
aoqi@0 1904 // Threads_lock NOT held, java_thread not protected by lock
aoqi@0 1905 // java_thread - pre-checked
aoqi@0 1906 // java_thread - unchecked
aoqi@0 1907 // depth - pre-checked as non-negative
aoqi@0 1908 jvmtiError
aoqi@0 1909 JvmtiEnv::SetLocalInt(JavaThread* java_thread, jint depth, jint slot, jint value) {
aoqi@0 1910 // rm object is created to clean up the javaVFrame created in
aoqi@0 1911 // doit_prologue(), but after doit() is finished with it.
aoqi@0 1912 ResourceMark rm;
aoqi@0 1913 jvalue val;
aoqi@0 1914 val.i = value;
aoqi@0 1915 VM_GetOrSetLocal op(java_thread, depth, slot, T_INT, val);
aoqi@0 1916 VMThread::execute(&op);
aoqi@0 1917 return op.result();
aoqi@0 1918 } /* end SetLocalInt */
aoqi@0 1919
aoqi@0 1920
aoqi@0 1921 // Threads_lock NOT held, java_thread not protected by lock
aoqi@0 1922 // java_thread - pre-checked
aoqi@0 1923 // java_thread - unchecked
aoqi@0 1924 // depth - pre-checked as non-negative
aoqi@0 1925 jvmtiError
aoqi@0 1926 JvmtiEnv::SetLocalLong(JavaThread* java_thread, jint depth, jint slot, jlong value) {
aoqi@0 1927 // rm object is created to clean up the javaVFrame created in
aoqi@0 1928 // doit_prologue(), but after doit() is finished with it.
aoqi@0 1929 ResourceMark rm;
aoqi@0 1930 jvalue val;
aoqi@0 1931 val.j = value;
aoqi@0 1932 VM_GetOrSetLocal op(java_thread, depth, slot, T_LONG, val);
aoqi@0 1933 VMThread::execute(&op);
aoqi@0 1934 return op.result();
aoqi@0 1935 } /* end SetLocalLong */
aoqi@0 1936
aoqi@0 1937
aoqi@0 1938 // Threads_lock NOT held, java_thread not protected by lock
aoqi@0 1939 // java_thread - pre-checked
aoqi@0 1940 // java_thread - unchecked
aoqi@0 1941 // depth - pre-checked as non-negative
aoqi@0 1942 jvmtiError
aoqi@0 1943 JvmtiEnv::SetLocalFloat(JavaThread* java_thread, jint depth, jint slot, jfloat value) {
aoqi@0 1944 // rm object is created to clean up the javaVFrame created in
aoqi@0 1945 // doit_prologue(), but after doit() is finished with it.
aoqi@0 1946 ResourceMark rm;
aoqi@0 1947 jvalue val;
aoqi@0 1948 val.f = value;
aoqi@0 1949 VM_GetOrSetLocal op(java_thread, depth, slot, T_FLOAT, val);
aoqi@0 1950 VMThread::execute(&op);
aoqi@0 1951 return op.result();
aoqi@0 1952 } /* end SetLocalFloat */
aoqi@0 1953
aoqi@0 1954
aoqi@0 1955 // Threads_lock NOT held, java_thread not protected by lock
aoqi@0 1956 // java_thread - pre-checked
aoqi@0 1957 // java_thread - unchecked
aoqi@0 1958 // depth - pre-checked as non-negative
aoqi@0 1959 jvmtiError
aoqi@0 1960 JvmtiEnv::SetLocalDouble(JavaThread* java_thread, jint depth, jint slot, jdouble value) {
aoqi@0 1961 // rm object is created to clean up the javaVFrame created in
aoqi@0 1962 // doit_prologue(), but after doit() is finished with it.
aoqi@0 1963 ResourceMark rm;
aoqi@0 1964 jvalue val;
aoqi@0 1965 val.d = value;
aoqi@0 1966 VM_GetOrSetLocal op(java_thread, depth, slot, T_DOUBLE, val);
aoqi@0 1967 VMThread::execute(&op);
aoqi@0 1968 return op.result();
aoqi@0 1969 } /* end SetLocalDouble */
aoqi@0 1970
aoqi@0 1971
aoqi@0 1972 //
aoqi@0 1973 // Breakpoint functions
aoqi@0 1974 //
aoqi@0 1975
aoqi@0 1976 // method_oop - pre-checked for validity, but may be NULL meaning obsolete method
aoqi@0 1977 jvmtiError
aoqi@0 1978 JvmtiEnv::SetBreakpoint(Method* method_oop, jlocation location) {
aoqi@0 1979 NULL_CHECK(method_oop, JVMTI_ERROR_INVALID_METHODID);
aoqi@0 1980 if (location < 0) { // simple invalid location check first
aoqi@0 1981 return JVMTI_ERROR_INVALID_LOCATION;
aoqi@0 1982 }
aoqi@0 1983 // verify that the breakpoint is not past the end of the method
aoqi@0 1984 if (location >= (jlocation) method_oop->code_size()) {
aoqi@0 1985 return JVMTI_ERROR_INVALID_LOCATION;
aoqi@0 1986 }
aoqi@0 1987
aoqi@0 1988 ResourceMark rm;
aoqi@0 1989 JvmtiBreakpoint bp(method_oop, location);
aoqi@0 1990 JvmtiBreakpoints& jvmti_breakpoints = JvmtiCurrentBreakpoints::get_jvmti_breakpoints();
aoqi@0 1991 if (jvmti_breakpoints.set(bp) == JVMTI_ERROR_DUPLICATE)
aoqi@0 1992 return JVMTI_ERROR_DUPLICATE;
aoqi@0 1993
aoqi@0 1994 if (TraceJVMTICalls) {
aoqi@0 1995 jvmti_breakpoints.print();
aoqi@0 1996 }
aoqi@0 1997
aoqi@0 1998 return JVMTI_ERROR_NONE;
aoqi@0 1999 } /* end SetBreakpoint */
aoqi@0 2000
aoqi@0 2001
aoqi@0 2002 // method_oop - pre-checked for validity, but may be NULL meaning obsolete method
aoqi@0 2003 jvmtiError
aoqi@0 2004 JvmtiEnv::ClearBreakpoint(Method* method_oop, jlocation location) {
aoqi@0 2005 NULL_CHECK(method_oop, JVMTI_ERROR_INVALID_METHODID);
aoqi@0 2006
aoqi@0 2007 if (location < 0) { // simple invalid location check first
aoqi@0 2008 return JVMTI_ERROR_INVALID_LOCATION;
aoqi@0 2009 }
aoqi@0 2010
aoqi@0 2011 // verify that the breakpoint is not past the end of the method
aoqi@0 2012 if (location >= (jlocation) method_oop->code_size()) {
aoqi@0 2013 return JVMTI_ERROR_INVALID_LOCATION;
aoqi@0 2014 }
aoqi@0 2015
aoqi@0 2016 JvmtiBreakpoint bp(method_oop, location);
aoqi@0 2017
aoqi@0 2018 JvmtiBreakpoints& jvmti_breakpoints = JvmtiCurrentBreakpoints::get_jvmti_breakpoints();
aoqi@0 2019 if (jvmti_breakpoints.clear(bp) == JVMTI_ERROR_NOT_FOUND)
aoqi@0 2020 return JVMTI_ERROR_NOT_FOUND;
aoqi@0 2021
aoqi@0 2022 if (TraceJVMTICalls) {
aoqi@0 2023 jvmti_breakpoints.print();
aoqi@0 2024 }
aoqi@0 2025
aoqi@0 2026 return JVMTI_ERROR_NONE;
aoqi@0 2027 } /* end ClearBreakpoint */
aoqi@0 2028
aoqi@0 2029
aoqi@0 2030 //
aoqi@0 2031 // Watched Field functions
aoqi@0 2032 //
aoqi@0 2033
aoqi@0 2034 jvmtiError
aoqi@0 2035 JvmtiEnv::SetFieldAccessWatch(fieldDescriptor* fdesc_ptr) {
aoqi@0 2036 // make sure we haven't set this watch before
aoqi@0 2037 if (fdesc_ptr->is_field_access_watched()) return JVMTI_ERROR_DUPLICATE;
aoqi@0 2038 fdesc_ptr->set_is_field_access_watched(true);
aoqi@0 2039
aoqi@0 2040 JvmtiEventController::change_field_watch(JVMTI_EVENT_FIELD_ACCESS, true);
aoqi@0 2041
aoqi@0 2042 return JVMTI_ERROR_NONE;
aoqi@0 2043 } /* end SetFieldAccessWatch */
aoqi@0 2044
aoqi@0 2045
aoqi@0 2046 jvmtiError
aoqi@0 2047 JvmtiEnv::ClearFieldAccessWatch(fieldDescriptor* fdesc_ptr) {
aoqi@0 2048 // make sure we have a watch to clear
aoqi@0 2049 if (!fdesc_ptr->is_field_access_watched()) return JVMTI_ERROR_NOT_FOUND;
aoqi@0 2050 fdesc_ptr->set_is_field_access_watched(false);
aoqi@0 2051
aoqi@0 2052 JvmtiEventController::change_field_watch(JVMTI_EVENT_FIELD_ACCESS, false);
aoqi@0 2053
aoqi@0 2054 return JVMTI_ERROR_NONE;
aoqi@0 2055 } /* end ClearFieldAccessWatch */
aoqi@0 2056
aoqi@0 2057
aoqi@0 2058 jvmtiError
aoqi@0 2059 JvmtiEnv::SetFieldModificationWatch(fieldDescriptor* fdesc_ptr) {
aoqi@0 2060 // make sure we haven't set this watch before
aoqi@0 2061 if (fdesc_ptr->is_field_modification_watched()) return JVMTI_ERROR_DUPLICATE;
aoqi@0 2062 fdesc_ptr->set_is_field_modification_watched(true);
aoqi@0 2063
aoqi@0 2064 JvmtiEventController::change_field_watch(JVMTI_EVENT_FIELD_MODIFICATION, true);
aoqi@0 2065
aoqi@0 2066 return JVMTI_ERROR_NONE;
aoqi@0 2067 } /* end SetFieldModificationWatch */
aoqi@0 2068
aoqi@0 2069
aoqi@0 2070 jvmtiError
aoqi@0 2071 JvmtiEnv::ClearFieldModificationWatch(fieldDescriptor* fdesc_ptr) {
aoqi@0 2072 // make sure we have a watch to clear
aoqi@0 2073 if (!fdesc_ptr->is_field_modification_watched()) return JVMTI_ERROR_NOT_FOUND;
aoqi@0 2074 fdesc_ptr->set_is_field_modification_watched(false);
aoqi@0 2075
aoqi@0 2076 JvmtiEventController::change_field_watch(JVMTI_EVENT_FIELD_MODIFICATION, false);
aoqi@0 2077
aoqi@0 2078 return JVMTI_ERROR_NONE;
aoqi@0 2079 } /* end ClearFieldModificationWatch */
aoqi@0 2080
aoqi@0 2081 //
aoqi@0 2082 // Class functions
aoqi@0 2083 //
aoqi@0 2084
aoqi@0 2085
aoqi@0 2086 // k_mirror - may be primitive, this must be checked
aoqi@0 2087 // signature_ptr - NULL is a valid value, must be checked
aoqi@0 2088 // generic_ptr - NULL is a valid value, must be checked
aoqi@0 2089 jvmtiError
aoqi@0 2090 JvmtiEnv::GetClassSignature(oop k_mirror, char** signature_ptr, char** generic_ptr) {
aoqi@0 2091 ResourceMark rm;
aoqi@0 2092 bool isPrimitive = java_lang_Class::is_primitive(k_mirror);
aoqi@0 2093 Klass* k = NULL;
aoqi@0 2094 if (!isPrimitive) {
aoqi@0 2095 k = java_lang_Class::as_Klass(k_mirror);
aoqi@0 2096 NULL_CHECK(k, JVMTI_ERROR_INVALID_CLASS);
aoqi@0 2097 }
aoqi@0 2098 if (signature_ptr != NULL) {
aoqi@0 2099 char* result = NULL;
aoqi@0 2100 if (isPrimitive) {
aoqi@0 2101 char tchar = type2char(java_lang_Class::primitive_type(k_mirror));
aoqi@0 2102 result = (char*) jvmtiMalloc(2);
aoqi@0 2103 result[0] = tchar;
aoqi@0 2104 result[1] = '\0';
aoqi@0 2105 } else {
aoqi@0 2106 const char* class_sig = k->signature_name();
aoqi@0 2107 result = (char *) jvmtiMalloc(strlen(class_sig)+1);
aoqi@0 2108 strcpy(result, class_sig);
aoqi@0 2109 }
aoqi@0 2110 *signature_ptr = result;
aoqi@0 2111 }
aoqi@0 2112 if (generic_ptr != NULL) {
aoqi@0 2113 *generic_ptr = NULL;
aoqi@0 2114 if (!isPrimitive && k->oop_is_instance()) {
aoqi@0 2115 Symbol* soo = InstanceKlass::cast(k)->generic_signature();
aoqi@0 2116 if (soo != NULL) {
aoqi@0 2117 const char *gen_sig = soo->as_C_string();
aoqi@0 2118 if (gen_sig != NULL) {
aoqi@0 2119 char* gen_result;
aoqi@0 2120 jvmtiError err = allocate(strlen(gen_sig) + 1,
aoqi@0 2121 (unsigned char **)&gen_result);
aoqi@0 2122 if (err != JVMTI_ERROR_NONE) {
aoqi@0 2123 return err;
aoqi@0 2124 }
aoqi@0 2125 strcpy(gen_result, gen_sig);
aoqi@0 2126 *generic_ptr = gen_result;
aoqi@0 2127 }
aoqi@0 2128 }
aoqi@0 2129 }
aoqi@0 2130 }
aoqi@0 2131 return JVMTI_ERROR_NONE;
aoqi@0 2132 } /* end GetClassSignature */
aoqi@0 2133
aoqi@0 2134
aoqi@0 2135 // k_mirror - may be primitive, this must be checked
aoqi@0 2136 // status_ptr - pre-checked for NULL
aoqi@0 2137 jvmtiError
aoqi@0 2138 JvmtiEnv::GetClassStatus(oop k_mirror, jint* status_ptr) {
aoqi@0 2139 jint result = 0;
aoqi@0 2140 if (java_lang_Class::is_primitive(k_mirror)) {
aoqi@0 2141 result |= JVMTI_CLASS_STATUS_PRIMITIVE;
aoqi@0 2142 } else {
aoqi@0 2143 Klass* k = java_lang_Class::as_Klass(k_mirror);
aoqi@0 2144 NULL_CHECK(k, JVMTI_ERROR_INVALID_CLASS);
aoqi@0 2145 result = k->jvmti_class_status();
aoqi@0 2146 }
aoqi@0 2147 *status_ptr = result;
aoqi@0 2148
aoqi@0 2149 return JVMTI_ERROR_NONE;
aoqi@0 2150 } /* end GetClassStatus */
aoqi@0 2151
aoqi@0 2152
aoqi@0 2153 // k_mirror - may be primitive, this must be checked
aoqi@0 2154 // source_name_ptr - pre-checked for NULL
aoqi@0 2155 jvmtiError
aoqi@0 2156 JvmtiEnv::GetSourceFileName(oop k_mirror, char** source_name_ptr) {
aoqi@0 2157 if (java_lang_Class::is_primitive(k_mirror)) {
aoqi@0 2158 return JVMTI_ERROR_ABSENT_INFORMATION;
aoqi@0 2159 }
aoqi@0 2160 Klass* k_klass = java_lang_Class::as_Klass(k_mirror);
aoqi@0 2161 NULL_CHECK(k_klass, JVMTI_ERROR_INVALID_CLASS);
aoqi@0 2162
aoqi@0 2163 if (!k_klass->oop_is_instance()) {
aoqi@0 2164 return JVMTI_ERROR_ABSENT_INFORMATION;
aoqi@0 2165 }
aoqi@0 2166
aoqi@0 2167 Symbol* sfnOop = InstanceKlass::cast(k_klass)->source_file_name();
aoqi@0 2168 NULL_CHECK(sfnOop, JVMTI_ERROR_ABSENT_INFORMATION);
aoqi@0 2169 {
aoqi@0 2170 JavaThread* current_thread = JavaThread::current();
aoqi@0 2171 ResourceMark rm(current_thread);
aoqi@0 2172 const char* sfncp = (const char*) sfnOop->as_C_string();
aoqi@0 2173 *source_name_ptr = (char *) jvmtiMalloc(strlen(sfncp)+1);
aoqi@0 2174 strcpy(*source_name_ptr, sfncp);
aoqi@0 2175 }
aoqi@0 2176
aoqi@0 2177 return JVMTI_ERROR_NONE;
aoqi@0 2178 } /* end GetSourceFileName */
aoqi@0 2179
aoqi@0 2180
aoqi@0 2181 // k_mirror - may be primitive, this must be checked
aoqi@0 2182 // modifiers_ptr - pre-checked for NULL
aoqi@0 2183 jvmtiError
aoqi@0 2184 JvmtiEnv::GetClassModifiers(oop k_mirror, jint* modifiers_ptr) {
aoqi@0 2185 JavaThread* current_thread = JavaThread::current();
aoqi@0 2186 jint result = 0;
aoqi@0 2187 if (!java_lang_Class::is_primitive(k_mirror)) {
aoqi@0 2188 Klass* k = java_lang_Class::as_Klass(k_mirror);
aoqi@0 2189 NULL_CHECK(k, JVMTI_ERROR_INVALID_CLASS);
aoqi@0 2190 result = k->compute_modifier_flags(current_thread);
aoqi@0 2191 JavaThread* THREAD = current_thread; // pass to macros
aoqi@0 2192 if (HAS_PENDING_EXCEPTION) {
aoqi@0 2193 CLEAR_PENDING_EXCEPTION;
aoqi@0 2194 return JVMTI_ERROR_INTERNAL;
aoqi@0 2195 };
aoqi@0 2196
aoqi@0 2197 // Reset the deleted ACC_SUPER bit ( deleted in compute_modifier_flags()).
aoqi@0 2198 if(k->is_super()) {
aoqi@0 2199 result |= JVM_ACC_SUPER;
aoqi@0 2200 }
aoqi@0 2201 } else {
aoqi@0 2202 result = (JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC);
aoqi@0 2203 }
aoqi@0 2204 *modifiers_ptr = result;
aoqi@0 2205
aoqi@0 2206 return JVMTI_ERROR_NONE;
aoqi@0 2207 } /* end GetClassModifiers */
aoqi@0 2208
aoqi@0 2209
aoqi@0 2210 // k_mirror - may be primitive, this must be checked
aoqi@0 2211 // method_count_ptr - pre-checked for NULL
aoqi@0 2212 // methods_ptr - pre-checked for NULL
aoqi@0 2213 jvmtiError
aoqi@0 2214 JvmtiEnv::GetClassMethods(oop k_mirror, jint* method_count_ptr, jmethodID** methods_ptr) {
aoqi@0 2215 JavaThread* current_thread = JavaThread::current();
aoqi@0 2216 HandleMark hm(current_thread);
aoqi@0 2217
aoqi@0 2218 if (java_lang_Class::is_primitive(k_mirror)) {
aoqi@0 2219 *method_count_ptr = 0;
aoqi@0 2220 *methods_ptr = (jmethodID*) jvmtiMalloc(0 * sizeof(jmethodID));
aoqi@0 2221 return JVMTI_ERROR_NONE;
aoqi@0 2222 }
aoqi@0 2223 Klass* k = java_lang_Class::as_Klass(k_mirror);
aoqi@0 2224 NULL_CHECK(k, JVMTI_ERROR_INVALID_CLASS);
aoqi@0 2225
aoqi@0 2226 // Return CLASS_NOT_PREPARED error as per JVMTI spec.
aoqi@0 2227 if (!(k->jvmti_class_status() & (JVMTI_CLASS_STATUS_PREPARED|JVMTI_CLASS_STATUS_ARRAY) )) {
aoqi@0 2228 return JVMTI_ERROR_CLASS_NOT_PREPARED;
aoqi@0 2229 }
aoqi@0 2230
aoqi@0 2231 if (!k->oop_is_instance()) {
aoqi@0 2232 *method_count_ptr = 0;
aoqi@0 2233 *methods_ptr = (jmethodID*) jvmtiMalloc(0 * sizeof(jmethodID));
aoqi@0 2234 return JVMTI_ERROR_NONE;
aoqi@0 2235 }
aoqi@0 2236 instanceKlassHandle instanceK_h(current_thread, k);
aoqi@0 2237 // Allocate the result and fill it in
aoqi@0 2238 int result_length = instanceK_h->methods()->length();
aoqi@0 2239 jmethodID* result_list = (jmethodID*)jvmtiMalloc(result_length * sizeof(jmethodID));
aoqi@0 2240 int index;
aoqi@0 2241 if (JvmtiExport::can_maintain_original_method_order()) {
aoqi@0 2242 // Use the original method ordering indices stored in the class, so we can emit
aoqi@0 2243 // jmethodIDs in the order they appeared in the class file
aoqi@0 2244 for (index = 0; index < result_length; index++) {
aoqi@0 2245 Method* m = instanceK_h->methods()->at(index);
aoqi@0 2246 int original_index = instanceK_h->method_ordering()->at(index);
aoqi@0 2247 assert(original_index >= 0 && original_index < result_length, "invalid original method index");
aoqi@0 2248 jmethodID id = m->jmethod_id();
aoqi@0 2249 result_list[original_index] = id;
aoqi@0 2250 }
aoqi@0 2251 } else {
aoqi@0 2252 // otherwise just copy in any order
aoqi@0 2253 for (index = 0; index < result_length; index++) {
aoqi@0 2254 Method* m = instanceK_h->methods()->at(index);
aoqi@0 2255 jmethodID id = m->jmethod_id();
aoqi@0 2256 result_list[index] = id;
aoqi@0 2257 }
aoqi@0 2258 }
aoqi@0 2259 // Fill in return value.
aoqi@0 2260 *method_count_ptr = result_length;
aoqi@0 2261 *methods_ptr = result_list;
aoqi@0 2262
aoqi@0 2263 return JVMTI_ERROR_NONE;
aoqi@0 2264 } /* end GetClassMethods */
aoqi@0 2265
aoqi@0 2266
aoqi@0 2267 // k_mirror - may be primitive, this must be checked
aoqi@0 2268 // field_count_ptr - pre-checked for NULL
aoqi@0 2269 // fields_ptr - pre-checked for NULL
aoqi@0 2270 jvmtiError
aoqi@0 2271 JvmtiEnv::GetClassFields(oop k_mirror, jint* field_count_ptr, jfieldID** fields_ptr) {
aoqi@0 2272 if (java_lang_Class::is_primitive(k_mirror)) {
aoqi@0 2273 *field_count_ptr = 0;
aoqi@0 2274 *fields_ptr = (jfieldID*) jvmtiMalloc(0 * sizeof(jfieldID));
aoqi@0 2275 return JVMTI_ERROR_NONE;
aoqi@0 2276 }
aoqi@0 2277 JavaThread* current_thread = JavaThread::current();
aoqi@0 2278 HandleMark hm(current_thread);
aoqi@0 2279 Klass* k = java_lang_Class::as_Klass(k_mirror);
aoqi@0 2280 NULL_CHECK(k, JVMTI_ERROR_INVALID_CLASS);
aoqi@0 2281
aoqi@0 2282 // Return CLASS_NOT_PREPARED error as per JVMTI spec.
aoqi@0 2283 if (!(k->jvmti_class_status() & (JVMTI_CLASS_STATUS_PREPARED|JVMTI_CLASS_STATUS_ARRAY) )) {
aoqi@0 2284 return JVMTI_ERROR_CLASS_NOT_PREPARED;
aoqi@0 2285 }
aoqi@0 2286
aoqi@0 2287 if (!k->oop_is_instance()) {
aoqi@0 2288 *field_count_ptr = 0;
aoqi@0 2289 *fields_ptr = (jfieldID*) jvmtiMalloc(0 * sizeof(jfieldID));
aoqi@0 2290 return JVMTI_ERROR_NONE;
aoqi@0 2291 }
aoqi@0 2292
aoqi@0 2293
aoqi@0 2294 instanceKlassHandle instanceK_h(current_thread, k);
aoqi@0 2295
aoqi@0 2296 int result_count = 0;
aoqi@0 2297 // First, count the fields.
aoqi@0 2298 FilteredFieldStream flds(instanceK_h, true, true);
aoqi@0 2299 result_count = flds.field_count();
aoqi@0 2300
aoqi@0 2301 // Allocate the result and fill it in
aoqi@0 2302 jfieldID* result_list = (jfieldID*) jvmtiMalloc(result_count * sizeof(jfieldID));
aoqi@0 2303 // The JVMTI spec requires fields in the order they occur in the class file,
aoqi@0 2304 // this is the reverse order of what FieldStream hands out.
aoqi@0 2305 int id_index = (result_count - 1);
aoqi@0 2306
aoqi@0 2307 for (FilteredFieldStream src_st(instanceK_h, true, true); !src_st.eos(); src_st.next()) {
aoqi@0 2308 result_list[id_index--] = jfieldIDWorkaround::to_jfieldID(
aoqi@0 2309 instanceK_h, src_st.offset(),
aoqi@0 2310 src_st.access_flags().is_static());
aoqi@0 2311 }
aoqi@0 2312 assert(id_index == -1, "just checking");
aoqi@0 2313 // Fill in the results
aoqi@0 2314 *field_count_ptr = result_count;
aoqi@0 2315 *fields_ptr = result_list;
aoqi@0 2316
aoqi@0 2317 return JVMTI_ERROR_NONE;
aoqi@0 2318 } /* end GetClassFields */
aoqi@0 2319
aoqi@0 2320
aoqi@0 2321 // k_mirror - may be primitive, this must be checked
aoqi@0 2322 // interface_count_ptr - pre-checked for NULL
aoqi@0 2323 // interfaces_ptr - pre-checked for NULL
aoqi@0 2324 jvmtiError
aoqi@0 2325 JvmtiEnv::GetImplementedInterfaces(oop k_mirror, jint* interface_count_ptr, jclass** interfaces_ptr) {
aoqi@0 2326 {
aoqi@0 2327 if (java_lang_Class::is_primitive(k_mirror)) {
aoqi@0 2328 *interface_count_ptr = 0;
aoqi@0 2329 *interfaces_ptr = (jclass*) jvmtiMalloc(0 * sizeof(jclass));
aoqi@0 2330 return JVMTI_ERROR_NONE;
aoqi@0 2331 }
aoqi@0 2332 JavaThread* current_thread = JavaThread::current();
aoqi@0 2333 HandleMark hm(current_thread);
aoqi@0 2334 Klass* k = java_lang_Class::as_Klass(k_mirror);
aoqi@0 2335 NULL_CHECK(k, JVMTI_ERROR_INVALID_CLASS);
aoqi@0 2336
aoqi@0 2337 // Return CLASS_NOT_PREPARED error as per JVMTI spec.
aoqi@0 2338 if (!(k->jvmti_class_status() & (JVMTI_CLASS_STATUS_PREPARED|JVMTI_CLASS_STATUS_ARRAY) ))
aoqi@0 2339 return JVMTI_ERROR_CLASS_NOT_PREPARED;
aoqi@0 2340
aoqi@0 2341 if (!k->oop_is_instance()) {
aoqi@0 2342 *interface_count_ptr = 0;
aoqi@0 2343 *interfaces_ptr = (jclass*) jvmtiMalloc(0 * sizeof(jclass));
aoqi@0 2344 return JVMTI_ERROR_NONE;
aoqi@0 2345 }
aoqi@0 2346
aoqi@0 2347 Array<Klass*>* interface_list = InstanceKlass::cast(k)->local_interfaces();
aoqi@0 2348 const int result_length = (interface_list == NULL ? 0 : interface_list->length());
aoqi@0 2349 jclass* result_list = (jclass*) jvmtiMalloc(result_length * sizeof(jclass));
aoqi@0 2350 for (int i_index = 0; i_index < result_length; i_index += 1) {
aoqi@0 2351 Klass* klass_at = interface_list->at(i_index);
aoqi@0 2352 assert(klass_at->is_klass(), "interfaces must be Klass*s");
aoqi@0 2353 assert(klass_at->is_interface(), "interfaces must be interfaces");
aoqi@0 2354 oop mirror_at = klass_at->java_mirror();
aoqi@0 2355 Handle handle_at = Handle(current_thread, mirror_at);
aoqi@0 2356 result_list[i_index] = (jclass) jni_reference(handle_at);
aoqi@0 2357 }
aoqi@0 2358 *interface_count_ptr = result_length;
aoqi@0 2359 *interfaces_ptr = result_list;
aoqi@0 2360 }
aoqi@0 2361
aoqi@0 2362 return JVMTI_ERROR_NONE;
aoqi@0 2363 } /* end GetImplementedInterfaces */
aoqi@0 2364
aoqi@0 2365
aoqi@0 2366 // k_mirror - may be primitive, this must be checked
aoqi@0 2367 // minor_version_ptr - pre-checked for NULL
aoqi@0 2368 // major_version_ptr - pre-checked for NULL
aoqi@0 2369 jvmtiError
aoqi@0 2370 JvmtiEnv::GetClassVersionNumbers(oop k_mirror, jint* minor_version_ptr, jint* major_version_ptr) {
aoqi@0 2371 if (java_lang_Class::is_primitive(k_mirror)) {
aoqi@0 2372 return JVMTI_ERROR_ABSENT_INFORMATION;
aoqi@0 2373 }
aoqi@0 2374 Klass* k_oop = java_lang_Class::as_Klass(k_mirror);
aoqi@0 2375 Thread *thread = Thread::current();
aoqi@0 2376 HandleMark hm(thread);
aoqi@0 2377 KlassHandle klass(thread, k_oop);
aoqi@0 2378
aoqi@0 2379 jint status = klass->jvmti_class_status();
aoqi@0 2380 if (status & (JVMTI_CLASS_STATUS_ERROR)) {
aoqi@0 2381 return JVMTI_ERROR_INVALID_CLASS;
aoqi@0 2382 }
aoqi@0 2383 if (status & (JVMTI_CLASS_STATUS_ARRAY)) {
aoqi@0 2384 return JVMTI_ERROR_ABSENT_INFORMATION;
aoqi@0 2385 }
aoqi@0 2386
aoqi@0 2387 instanceKlassHandle ik(thread, k_oop);
aoqi@0 2388 *minor_version_ptr = ik->minor_version();
aoqi@0 2389 *major_version_ptr = ik->major_version();
aoqi@0 2390
aoqi@0 2391 return JVMTI_ERROR_NONE;
aoqi@0 2392 } /* end GetClassVersionNumbers */
aoqi@0 2393
aoqi@0 2394
aoqi@0 2395 // k_mirror - may be primitive, this must be checked
aoqi@0 2396 // constant_pool_count_ptr - pre-checked for NULL
aoqi@0 2397 // constant_pool_byte_count_ptr - pre-checked for NULL
aoqi@0 2398 // constant_pool_bytes_ptr - pre-checked for NULL
aoqi@0 2399 jvmtiError
aoqi@0 2400 JvmtiEnv::GetConstantPool(oop k_mirror, jint* constant_pool_count_ptr, jint* constant_pool_byte_count_ptr, unsigned char** constant_pool_bytes_ptr) {
aoqi@0 2401 if (java_lang_Class::is_primitive(k_mirror)) {
aoqi@0 2402 return JVMTI_ERROR_ABSENT_INFORMATION;
aoqi@0 2403 }
aoqi@0 2404
aoqi@0 2405 Klass* k_oop = java_lang_Class::as_Klass(k_mirror);
aoqi@0 2406 Thread *thread = Thread::current();
aoqi@0 2407 HandleMark hm(thread);
aoqi@0 2408 ResourceMark rm(thread);
aoqi@0 2409 KlassHandle klass(thread, k_oop);
aoqi@0 2410
aoqi@0 2411 jint status = klass->jvmti_class_status();
aoqi@0 2412 if (status & (JVMTI_CLASS_STATUS_ERROR)) {
aoqi@0 2413 return JVMTI_ERROR_INVALID_CLASS;
aoqi@0 2414 }
aoqi@0 2415 if (status & (JVMTI_CLASS_STATUS_ARRAY)) {
aoqi@0 2416 return JVMTI_ERROR_ABSENT_INFORMATION;
aoqi@0 2417 }
aoqi@0 2418
aoqi@0 2419 instanceKlassHandle ikh(thread, k_oop);
aoqi@0 2420 constantPoolHandle constants(thread, ikh->constants());
aoqi@0 2421 MonitorLockerEx ml(constants->lock()); // lock constant pool while we query it
aoqi@0 2422
aoqi@0 2423 JvmtiConstantPoolReconstituter reconstituter(ikh);
aoqi@0 2424 if (reconstituter.get_error() != JVMTI_ERROR_NONE) {
aoqi@0 2425 return reconstituter.get_error();
aoqi@0 2426 }
aoqi@0 2427
aoqi@0 2428 unsigned char *cpool_bytes;
aoqi@0 2429 int cpool_size = reconstituter.cpool_size();
aoqi@0 2430 if (reconstituter.get_error() != JVMTI_ERROR_NONE) {
aoqi@0 2431 return reconstituter.get_error();
aoqi@0 2432 }
aoqi@0 2433 jvmtiError res = allocate(cpool_size, &cpool_bytes);
aoqi@0 2434 if (res != JVMTI_ERROR_NONE) {
aoqi@0 2435 return res;
aoqi@0 2436 }
aoqi@0 2437 reconstituter.copy_cpool_bytes(cpool_bytes);
aoqi@0 2438 if (reconstituter.get_error() != JVMTI_ERROR_NONE) {
aoqi@0 2439 return reconstituter.get_error();
aoqi@0 2440 }
aoqi@0 2441
aoqi@0 2442 *constant_pool_count_ptr = constants->length();
aoqi@0 2443 *constant_pool_byte_count_ptr = cpool_size;
aoqi@0 2444 *constant_pool_bytes_ptr = cpool_bytes;
aoqi@0 2445
aoqi@0 2446 return JVMTI_ERROR_NONE;
aoqi@0 2447 } /* end GetConstantPool */
aoqi@0 2448
aoqi@0 2449
aoqi@0 2450 // k_mirror - may be primitive, this must be checked
aoqi@0 2451 // is_interface_ptr - pre-checked for NULL
aoqi@0 2452 jvmtiError
aoqi@0 2453 JvmtiEnv::IsInterface(oop k_mirror, jboolean* is_interface_ptr) {
aoqi@0 2454 {
aoqi@0 2455 bool result = false;
aoqi@0 2456 if (!java_lang_Class::is_primitive(k_mirror)) {
aoqi@0 2457 Klass* k = java_lang_Class::as_Klass(k_mirror);
aoqi@0 2458 if (k != NULL && k->is_interface()) {
aoqi@0 2459 result = true;
aoqi@0 2460 }
aoqi@0 2461 }
aoqi@0 2462 *is_interface_ptr = result;
aoqi@0 2463 }
aoqi@0 2464
aoqi@0 2465 return JVMTI_ERROR_NONE;
aoqi@0 2466 } /* end IsInterface */
aoqi@0 2467
aoqi@0 2468
aoqi@0 2469 // k_mirror - may be primitive, this must be checked
aoqi@0 2470 // is_array_class_ptr - pre-checked for NULL
aoqi@0 2471 jvmtiError
aoqi@0 2472 JvmtiEnv::IsArrayClass(oop k_mirror, jboolean* is_array_class_ptr) {
aoqi@0 2473 {
aoqi@0 2474 bool result = false;
aoqi@0 2475 if (!java_lang_Class::is_primitive(k_mirror)) {
aoqi@0 2476 Klass* k = java_lang_Class::as_Klass(k_mirror);
aoqi@0 2477 if (k != NULL && k->oop_is_array()) {
aoqi@0 2478 result = true;
aoqi@0 2479 }
aoqi@0 2480 }
aoqi@0 2481 *is_array_class_ptr = result;
aoqi@0 2482 }
aoqi@0 2483
aoqi@0 2484 return JVMTI_ERROR_NONE;
aoqi@0 2485 } /* end IsArrayClass */
aoqi@0 2486
aoqi@0 2487
aoqi@0 2488 // k_mirror - may be primitive, this must be checked
aoqi@0 2489 // classloader_ptr - pre-checked for NULL
aoqi@0 2490 jvmtiError
aoqi@0 2491 JvmtiEnv::GetClassLoader(oop k_mirror, jobject* classloader_ptr) {
aoqi@0 2492 {
aoqi@0 2493 if (java_lang_Class::is_primitive(k_mirror)) {
aoqi@0 2494 *classloader_ptr = (jclass) jni_reference(Handle());
aoqi@0 2495 return JVMTI_ERROR_NONE;
aoqi@0 2496 }
aoqi@0 2497 JavaThread* current_thread = JavaThread::current();
aoqi@0 2498 HandleMark hm(current_thread);
aoqi@0 2499 Klass* k = java_lang_Class::as_Klass(k_mirror);
aoqi@0 2500 NULL_CHECK(k, JVMTI_ERROR_INVALID_CLASS);
aoqi@0 2501
aoqi@0 2502 oop result_oop = k->class_loader();
aoqi@0 2503 if (result_oop == NULL) {
aoqi@0 2504 *classloader_ptr = (jclass) jni_reference(Handle());
aoqi@0 2505 return JVMTI_ERROR_NONE;
aoqi@0 2506 }
aoqi@0 2507 Handle result_handle = Handle(current_thread, result_oop);
aoqi@0 2508 jclass result_jnihandle = (jclass) jni_reference(result_handle);
aoqi@0 2509 *classloader_ptr = result_jnihandle;
aoqi@0 2510 }
aoqi@0 2511 return JVMTI_ERROR_NONE;
aoqi@0 2512 } /* end GetClassLoader */
aoqi@0 2513
aoqi@0 2514
aoqi@0 2515 // k_mirror - may be primitive, this must be checked
aoqi@0 2516 // source_debug_extension_ptr - pre-checked for NULL
aoqi@0 2517 jvmtiError
aoqi@0 2518 JvmtiEnv::GetSourceDebugExtension(oop k_mirror, char** source_debug_extension_ptr) {
aoqi@0 2519 {
aoqi@0 2520 if (java_lang_Class::is_primitive(k_mirror)) {
aoqi@0 2521 return JVMTI_ERROR_ABSENT_INFORMATION;
aoqi@0 2522 }
aoqi@0 2523 Klass* k = java_lang_Class::as_Klass(k_mirror);
aoqi@0 2524 NULL_CHECK(k, JVMTI_ERROR_INVALID_CLASS);
aoqi@0 2525 if (!k->oop_is_instance()) {
aoqi@0 2526 return JVMTI_ERROR_ABSENT_INFORMATION;
aoqi@0 2527 }
aoqi@0 2528 char* sde = InstanceKlass::cast(k)->source_debug_extension();
aoqi@0 2529 NULL_CHECK(sde, JVMTI_ERROR_ABSENT_INFORMATION);
aoqi@0 2530
aoqi@0 2531 {
aoqi@0 2532 *source_debug_extension_ptr = (char *) jvmtiMalloc(strlen(sde)+1);
aoqi@0 2533 strcpy(*source_debug_extension_ptr, sde);
aoqi@0 2534 }
aoqi@0 2535 }
aoqi@0 2536
aoqi@0 2537 return JVMTI_ERROR_NONE;
aoqi@0 2538 } /* end GetSourceDebugExtension */
aoqi@0 2539
aoqi@0 2540 //
aoqi@0 2541 // Object functions
aoqi@0 2542 //
aoqi@0 2543
aoqi@0 2544 // hash_code_ptr - pre-checked for NULL
aoqi@0 2545 jvmtiError
aoqi@0 2546 JvmtiEnv::GetObjectHashCode(jobject object, jint* hash_code_ptr) {
aoqi@0 2547 oop mirror = JNIHandles::resolve_external_guard(object);
aoqi@0 2548 NULL_CHECK(mirror, JVMTI_ERROR_INVALID_OBJECT);
aoqi@0 2549 NULL_CHECK(hash_code_ptr, JVMTI_ERROR_NULL_POINTER);
aoqi@0 2550
aoqi@0 2551 {
aoqi@0 2552 jint result = (jint) mirror->identity_hash();
aoqi@0 2553 *hash_code_ptr = result;
aoqi@0 2554 }
aoqi@0 2555 return JVMTI_ERROR_NONE;
aoqi@0 2556 } /* end GetObjectHashCode */
aoqi@0 2557
aoqi@0 2558
aoqi@0 2559 // info_ptr - pre-checked for NULL
aoqi@0 2560 jvmtiError
aoqi@0 2561 JvmtiEnv::GetObjectMonitorUsage(jobject object, jvmtiMonitorUsage* info_ptr) {
aoqi@0 2562 JavaThread* calling_thread = JavaThread::current();
aoqi@0 2563 jvmtiError err = get_object_monitor_usage(calling_thread, object, info_ptr);
aoqi@0 2564 if (err == JVMTI_ERROR_THREAD_NOT_SUSPENDED) {
aoqi@0 2565 // Some of the critical threads were not suspended. go to a safepoint and try again
aoqi@0 2566 VM_GetObjectMonitorUsage op(this, calling_thread, object, info_ptr);
aoqi@0 2567 VMThread::execute(&op);
aoqi@0 2568 err = op.result();
aoqi@0 2569 }
aoqi@0 2570 return err;
aoqi@0 2571 } /* end GetObjectMonitorUsage */
aoqi@0 2572
aoqi@0 2573
aoqi@0 2574 //
aoqi@0 2575 // Field functions
aoqi@0 2576 //
aoqi@0 2577
aoqi@0 2578 // name_ptr - NULL is a valid value, must be checked
aoqi@0 2579 // signature_ptr - NULL is a valid value, must be checked
aoqi@0 2580 // generic_ptr - NULL is a valid value, must be checked
aoqi@0 2581 jvmtiError
aoqi@0 2582 JvmtiEnv::GetFieldName(fieldDescriptor* fdesc_ptr, char** name_ptr, char** signature_ptr, char** generic_ptr) {
aoqi@0 2583 JavaThread* current_thread = JavaThread::current();
aoqi@0 2584 ResourceMark rm(current_thread);
aoqi@0 2585 if (name_ptr == NULL) {
aoqi@0 2586 // just don't return the name
aoqi@0 2587 } else {
aoqi@0 2588 const char* fieldName = fdesc_ptr->name()->as_C_string();
aoqi@0 2589 *name_ptr = (char*) jvmtiMalloc(strlen(fieldName) + 1);
aoqi@0 2590 if (*name_ptr == NULL)
aoqi@0 2591 return JVMTI_ERROR_OUT_OF_MEMORY;
aoqi@0 2592 strcpy(*name_ptr, fieldName);
aoqi@0 2593 }
aoqi@0 2594 if (signature_ptr== NULL) {
aoqi@0 2595 // just don't return the signature
aoqi@0 2596 } else {
aoqi@0 2597 const char* fieldSignature = fdesc_ptr->signature()->as_C_string();
aoqi@0 2598 *signature_ptr = (char*) jvmtiMalloc(strlen(fieldSignature) + 1);
aoqi@0 2599 if (*signature_ptr == NULL)
aoqi@0 2600 return JVMTI_ERROR_OUT_OF_MEMORY;
aoqi@0 2601 strcpy(*signature_ptr, fieldSignature);
aoqi@0 2602 }
aoqi@0 2603 if (generic_ptr != NULL) {
aoqi@0 2604 *generic_ptr = NULL;
aoqi@0 2605 Symbol* soop = fdesc_ptr->generic_signature();
aoqi@0 2606 if (soop != NULL) {
aoqi@0 2607 const char* gen_sig = soop->as_C_string();
aoqi@0 2608 if (gen_sig != NULL) {
aoqi@0 2609 jvmtiError err = allocate(strlen(gen_sig) + 1, (unsigned char **)generic_ptr);
aoqi@0 2610 if (err != JVMTI_ERROR_NONE) {
aoqi@0 2611 return err;
aoqi@0 2612 }
aoqi@0 2613 strcpy(*generic_ptr, gen_sig);
aoqi@0 2614 }
aoqi@0 2615 }
aoqi@0 2616 }
aoqi@0 2617 return JVMTI_ERROR_NONE;
aoqi@0 2618 } /* end GetFieldName */
aoqi@0 2619
aoqi@0 2620
aoqi@0 2621 // declaring_class_ptr - pre-checked for NULL
aoqi@0 2622 jvmtiError
aoqi@0 2623 JvmtiEnv::GetFieldDeclaringClass(fieldDescriptor* fdesc_ptr, jclass* declaring_class_ptr) {
aoqi@0 2624
aoqi@0 2625 *declaring_class_ptr = get_jni_class_non_null(fdesc_ptr->field_holder());
aoqi@0 2626 return JVMTI_ERROR_NONE;
aoqi@0 2627 } /* end GetFieldDeclaringClass */
aoqi@0 2628
aoqi@0 2629
aoqi@0 2630 // modifiers_ptr - pre-checked for NULL
aoqi@0 2631 jvmtiError
aoqi@0 2632 JvmtiEnv::GetFieldModifiers(fieldDescriptor* fdesc_ptr, jint* modifiers_ptr) {
aoqi@0 2633
aoqi@0 2634 AccessFlags resultFlags = fdesc_ptr->access_flags();
aoqi@0 2635 jint result = resultFlags.as_int();
aoqi@0 2636 *modifiers_ptr = result;
aoqi@0 2637
aoqi@0 2638 return JVMTI_ERROR_NONE;
aoqi@0 2639 } /* end GetFieldModifiers */
aoqi@0 2640
aoqi@0 2641
aoqi@0 2642 // is_synthetic_ptr - pre-checked for NULL
aoqi@0 2643 jvmtiError
aoqi@0 2644 JvmtiEnv::IsFieldSynthetic(fieldDescriptor* fdesc_ptr, jboolean* is_synthetic_ptr) {
aoqi@0 2645 *is_synthetic_ptr = fdesc_ptr->is_synthetic();
aoqi@0 2646 return JVMTI_ERROR_NONE;
aoqi@0 2647 } /* end IsFieldSynthetic */
aoqi@0 2648
aoqi@0 2649
aoqi@0 2650 //
aoqi@0 2651 // Method functions
aoqi@0 2652 //
aoqi@0 2653
aoqi@0 2654 // method_oop - pre-checked for validity, but may be NULL meaning obsolete method
aoqi@0 2655 // name_ptr - NULL is a valid value, must be checked
aoqi@0 2656 // signature_ptr - NULL is a valid value, must be checked
aoqi@0 2657 // generic_ptr - NULL is a valid value, must be checked
aoqi@0 2658 jvmtiError
aoqi@0 2659 JvmtiEnv::GetMethodName(Method* method_oop, char** name_ptr, char** signature_ptr, char** generic_ptr) {
aoqi@0 2660 NULL_CHECK(method_oop, JVMTI_ERROR_INVALID_METHODID);
aoqi@0 2661 JavaThread* current_thread = JavaThread::current();
aoqi@0 2662
aoqi@0 2663 ResourceMark rm(current_thread); // get the utf8 name and signature
aoqi@0 2664 if (name_ptr == NULL) {
aoqi@0 2665 // just don't return the name
aoqi@0 2666 } else {
aoqi@0 2667 const char* utf8_name = (const char *) method_oop->name()->as_utf8();
aoqi@0 2668 *name_ptr = (char *) jvmtiMalloc(strlen(utf8_name)+1);
aoqi@0 2669 strcpy(*name_ptr, utf8_name);
aoqi@0 2670 }
aoqi@0 2671 if (signature_ptr == NULL) {
aoqi@0 2672 // just don't return the signature
aoqi@0 2673 } else {
aoqi@0 2674 const char* utf8_signature = (const char *) method_oop->signature()->as_utf8();
aoqi@0 2675 *signature_ptr = (char *) jvmtiMalloc(strlen(utf8_signature) + 1);
aoqi@0 2676 strcpy(*signature_ptr, utf8_signature);
aoqi@0 2677 }
aoqi@0 2678
aoqi@0 2679 if (generic_ptr != NULL) {
aoqi@0 2680 *generic_ptr = NULL;
aoqi@0 2681 Symbol* soop = method_oop->generic_signature();
aoqi@0 2682 if (soop != NULL) {
aoqi@0 2683 const char* gen_sig = soop->as_C_string();
aoqi@0 2684 if (gen_sig != NULL) {
aoqi@0 2685 jvmtiError err = allocate(strlen(gen_sig) + 1, (unsigned char **)generic_ptr);
aoqi@0 2686 if (err != JVMTI_ERROR_NONE) {
aoqi@0 2687 return err;
aoqi@0 2688 }
aoqi@0 2689 strcpy(*generic_ptr, gen_sig);
aoqi@0 2690 }
aoqi@0 2691 }
aoqi@0 2692 }
aoqi@0 2693 return JVMTI_ERROR_NONE;
aoqi@0 2694 } /* end GetMethodName */
aoqi@0 2695
aoqi@0 2696
aoqi@0 2697 // method_oop - pre-checked for validity, but may be NULL meaning obsolete method
aoqi@0 2698 // declaring_class_ptr - pre-checked for NULL
aoqi@0 2699 jvmtiError
aoqi@0 2700 JvmtiEnv::GetMethodDeclaringClass(Method* method_oop, jclass* declaring_class_ptr) {
aoqi@0 2701 NULL_CHECK(method_oop, JVMTI_ERROR_INVALID_METHODID);
aoqi@0 2702 (*declaring_class_ptr) = get_jni_class_non_null(method_oop->method_holder());
aoqi@0 2703 return JVMTI_ERROR_NONE;
aoqi@0 2704 } /* end GetMethodDeclaringClass */
aoqi@0 2705
aoqi@0 2706
aoqi@0 2707 // method_oop - pre-checked for validity, but may be NULL meaning obsolete method
aoqi@0 2708 // modifiers_ptr - pre-checked for NULL
aoqi@0 2709 jvmtiError
aoqi@0 2710 JvmtiEnv::GetMethodModifiers(Method* method_oop, jint* modifiers_ptr) {
aoqi@0 2711 NULL_CHECK(method_oop, JVMTI_ERROR_INVALID_METHODID);
aoqi@0 2712 (*modifiers_ptr) = method_oop->access_flags().as_int() & JVM_RECOGNIZED_METHOD_MODIFIERS;
aoqi@0 2713 return JVMTI_ERROR_NONE;
aoqi@0 2714 } /* end GetMethodModifiers */
aoqi@0 2715
aoqi@0 2716
aoqi@0 2717 // method_oop - pre-checked for validity, but may be NULL meaning obsolete method
aoqi@0 2718 // max_ptr - pre-checked for NULL
aoqi@0 2719 jvmtiError
aoqi@0 2720 JvmtiEnv::GetMaxLocals(Method* method_oop, jint* max_ptr) {
aoqi@0 2721 NULL_CHECK(method_oop, JVMTI_ERROR_INVALID_METHODID);
aoqi@0 2722 // get max stack
aoqi@0 2723 (*max_ptr) = method_oop->max_locals();
aoqi@0 2724 return JVMTI_ERROR_NONE;
aoqi@0 2725 } /* end GetMaxLocals */
aoqi@0 2726
aoqi@0 2727
aoqi@0 2728 // method_oop - pre-checked for validity, but may be NULL meaning obsolete method
aoqi@0 2729 // size_ptr - pre-checked for NULL
aoqi@0 2730 jvmtiError
aoqi@0 2731 JvmtiEnv::GetArgumentsSize(Method* method_oop, jint* size_ptr) {
aoqi@0 2732 NULL_CHECK(method_oop, JVMTI_ERROR_INVALID_METHODID);
aoqi@0 2733 // get size of arguments
aoqi@0 2734
aoqi@0 2735 (*size_ptr) = method_oop->size_of_parameters();
aoqi@0 2736 return JVMTI_ERROR_NONE;
aoqi@0 2737 } /* end GetArgumentsSize */
aoqi@0 2738
aoqi@0 2739
aoqi@0 2740 // method_oop - pre-checked for validity, but may be NULL meaning obsolete method
aoqi@0 2741 // entry_count_ptr - pre-checked for NULL
aoqi@0 2742 // table_ptr - pre-checked for NULL
aoqi@0 2743 jvmtiError
aoqi@0 2744 JvmtiEnv::GetLineNumberTable(Method* method_oop, jint* entry_count_ptr, jvmtiLineNumberEntry** table_ptr) {
aoqi@0 2745 NULL_CHECK(method_oop, JVMTI_ERROR_INVALID_METHODID);
aoqi@0 2746 if (!method_oop->has_linenumber_table()) {
aoqi@0 2747 return (JVMTI_ERROR_ABSENT_INFORMATION);
aoqi@0 2748 }
aoqi@0 2749
aoqi@0 2750 // The line number table is compressed so we don't know how big it is until decompressed.
aoqi@0 2751 // Decompression is really fast so we just do it twice.
aoqi@0 2752
aoqi@0 2753 // Compute size of table
aoqi@0 2754 jint num_entries = 0;
aoqi@0 2755 CompressedLineNumberReadStream stream(method_oop->compressed_linenumber_table());
aoqi@0 2756 while (stream.read_pair()) {
aoqi@0 2757 num_entries++;
aoqi@0 2758 }
aoqi@0 2759 jvmtiLineNumberEntry *jvmti_table =
aoqi@0 2760 (jvmtiLineNumberEntry *)jvmtiMalloc(num_entries * (sizeof(jvmtiLineNumberEntry)));
aoqi@0 2761
aoqi@0 2762 // Fill jvmti table
aoqi@0 2763 if (num_entries > 0) {
aoqi@0 2764 int index = 0;
aoqi@0 2765 CompressedLineNumberReadStream stream(method_oop->compressed_linenumber_table());
aoqi@0 2766 while (stream.read_pair()) {
aoqi@0 2767 jvmti_table[index].start_location = (jlocation) stream.bci();
aoqi@0 2768 jvmti_table[index].line_number = (jint) stream.line();
aoqi@0 2769 index++;
aoqi@0 2770 }
aoqi@0 2771 assert(index == num_entries, "sanity check");
aoqi@0 2772 }
aoqi@0 2773
aoqi@0 2774 // Set up results
aoqi@0 2775 (*entry_count_ptr) = num_entries;
aoqi@0 2776 (*table_ptr) = jvmti_table;
aoqi@0 2777
aoqi@0 2778 return JVMTI_ERROR_NONE;
aoqi@0 2779 } /* end GetLineNumberTable */
aoqi@0 2780
aoqi@0 2781
aoqi@0 2782 // method_oop - pre-checked for validity, but may be NULL meaning obsolete method
aoqi@0 2783 // start_location_ptr - pre-checked for NULL
aoqi@0 2784 // end_location_ptr - pre-checked for NULL
aoqi@0 2785 jvmtiError
aoqi@0 2786 JvmtiEnv::GetMethodLocation(Method* method_oop, jlocation* start_location_ptr, jlocation* end_location_ptr) {
aoqi@0 2787
aoqi@0 2788 NULL_CHECK(method_oop, JVMTI_ERROR_INVALID_METHODID);
aoqi@0 2789 // get start and end location
aoqi@0 2790 (*end_location_ptr) = (jlocation) (method_oop->code_size() - 1);
aoqi@0 2791 if (method_oop->code_size() == 0) {
aoqi@0 2792 // there is no code so there is no start location
aoqi@0 2793 (*start_location_ptr) = (jlocation)(-1);
aoqi@0 2794 } else {
aoqi@0 2795 (*start_location_ptr) = (jlocation)(0);
aoqi@0 2796 }
aoqi@0 2797
aoqi@0 2798 return JVMTI_ERROR_NONE;
aoqi@0 2799 } /* end GetMethodLocation */
aoqi@0 2800
aoqi@0 2801
aoqi@0 2802 // method_oop - pre-checked for validity, but may be NULL meaning obsolete method
aoqi@0 2803 // entry_count_ptr - pre-checked for NULL
aoqi@0 2804 // table_ptr - pre-checked for NULL
aoqi@0 2805 jvmtiError
aoqi@0 2806 JvmtiEnv::GetLocalVariableTable(Method* method_oop, jint* entry_count_ptr, jvmtiLocalVariableEntry** table_ptr) {
aoqi@0 2807
aoqi@0 2808 NULL_CHECK(method_oop, JVMTI_ERROR_INVALID_METHODID);
aoqi@0 2809 JavaThread* current_thread = JavaThread::current();
aoqi@0 2810
aoqi@0 2811 // does the klass have any local variable information?
aoqi@0 2812 InstanceKlass* ik = method_oop->method_holder();
aoqi@0 2813 if (!ik->access_flags().has_localvariable_table()) {
aoqi@0 2814 return (JVMTI_ERROR_ABSENT_INFORMATION);
aoqi@0 2815 }
aoqi@0 2816
aoqi@0 2817 ConstantPool* constants = method_oop->constants();
aoqi@0 2818 NULL_CHECK(constants, JVMTI_ERROR_ABSENT_INFORMATION);
aoqi@0 2819
aoqi@0 2820 // in the vm localvariable table representation, 6 consecutive elements in the table
aoqi@0 2821 // represent a 6-tuple of shorts
aoqi@0 2822 // [start_pc, length, name_index, descriptor_index, signature_index, index]
aoqi@0 2823 jint num_entries = method_oop->localvariable_table_length();
aoqi@0 2824 jvmtiLocalVariableEntry *jvmti_table = (jvmtiLocalVariableEntry *)
aoqi@0 2825 jvmtiMalloc(num_entries * (sizeof(jvmtiLocalVariableEntry)));
aoqi@0 2826
aoqi@0 2827 if (num_entries > 0) {
aoqi@0 2828 LocalVariableTableElement* table = method_oop->localvariable_table_start();
aoqi@0 2829 for (int i = 0; i < num_entries; i++) {
aoqi@0 2830 // get the 5 tuple information from the vm table
aoqi@0 2831 jlocation start_location = (jlocation) table[i].start_bci;
aoqi@0 2832 jint length = (jint) table[i].length;
aoqi@0 2833 int name_index = (int) table[i].name_cp_index;
aoqi@0 2834 int signature_index = (int) table[i].descriptor_cp_index;
aoqi@0 2835 int generic_signature_index = (int) table[i].signature_cp_index;
aoqi@0 2836 jint slot = (jint) table[i].slot;
aoqi@0 2837
aoqi@0 2838 // get utf8 name and signature
aoqi@0 2839 char *name_buf = NULL;
aoqi@0 2840 char *sig_buf = NULL;
aoqi@0 2841 char *gen_sig_buf = NULL;
aoqi@0 2842 {
aoqi@0 2843 ResourceMark rm(current_thread);
aoqi@0 2844
aoqi@0 2845 const char *utf8_name = (const char *) constants->symbol_at(name_index)->as_utf8();
aoqi@0 2846 name_buf = (char *) jvmtiMalloc(strlen(utf8_name)+1);
aoqi@0 2847 strcpy(name_buf, utf8_name);
aoqi@0 2848
aoqi@0 2849 const char *utf8_signature = (const char *) constants->symbol_at(signature_index)->as_utf8();
aoqi@0 2850 sig_buf = (char *) jvmtiMalloc(strlen(utf8_signature)+1);
aoqi@0 2851 strcpy(sig_buf, utf8_signature);
aoqi@0 2852
aoqi@0 2853 if (generic_signature_index > 0) {
aoqi@0 2854 const char *utf8_gen_sign = (const char *)
aoqi@0 2855 constants->symbol_at(generic_signature_index)->as_utf8();
aoqi@0 2856 gen_sig_buf = (char *) jvmtiMalloc(strlen(utf8_gen_sign)+1);
aoqi@0 2857 strcpy(gen_sig_buf, utf8_gen_sign);
aoqi@0 2858 }
aoqi@0 2859 }
aoqi@0 2860
aoqi@0 2861 // fill in the jvmti local variable table
aoqi@0 2862 jvmti_table[i].start_location = start_location;
aoqi@0 2863 jvmti_table[i].length = length;
aoqi@0 2864 jvmti_table[i].name = name_buf;
aoqi@0 2865 jvmti_table[i].signature = sig_buf;
aoqi@0 2866 jvmti_table[i].generic_signature = gen_sig_buf;
aoqi@0 2867 jvmti_table[i].slot = slot;
aoqi@0 2868 }
aoqi@0 2869 }
aoqi@0 2870
aoqi@0 2871 // set results
aoqi@0 2872 (*entry_count_ptr) = num_entries;
aoqi@0 2873 (*table_ptr) = jvmti_table;
aoqi@0 2874
aoqi@0 2875 return JVMTI_ERROR_NONE;
aoqi@0 2876 } /* end GetLocalVariableTable */
aoqi@0 2877
aoqi@0 2878
aoqi@0 2879 // method_oop - pre-checked for validity, but may be NULL meaning obsolete method
aoqi@0 2880 // bytecode_count_ptr - pre-checked for NULL
aoqi@0 2881 // bytecodes_ptr - pre-checked for NULL
aoqi@0 2882 jvmtiError
aoqi@0 2883 JvmtiEnv::GetBytecodes(Method* method_oop, jint* bytecode_count_ptr, unsigned char** bytecodes_ptr) {
aoqi@0 2884 NULL_CHECK(method_oop, JVMTI_ERROR_INVALID_METHODID);
aoqi@0 2885
aoqi@0 2886 HandleMark hm;
aoqi@0 2887 methodHandle method(method_oop);
aoqi@0 2888 jint size = (jint)method->code_size();
aoqi@0 2889 jvmtiError err = allocate(size, bytecodes_ptr);
aoqi@0 2890 if (err != JVMTI_ERROR_NONE) {
aoqi@0 2891 return err;
aoqi@0 2892 }
aoqi@0 2893
aoqi@0 2894 (*bytecode_count_ptr) = size;
aoqi@0 2895 // get byte codes
aoqi@0 2896 JvmtiClassFileReconstituter::copy_bytecodes(method, *bytecodes_ptr);
aoqi@0 2897
aoqi@0 2898 return JVMTI_ERROR_NONE;
aoqi@0 2899 } /* end GetBytecodes */
aoqi@0 2900
aoqi@0 2901
aoqi@0 2902 // method_oop - pre-checked for validity, but may be NULL meaning obsolete method
aoqi@0 2903 // is_native_ptr - pre-checked for NULL
aoqi@0 2904 jvmtiError
aoqi@0 2905 JvmtiEnv::IsMethodNative(Method* method_oop, jboolean* is_native_ptr) {
aoqi@0 2906 NULL_CHECK(method_oop, JVMTI_ERROR_INVALID_METHODID);
aoqi@0 2907 (*is_native_ptr) = method_oop->is_native();
aoqi@0 2908 return JVMTI_ERROR_NONE;
aoqi@0 2909 } /* end IsMethodNative */
aoqi@0 2910
aoqi@0 2911
aoqi@0 2912 // method_oop - pre-checked for validity, but may be NULL meaning obsolete method
aoqi@0 2913 // is_synthetic_ptr - pre-checked for NULL
aoqi@0 2914 jvmtiError
aoqi@0 2915 JvmtiEnv::IsMethodSynthetic(Method* method_oop, jboolean* is_synthetic_ptr) {
aoqi@0 2916 NULL_CHECK(method_oop, JVMTI_ERROR_INVALID_METHODID);
aoqi@0 2917 (*is_synthetic_ptr) = method_oop->is_synthetic();
aoqi@0 2918 return JVMTI_ERROR_NONE;
aoqi@0 2919 } /* end IsMethodSynthetic */
aoqi@0 2920
aoqi@0 2921
aoqi@0 2922 // method_oop - pre-checked for validity, but may be NULL meaning obsolete method
aoqi@0 2923 // is_obsolete_ptr - pre-checked for NULL
aoqi@0 2924 jvmtiError
aoqi@0 2925 JvmtiEnv::IsMethodObsolete(Method* method_oop, jboolean* is_obsolete_ptr) {
aoqi@0 2926 if (use_version_1_0_semantics() &&
aoqi@0 2927 get_capabilities()->can_redefine_classes == 0) {
aoqi@0 2928 // This JvmtiEnv requested version 1.0 semantics and this function
aoqi@0 2929 // requires the can_redefine_classes capability in version 1.0 so
aoqi@0 2930 // we need to return an error here.
aoqi@0 2931 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
aoqi@0 2932 }
aoqi@0 2933
aoqi@0 2934 if (method_oop == NULL || method_oop->is_obsolete()) {
aoqi@0 2935 *is_obsolete_ptr = true;
aoqi@0 2936 } else {
aoqi@0 2937 *is_obsolete_ptr = false;
aoqi@0 2938 }
aoqi@0 2939 return JVMTI_ERROR_NONE;
aoqi@0 2940 } /* end IsMethodObsolete */
aoqi@0 2941
aoqi@0 2942 //
aoqi@0 2943 // Raw Monitor functions
aoqi@0 2944 //
aoqi@0 2945
aoqi@0 2946 // name - pre-checked for NULL
aoqi@0 2947 // monitor_ptr - pre-checked for NULL
aoqi@0 2948 jvmtiError
aoqi@0 2949 JvmtiEnv::CreateRawMonitor(const char* name, jrawMonitorID* monitor_ptr) {
aoqi@0 2950 JvmtiRawMonitor* rmonitor = new JvmtiRawMonitor(name);
aoqi@0 2951 NULL_CHECK(rmonitor, JVMTI_ERROR_OUT_OF_MEMORY);
aoqi@0 2952
aoqi@0 2953 *monitor_ptr = (jrawMonitorID)rmonitor;
aoqi@0 2954
aoqi@0 2955 return JVMTI_ERROR_NONE;
aoqi@0 2956 } /* end CreateRawMonitor */
aoqi@0 2957
aoqi@0 2958
aoqi@0 2959 // rmonitor - pre-checked for validity
aoqi@0 2960 jvmtiError
aoqi@0 2961 JvmtiEnv::DestroyRawMonitor(JvmtiRawMonitor * rmonitor) {
aoqi@0 2962 if (Threads::number_of_threads() == 0) {
aoqi@0 2963 // Remove this monitor from pending raw monitors list
aoqi@0 2964 // if it has entered in onload or start phase.
aoqi@0 2965 JvmtiPendingMonitors::destroy(rmonitor);
aoqi@0 2966 } else {
aoqi@0 2967 Thread* thread = Thread::current();
aoqi@0 2968 if (rmonitor->is_entered(thread)) {
aoqi@0 2969 // The caller owns this monitor which we are about to destroy.
aoqi@0 2970 // We exit the underlying synchronization object so that the
aoqi@0 2971 // "delete monitor" call below can work without an assertion
aoqi@0 2972 // failure on systems that don't like destroying synchronization
aoqi@0 2973 // objects that are locked.
aoqi@0 2974 int r;
aoqi@0 2975 intptr_t recursion = rmonitor->recursions();
fmatte@9511 2976 for (intptr_t i = 0; i <= recursion; i++) {
aoqi@0 2977 r = rmonitor->raw_exit(thread);
aoqi@0 2978 assert(r == ObjectMonitor::OM_OK, "raw_exit should have worked");
aoqi@0 2979 if (r != ObjectMonitor::OM_OK) { // robustness
aoqi@0 2980 return JVMTI_ERROR_INTERNAL;
aoqi@0 2981 }
aoqi@0 2982 }
aoqi@0 2983 }
aoqi@0 2984 if (rmonitor->owner() != NULL) {
aoqi@0 2985 // The caller is trying to destroy a monitor that is locked by
aoqi@0 2986 // someone else. While this is not forbidden by the JVMTI
aoqi@0 2987 // spec, it will cause an assertion failure on systems that don't
aoqi@0 2988 // like destroying synchronization objects that are locked.
aoqi@0 2989 // We indicate a problem with the error return (and leak the
aoqi@0 2990 // monitor's memory).
aoqi@0 2991 return JVMTI_ERROR_NOT_MONITOR_OWNER;
aoqi@0 2992 }
aoqi@0 2993 }
aoqi@0 2994
aoqi@0 2995 delete rmonitor;
aoqi@0 2996
aoqi@0 2997 return JVMTI_ERROR_NONE;
aoqi@0 2998 } /* end DestroyRawMonitor */
aoqi@0 2999
aoqi@0 3000
aoqi@0 3001 // rmonitor - pre-checked for validity
aoqi@0 3002 jvmtiError
aoqi@0 3003 JvmtiEnv::RawMonitorEnter(JvmtiRawMonitor * rmonitor) {
aoqi@0 3004 if (Threads::number_of_threads() == 0) {
aoqi@0 3005 // No JavaThreads exist so ObjectMonitor enter cannot be
aoqi@0 3006 // used, add this raw monitor to the pending list.
aoqi@0 3007 // The pending monitors will be actually entered when
aoqi@0 3008 // the VM is setup.
aoqi@0 3009 // See transition_pending_raw_monitors in create_vm()
aoqi@0 3010 // in thread.cpp.
aoqi@0 3011 JvmtiPendingMonitors::enter(rmonitor);
aoqi@0 3012 } else {
csahu@8316 3013 int r = 0;
aoqi@0 3014 Thread* thread = Thread::current();
aoqi@0 3015
aoqi@0 3016 if (thread->is_Java_thread()) {
aoqi@0 3017 JavaThread* current_thread = (JavaThread*)thread;
aoqi@0 3018
aoqi@0 3019 #ifdef PROPER_TRANSITIONS
aoqi@0 3020 // Not really unknown but ThreadInVMfromNative does more than we want
aoqi@0 3021 ThreadInVMfromUnknown __tiv;
aoqi@0 3022 {
aoqi@0 3023 ThreadBlockInVM __tbivm(current_thread);
aoqi@0 3024 r = rmonitor->raw_enter(current_thread);
aoqi@0 3025 }
aoqi@0 3026 #else
aoqi@0 3027 /* Transition to thread_blocked without entering vm state */
aoqi@0 3028 /* This is really evil. Normally you can't undo _thread_blocked */
aoqi@0 3029 /* transitions like this because it would cause us to miss a */
aoqi@0 3030 /* safepoint but since the thread was already in _thread_in_native */
aoqi@0 3031 /* the thread is not leaving a safepoint safe state and it will */
aoqi@0 3032 /* block when it tries to return from native. We can't safepoint */
aoqi@0 3033 /* block in here because we could deadlock the vmthread. Blech. */
aoqi@0 3034
aoqi@0 3035 JavaThreadState state = current_thread->thread_state();
aoqi@0 3036 assert(state == _thread_in_native, "Must be _thread_in_native");
aoqi@0 3037 // frame should already be walkable since we are in native
aoqi@0 3038 assert(!current_thread->has_last_Java_frame() ||
aoqi@0 3039 current_thread->frame_anchor()->walkable(), "Must be walkable");
aoqi@0 3040 current_thread->set_thread_state(_thread_blocked);
aoqi@0 3041
aoqi@0 3042 r = rmonitor->raw_enter(current_thread);
aoqi@0 3043 // restore state, still at a safepoint safe state
aoqi@0 3044 current_thread->set_thread_state(state);
aoqi@0 3045
aoqi@0 3046 #endif /* PROPER_TRANSITIONS */
aoqi@0 3047 assert(r == ObjectMonitor::OM_OK, "raw_enter should have worked");
aoqi@0 3048 } else {
aoqi@0 3049 if (thread->is_VM_thread() || thread->is_ConcurrentGC_thread()) {
aoqi@0 3050 r = rmonitor->raw_enter(thread);
aoqi@0 3051 } else {
aoqi@0 3052 ShouldNotReachHere();
aoqi@0 3053 }
aoqi@0 3054 }
aoqi@0 3055
aoqi@0 3056 if (r != ObjectMonitor::OM_OK) { // robustness
aoqi@0 3057 return JVMTI_ERROR_INTERNAL;
aoqi@0 3058 }
aoqi@0 3059 }
aoqi@0 3060 return JVMTI_ERROR_NONE;
aoqi@0 3061 } /* end RawMonitorEnter */
aoqi@0 3062
aoqi@0 3063
aoqi@0 3064 // rmonitor - pre-checked for validity
aoqi@0 3065 jvmtiError
aoqi@0 3066 JvmtiEnv::RawMonitorExit(JvmtiRawMonitor * rmonitor) {
aoqi@0 3067 jvmtiError err = JVMTI_ERROR_NONE;
aoqi@0 3068
aoqi@0 3069 if (Threads::number_of_threads() == 0) {
aoqi@0 3070 // No JavaThreads exist so just remove this monitor from the pending list.
aoqi@0 3071 // Bool value from exit is false if rmonitor is not in the list.
aoqi@0 3072 if (!JvmtiPendingMonitors::exit(rmonitor)) {
aoqi@0 3073 err = JVMTI_ERROR_NOT_MONITOR_OWNER;
aoqi@0 3074 }
aoqi@0 3075 } else {
csahu@8316 3076 int r = 0;
aoqi@0 3077 Thread* thread = Thread::current();
aoqi@0 3078
aoqi@0 3079 if (thread->is_Java_thread()) {
aoqi@0 3080 JavaThread* current_thread = (JavaThread*)thread;
aoqi@0 3081 #ifdef PROPER_TRANSITIONS
aoqi@0 3082 // Not really unknown but ThreadInVMfromNative does more than we want
aoqi@0 3083 ThreadInVMfromUnknown __tiv;
aoqi@0 3084 #endif /* PROPER_TRANSITIONS */
aoqi@0 3085 r = rmonitor->raw_exit(current_thread);
aoqi@0 3086 } else {
aoqi@0 3087 if (thread->is_VM_thread() || thread->is_ConcurrentGC_thread()) {
aoqi@0 3088 r = rmonitor->raw_exit(thread);
aoqi@0 3089 } else {
aoqi@0 3090 ShouldNotReachHere();
aoqi@0 3091 }
aoqi@0 3092 }
aoqi@0 3093
aoqi@0 3094 if (r == ObjectMonitor::OM_ILLEGAL_MONITOR_STATE) {
aoqi@0 3095 err = JVMTI_ERROR_NOT_MONITOR_OWNER;
aoqi@0 3096 } else {
aoqi@0 3097 assert(r == ObjectMonitor::OM_OK, "raw_exit should have worked");
aoqi@0 3098 if (r != ObjectMonitor::OM_OK) { // robustness
aoqi@0 3099 err = JVMTI_ERROR_INTERNAL;
aoqi@0 3100 }
aoqi@0 3101 }
aoqi@0 3102 }
aoqi@0 3103 return err;
aoqi@0 3104 } /* end RawMonitorExit */
aoqi@0 3105
aoqi@0 3106
aoqi@0 3107 // rmonitor - pre-checked for validity
aoqi@0 3108 jvmtiError
aoqi@0 3109 JvmtiEnv::RawMonitorWait(JvmtiRawMonitor * rmonitor, jlong millis) {
csahu@8316 3110 int r = 0;
aoqi@0 3111 Thread* thread = Thread::current();
aoqi@0 3112
aoqi@0 3113 if (thread->is_Java_thread()) {
aoqi@0 3114 JavaThread* current_thread = (JavaThread*)thread;
aoqi@0 3115 #ifdef PROPER_TRANSITIONS
aoqi@0 3116 // Not really unknown but ThreadInVMfromNative does more than we want
aoqi@0 3117 ThreadInVMfromUnknown __tiv;
aoqi@0 3118 {
aoqi@0 3119 ThreadBlockInVM __tbivm(current_thread);
aoqi@0 3120 r = rmonitor->raw_wait(millis, true, current_thread);
aoqi@0 3121 }
aoqi@0 3122 #else
aoqi@0 3123 /* Transition to thread_blocked without entering vm state */
aoqi@0 3124 /* This is really evil. Normally you can't undo _thread_blocked */
aoqi@0 3125 /* transitions like this because it would cause us to miss a */
aoqi@0 3126 /* safepoint but since the thread was already in _thread_in_native */
aoqi@0 3127 /* the thread is not leaving a safepoint safe state and it will */
aoqi@0 3128 /* block when it tries to return from native. We can't safepoint */
aoqi@0 3129 /* block in here because we could deadlock the vmthread. Blech. */
aoqi@0 3130
aoqi@0 3131 JavaThreadState state = current_thread->thread_state();
aoqi@0 3132 assert(state == _thread_in_native, "Must be _thread_in_native");
aoqi@0 3133 // frame should already be walkable since we are in native
aoqi@0 3134 assert(!current_thread->has_last_Java_frame() ||
aoqi@0 3135 current_thread->frame_anchor()->walkable(), "Must be walkable");
aoqi@0 3136 current_thread->set_thread_state(_thread_blocked);
aoqi@0 3137
aoqi@0 3138 r = rmonitor->raw_wait(millis, true, current_thread);
aoqi@0 3139 // restore state, still at a safepoint safe state
aoqi@0 3140 current_thread->set_thread_state(state);
aoqi@0 3141
aoqi@0 3142 #endif /* PROPER_TRANSITIONS */
aoqi@0 3143 } else {
aoqi@0 3144 if (thread->is_VM_thread() || thread->is_ConcurrentGC_thread()) {
aoqi@0 3145 r = rmonitor->raw_wait(millis, true, thread);
aoqi@0 3146 } else {
aoqi@0 3147 ShouldNotReachHere();
aoqi@0 3148 }
aoqi@0 3149 }
aoqi@0 3150
aoqi@0 3151 switch (r) {
aoqi@0 3152 case ObjectMonitor::OM_INTERRUPTED:
aoqi@0 3153 return JVMTI_ERROR_INTERRUPT;
aoqi@0 3154 case ObjectMonitor::OM_ILLEGAL_MONITOR_STATE:
aoqi@0 3155 return JVMTI_ERROR_NOT_MONITOR_OWNER;
aoqi@0 3156 }
aoqi@0 3157 assert(r == ObjectMonitor::OM_OK, "raw_wait should have worked");
aoqi@0 3158 if (r != ObjectMonitor::OM_OK) { // robustness
aoqi@0 3159 return JVMTI_ERROR_INTERNAL;
aoqi@0 3160 }
aoqi@0 3161
aoqi@0 3162 return JVMTI_ERROR_NONE;
aoqi@0 3163 } /* end RawMonitorWait */
aoqi@0 3164
aoqi@0 3165
aoqi@0 3166 // rmonitor - pre-checked for validity
aoqi@0 3167 jvmtiError
aoqi@0 3168 JvmtiEnv::RawMonitorNotify(JvmtiRawMonitor * rmonitor) {
csahu@8316 3169 int r = 0;
aoqi@0 3170 Thread* thread = Thread::current();
aoqi@0 3171
aoqi@0 3172 if (thread->is_Java_thread()) {
aoqi@0 3173 JavaThread* current_thread = (JavaThread*)thread;
aoqi@0 3174 // Not really unknown but ThreadInVMfromNative does more than we want
aoqi@0 3175 ThreadInVMfromUnknown __tiv;
aoqi@0 3176 r = rmonitor->raw_notify(current_thread);
aoqi@0 3177 } else {
aoqi@0 3178 if (thread->is_VM_thread() || thread->is_ConcurrentGC_thread()) {
aoqi@0 3179 r = rmonitor->raw_notify(thread);
aoqi@0 3180 } else {
aoqi@0 3181 ShouldNotReachHere();
aoqi@0 3182 }
aoqi@0 3183 }
aoqi@0 3184
aoqi@0 3185 if (r == ObjectMonitor::OM_ILLEGAL_MONITOR_STATE) {
aoqi@0 3186 return JVMTI_ERROR_NOT_MONITOR_OWNER;
aoqi@0 3187 }
aoqi@0 3188 assert(r == ObjectMonitor::OM_OK, "raw_notify should have worked");
aoqi@0 3189 if (r != ObjectMonitor::OM_OK) { // robustness
aoqi@0 3190 return JVMTI_ERROR_INTERNAL;
aoqi@0 3191 }
aoqi@0 3192
aoqi@0 3193 return JVMTI_ERROR_NONE;
aoqi@0 3194 } /* end RawMonitorNotify */
aoqi@0 3195
aoqi@0 3196
aoqi@0 3197 // rmonitor - pre-checked for validity
aoqi@0 3198 jvmtiError
aoqi@0 3199 JvmtiEnv::RawMonitorNotifyAll(JvmtiRawMonitor * rmonitor) {
csahu@8316 3200 int r = 0;
aoqi@0 3201 Thread* thread = Thread::current();
aoqi@0 3202
aoqi@0 3203 if (thread->is_Java_thread()) {
aoqi@0 3204 JavaThread* current_thread = (JavaThread*)thread;
aoqi@0 3205 ThreadInVMfromUnknown __tiv;
aoqi@0 3206 r = rmonitor->raw_notifyAll(current_thread);
aoqi@0 3207 } else {
aoqi@0 3208 if (thread->is_VM_thread() || thread->is_ConcurrentGC_thread()) {
aoqi@0 3209 r = rmonitor->raw_notifyAll(thread);
aoqi@0 3210 } else {
aoqi@0 3211 ShouldNotReachHere();
aoqi@0 3212 }
aoqi@0 3213 }
aoqi@0 3214
aoqi@0 3215 if (r == ObjectMonitor::OM_ILLEGAL_MONITOR_STATE) {
aoqi@0 3216 return JVMTI_ERROR_NOT_MONITOR_OWNER;
aoqi@0 3217 }
aoqi@0 3218 assert(r == ObjectMonitor::OM_OK, "raw_notifyAll should have worked");
aoqi@0 3219 if (r != ObjectMonitor::OM_OK) { // robustness
aoqi@0 3220 return JVMTI_ERROR_INTERNAL;
aoqi@0 3221 }
aoqi@0 3222
aoqi@0 3223 return JVMTI_ERROR_NONE;
aoqi@0 3224 } /* end RawMonitorNotifyAll */
aoqi@0 3225
aoqi@0 3226
aoqi@0 3227 //
aoqi@0 3228 // JNI Function Interception functions
aoqi@0 3229 //
aoqi@0 3230
aoqi@0 3231
aoqi@0 3232 // function_table - pre-checked for NULL
aoqi@0 3233 jvmtiError
aoqi@0 3234 JvmtiEnv::SetJNIFunctionTable(const jniNativeInterface* function_table) {
aoqi@0 3235 // Copy jni function table at safepoint.
aoqi@0 3236 VM_JNIFunctionTableCopier copier(function_table);
aoqi@0 3237 VMThread::execute(&copier);
aoqi@0 3238
aoqi@0 3239 return JVMTI_ERROR_NONE;
aoqi@0 3240 } /* end SetJNIFunctionTable */
aoqi@0 3241
aoqi@0 3242
aoqi@0 3243 // function_table - pre-checked for NULL
aoqi@0 3244 jvmtiError
aoqi@0 3245 JvmtiEnv::GetJNIFunctionTable(jniNativeInterface** function_table) {
aoqi@0 3246 *function_table=(jniNativeInterface*)jvmtiMalloc(sizeof(jniNativeInterface));
aoqi@0 3247 if (*function_table == NULL)
aoqi@0 3248 return JVMTI_ERROR_OUT_OF_MEMORY;
aoqi@0 3249 memcpy(*function_table,(JavaThread::current())->get_jni_functions(),sizeof(jniNativeInterface));
aoqi@0 3250 return JVMTI_ERROR_NONE;
aoqi@0 3251 } /* end GetJNIFunctionTable */
aoqi@0 3252
aoqi@0 3253
aoqi@0 3254 //
aoqi@0 3255 // Event Management functions
aoqi@0 3256 //
aoqi@0 3257
aoqi@0 3258 jvmtiError
aoqi@0 3259 JvmtiEnv::GenerateEvents(jvmtiEvent event_type) {
aoqi@0 3260 // can only generate two event types
aoqi@0 3261 if (event_type != JVMTI_EVENT_COMPILED_METHOD_LOAD &&
aoqi@0 3262 event_type != JVMTI_EVENT_DYNAMIC_CODE_GENERATED) {
aoqi@0 3263 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
aoqi@0 3264 }
aoqi@0 3265
aoqi@0 3266 // for compiled_method_load events we must check that the environment
aoqi@0 3267 // has the can_generate_compiled_method_load_events capability.
aoqi@0 3268 if (event_type == JVMTI_EVENT_COMPILED_METHOD_LOAD) {
aoqi@0 3269 if (get_capabilities()->can_generate_compiled_method_load_events == 0) {
aoqi@0 3270 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
aoqi@0 3271 }
aoqi@0 3272 return JvmtiCodeBlobEvents::generate_compiled_method_load_events(this);
aoqi@0 3273 } else {
aoqi@0 3274 return JvmtiCodeBlobEvents::generate_dynamic_code_events(this);
aoqi@0 3275 }
aoqi@0 3276
aoqi@0 3277 } /* end GenerateEvents */
aoqi@0 3278
aoqi@0 3279
aoqi@0 3280 //
aoqi@0 3281 // Extension Mechanism functions
aoqi@0 3282 //
aoqi@0 3283
aoqi@0 3284 // extension_count_ptr - pre-checked for NULL
aoqi@0 3285 // extensions - pre-checked for NULL
aoqi@0 3286 jvmtiError
aoqi@0 3287 JvmtiEnv::GetExtensionFunctions(jint* extension_count_ptr, jvmtiExtensionFunctionInfo** extensions) {
aoqi@0 3288 return JvmtiExtensions::get_functions(this, extension_count_ptr, extensions);
aoqi@0 3289 } /* end GetExtensionFunctions */
aoqi@0 3290
aoqi@0 3291
aoqi@0 3292 // extension_count_ptr - pre-checked for NULL
aoqi@0 3293 // extensions - pre-checked for NULL
aoqi@0 3294 jvmtiError
aoqi@0 3295 JvmtiEnv::GetExtensionEvents(jint* extension_count_ptr, jvmtiExtensionEventInfo** extensions) {
aoqi@0 3296 return JvmtiExtensions::get_events(this, extension_count_ptr, extensions);
aoqi@0 3297 } /* end GetExtensionEvents */
aoqi@0 3298
aoqi@0 3299
aoqi@0 3300 // callback - NULL is a valid value, must be checked
aoqi@0 3301 jvmtiError
aoqi@0 3302 JvmtiEnv::SetExtensionEventCallback(jint extension_event_index, jvmtiExtensionEvent callback) {
aoqi@0 3303 return JvmtiExtensions::set_event_callback(this, extension_event_index, callback);
aoqi@0 3304 } /* end SetExtensionEventCallback */
aoqi@0 3305
aoqi@0 3306 //
aoqi@0 3307 // Timers functions
aoqi@0 3308 //
aoqi@0 3309
aoqi@0 3310 // info_ptr - pre-checked for NULL
aoqi@0 3311 jvmtiError
aoqi@0 3312 JvmtiEnv::GetCurrentThreadCpuTimerInfo(jvmtiTimerInfo* info_ptr) {
aoqi@0 3313 os::current_thread_cpu_time_info(info_ptr);
aoqi@0 3314 return JVMTI_ERROR_NONE;
aoqi@0 3315 } /* end GetCurrentThreadCpuTimerInfo */
aoqi@0 3316
aoqi@0 3317
aoqi@0 3318 // nanos_ptr - pre-checked for NULL
aoqi@0 3319 jvmtiError
aoqi@0 3320 JvmtiEnv::GetCurrentThreadCpuTime(jlong* nanos_ptr) {
aoqi@0 3321 *nanos_ptr = os::current_thread_cpu_time();
aoqi@0 3322 return JVMTI_ERROR_NONE;
aoqi@0 3323 } /* end GetCurrentThreadCpuTime */
aoqi@0 3324
aoqi@0 3325
aoqi@0 3326 // info_ptr - pre-checked for NULL
aoqi@0 3327 jvmtiError
aoqi@0 3328 JvmtiEnv::GetThreadCpuTimerInfo(jvmtiTimerInfo* info_ptr) {
aoqi@0 3329 os::thread_cpu_time_info(info_ptr);
aoqi@0 3330 return JVMTI_ERROR_NONE;
aoqi@0 3331 } /* end GetThreadCpuTimerInfo */
aoqi@0 3332
aoqi@0 3333
aoqi@0 3334 // Threads_lock NOT held, java_thread not protected by lock
aoqi@0 3335 // java_thread - pre-checked
aoqi@0 3336 // nanos_ptr - pre-checked for NULL
aoqi@0 3337 jvmtiError
aoqi@0 3338 JvmtiEnv::GetThreadCpuTime(JavaThread* java_thread, jlong* nanos_ptr) {
aoqi@0 3339 *nanos_ptr = os::thread_cpu_time(java_thread);
aoqi@0 3340 return JVMTI_ERROR_NONE;
aoqi@0 3341 } /* end GetThreadCpuTime */
aoqi@0 3342
aoqi@0 3343
aoqi@0 3344 // info_ptr - pre-checked for NULL
aoqi@0 3345 jvmtiError
aoqi@0 3346 JvmtiEnv::GetTimerInfo(jvmtiTimerInfo* info_ptr) {
aoqi@0 3347 os::javaTimeNanos_info(info_ptr);
aoqi@0 3348 return JVMTI_ERROR_NONE;
aoqi@0 3349 } /* end GetTimerInfo */
aoqi@0 3350
aoqi@0 3351
aoqi@0 3352 // nanos_ptr - pre-checked for NULL
aoqi@0 3353 jvmtiError
aoqi@0 3354 JvmtiEnv::GetTime(jlong* nanos_ptr) {
aoqi@0 3355 *nanos_ptr = os::javaTimeNanos();
aoqi@0 3356 return JVMTI_ERROR_NONE;
aoqi@0 3357 } /* end GetTime */
aoqi@0 3358
aoqi@0 3359
aoqi@0 3360 // processor_count_ptr - pre-checked for NULL
aoqi@0 3361 jvmtiError
aoqi@0 3362 JvmtiEnv::GetAvailableProcessors(jint* processor_count_ptr) {
aoqi@0 3363 *processor_count_ptr = os::active_processor_count();
aoqi@0 3364 return JVMTI_ERROR_NONE;
aoqi@0 3365 } /* end GetAvailableProcessors */
aoqi@0 3366
aoqi@0 3367 //
aoqi@0 3368 // System Properties functions
aoqi@0 3369 //
aoqi@0 3370
aoqi@0 3371 // count_ptr - pre-checked for NULL
aoqi@0 3372 // property_ptr - pre-checked for NULL
aoqi@0 3373 jvmtiError
aoqi@0 3374 JvmtiEnv::GetSystemProperties(jint* count_ptr, char*** property_ptr) {
aoqi@0 3375 jvmtiError err = JVMTI_ERROR_NONE;
aoqi@0 3376
aoqi@0 3377 *count_ptr = Arguments::PropertyList_count(Arguments::system_properties());
aoqi@0 3378
aoqi@0 3379 err = allocate(*count_ptr * sizeof(char *), (unsigned char **)property_ptr);
aoqi@0 3380 if (err != JVMTI_ERROR_NONE) {
aoqi@0 3381 return err;
aoqi@0 3382 }
aoqi@0 3383 int i = 0 ;
aoqi@0 3384 for (SystemProperty* p = Arguments::system_properties(); p != NULL && i < *count_ptr; p = p->next(), i++) {
aoqi@0 3385 const char *key = p->key();
aoqi@0 3386 char **tmp_value = *property_ptr+i;
aoqi@0 3387 err = allocate((strlen(key)+1) * sizeof(char), (unsigned char**)tmp_value);
aoqi@0 3388 if (err == JVMTI_ERROR_NONE) {
aoqi@0 3389 strcpy(*tmp_value, key);
aoqi@0 3390 } else {
aoqi@0 3391 // clean up previously allocated memory.
fmatte@9511 3392 for (int j = 0; j < i; j++) {
aoqi@0 3393 Deallocate((unsigned char*)*property_ptr+j);
aoqi@0 3394 }
aoqi@0 3395 Deallocate((unsigned char*)property_ptr);
aoqi@0 3396 break;
aoqi@0 3397 }
aoqi@0 3398 }
aoqi@0 3399 return err;
aoqi@0 3400 } /* end GetSystemProperties */
aoqi@0 3401
aoqi@0 3402
aoqi@0 3403 // property - pre-checked for NULL
aoqi@0 3404 // value_ptr - pre-checked for NULL
aoqi@0 3405 jvmtiError
aoqi@0 3406 JvmtiEnv::GetSystemProperty(const char* property, char** value_ptr) {
aoqi@0 3407 jvmtiError err = JVMTI_ERROR_NONE;
aoqi@0 3408 const char *value;
aoqi@0 3409
aoqi@0 3410 value = Arguments::PropertyList_get_value(Arguments::system_properties(), property);
aoqi@0 3411 if (value == NULL) {
aoqi@0 3412 err = JVMTI_ERROR_NOT_AVAILABLE;
aoqi@0 3413 } else {
aoqi@0 3414 err = allocate((strlen(value)+1) * sizeof(char), (unsigned char **)value_ptr);
aoqi@0 3415 if (err == JVMTI_ERROR_NONE) {
aoqi@0 3416 strcpy(*value_ptr, value);
aoqi@0 3417 }
aoqi@0 3418 }
aoqi@0 3419 return err;
aoqi@0 3420 } /* end GetSystemProperty */
aoqi@0 3421
aoqi@0 3422
aoqi@0 3423 // property - pre-checked for NULL
aoqi@0 3424 // value - NULL is a valid value, must be checked
aoqi@0 3425 jvmtiError
aoqi@0 3426 JvmtiEnv::SetSystemProperty(const char* property, const char* value_ptr) {
aoqi@0 3427 jvmtiError err =JVMTI_ERROR_NOT_AVAILABLE;
aoqi@0 3428
aoqi@0 3429 for (SystemProperty* p = Arguments::system_properties(); p != NULL; p = p->next()) {
aoqi@0 3430 if (strcmp(property, p->key()) == 0) {
aoqi@0 3431 if (p->set_value((char *)value_ptr)) {
aoqi@0 3432 err = JVMTI_ERROR_NONE;
aoqi@0 3433 }
aoqi@0 3434 }
aoqi@0 3435 }
aoqi@0 3436 return err;
aoqi@0 3437 } /* end SetSystemProperty */

mercurial