src/share/vm/prims/jvmtiEnv.cpp

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 6689
997fd9660dd5
parent 0
f90c822e73f8
child 7535
7ae4e26cb1e0
permissions
-rw-r--r--

merge

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

mercurial