1569 if (var->type() == T_OBJECT) { 1570 JVMCIENV->put_object_at(array, i, HotSpotJVMCI::wrap(locals->at(i)->get_obj()())); 1571 } 1572 } 1573 HotSpotJVMCI::HotSpotStackFrameReference::set_objectsMaterialized(JVMCIENV, hs_frame, JNI_TRUE); 1574 C2V_END 1575 1576 // Creates a scope where the current thread is attached and detached 1577 // from HotSpot if it wasn't already attached when entering the scope. 1578 extern "C" void jio_printf(const char *fmt, ...); 1579 class AttachDetach : public StackObj { 1580 public: 1581 bool _attached; 1582 AttachDetach(JNIEnv* env, Thread* current_thread) { 1583 if (current_thread == NULL) { 1584 extern struct JavaVM_ main_vm; 1585 JNIEnv* hotspotEnv; 1586 jint res = main_vm.AttachCurrentThread((void**)&hotspotEnv, NULL); 1587 _attached = res == JNI_OK; 1588 static volatile int report_attach_error = 0; 1589 if (res != JNI_OK && report_attach_error == 0 && Atomic::cmpxchg(1, &report_attach_error, 0) == 0) { 1590 // Only report an attach error once 1591 jio_printf("Warning: attaching current thread to VM failed with %d (future attach errors are suppressed)\n", res); 1592 } 1593 } else { 1594 _attached = false; 1595 } 1596 } 1597 ~AttachDetach() { 1598 if (_attached && get_current_thread() != NULL) { 1599 extern struct JavaVM_ main_vm; 1600 jint res = main_vm.DetachCurrentThread(); 1601 static volatile int report_detach_error = 0; 1602 if (res != JNI_OK && report_detach_error == 0 && Atomic::cmpxchg(1, &report_detach_error, 0) == 0) { 1603 // Only report an attach error once 1604 jio_printf("Warning: detaching current thread from VM failed with %d (future attach errors are suppressed)\n", res); 1605 } 1606 } 1607 } 1608 }; 1609 1610 C2V_VMENTRY_PREFIX(jint, writeDebugOutput, (JNIEnv* env, jobject, jbyteArray bytes, jint offset, jint length, bool flush, bool can_throw)) 1611 AttachDetach ad(env, base_thread); 1612 bool use_tty = true; 1613 if (base_thread == NULL) { 1614 if (!ad._attached) { 1615 // Can only use tty if the current thread is attached 1616 return 0; 1617 } 1618 base_thread = get_current_thread(); 1619 } 1620 JVMCITraceMark jtm("writeDebugOutput"); 1621 assert(base_thread->is_Java_thread(), "just checking"); 1622 JavaThread* thread = (JavaThread*) base_thread; | 1569 if (var->type() == T_OBJECT) { 1570 JVMCIENV->put_object_at(array, i, HotSpotJVMCI::wrap(locals->at(i)->get_obj()())); 1571 } 1572 } 1573 HotSpotJVMCI::HotSpotStackFrameReference::set_objectsMaterialized(JVMCIENV, hs_frame, JNI_TRUE); 1574 C2V_END 1575 1576 // Creates a scope where the current thread is attached and detached 1577 // from HotSpot if it wasn't already attached when entering the scope. 1578 extern "C" void jio_printf(const char *fmt, ...); 1579 class AttachDetach : public StackObj { 1580 public: 1581 bool _attached; 1582 AttachDetach(JNIEnv* env, Thread* current_thread) { 1583 if (current_thread == NULL) { 1584 extern struct JavaVM_ main_vm; 1585 JNIEnv* hotspotEnv; 1586 jint res = main_vm.AttachCurrentThread((void**)&hotspotEnv, NULL); 1587 _attached = res == JNI_OK; 1588 static volatile int report_attach_error = 0; 1589 if (res != JNI_OK && report_attach_error == 0 && Atomic::cmpxchg(&report_attach_error, 0, 1) == 0) { 1590 // Only report an attach error once 1591 jio_printf("Warning: attaching current thread to VM failed with %d (future attach errors are suppressed)\n", res); 1592 } 1593 } else { 1594 _attached = false; 1595 } 1596 } 1597 ~AttachDetach() { 1598 if (_attached && get_current_thread() != NULL) { 1599 extern struct JavaVM_ main_vm; 1600 jint res = main_vm.DetachCurrentThread(); 1601 static volatile int report_detach_error = 0; 1602 if (res != JNI_OK && report_detach_error == 0 && Atomic::cmpxchg(&report_detach_error, 0, 1) == 0) { 1603 // Only report an attach error once 1604 jio_printf("Warning: detaching current thread from VM failed with %d (future attach errors are suppressed)\n", res); 1605 } 1606 } 1607 } 1608 }; 1609 1610 C2V_VMENTRY_PREFIX(jint, writeDebugOutput, (JNIEnv* env, jobject, jbyteArray bytes, jint offset, jint length, bool flush, bool can_throw)) 1611 AttachDetach ad(env, base_thread); 1612 bool use_tty = true; 1613 if (base_thread == NULL) { 1614 if (!ad._attached) { 1615 // Can only use tty if the current thread is attached 1616 return 0; 1617 } 1618 base_thread = get_current_thread(); 1619 } 1620 JVMCITraceMark jtm("writeDebugOutput"); 1621 assert(base_thread->is_Java_thread(), "just checking"); 1622 JavaThread* thread = (JavaThread*) base_thread; |