equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
2970 |
2970 |
2971 JVM_ENTRY(void, JVM_Yield(JNIEnv *env, jclass threadClass)) |
2971 JVM_ENTRY(void, JVM_Yield(JNIEnv *env, jclass threadClass)) |
2972 JVMWrapper("JVM_Yield"); |
2972 JVMWrapper("JVM_Yield"); |
2973 if (os::dont_yield()) return; |
2973 if (os::dont_yield()) return; |
2974 HOTSPOT_THREAD_YIELD(); |
2974 HOTSPOT_THREAD_YIELD(); |
2975 |
2975 os::naked_yield(); |
2976 // When ConvertYieldToSleep is off (default), this matches the classic VM use of yield. |
|
2977 // Critical for similar threading behaviour |
|
2978 if (ConvertYieldToSleep) { |
|
2979 os::sleep(thread, MinSleepInterval, false); |
|
2980 } else { |
|
2981 os::naked_yield(); |
|
2982 } |
|
2983 JVM_END |
2976 JVM_END |
2984 |
2977 |
2985 |
2978 |
2986 JVM_ENTRY(void, JVM_Sleep(JNIEnv* env, jclass threadClass, jlong millis)) |
2979 JVM_ENTRY(void, JVM_Sleep(JNIEnv* env, jclass threadClass, jlong millis)) |
2987 JVMWrapper("JVM_Sleep"); |
2980 JVMWrapper("JVM_Sleep"); |
3001 HOTSPOT_THREAD_SLEEP_BEGIN(millis); |
2994 HOTSPOT_THREAD_SLEEP_BEGIN(millis); |
3002 |
2995 |
3003 EventThreadSleep event; |
2996 EventThreadSleep event; |
3004 |
2997 |
3005 if (millis == 0) { |
2998 if (millis == 0) { |
3006 // When ConvertSleepToYield is on, this matches the classic VM implementation of |
2999 os::naked_yield(); |
3007 // JVM_Sleep. Critical for similar threading behaviour (Win32) |
|
3008 // It appears that in certain GUI contexts, it may be beneficial to do a short sleep |
|
3009 // for SOLARIS |
|
3010 if (ConvertSleepToYield) { |
|
3011 os::naked_yield(); |
|
3012 } else { |
|
3013 ThreadState old_state = thread->osthread()->get_state(); |
|
3014 thread->osthread()->set_state(SLEEPING); |
|
3015 os::sleep(thread, MinSleepInterval, false); |
|
3016 thread->osthread()->set_state(old_state); |
|
3017 } |
|
3018 } else { |
3000 } else { |
3019 ThreadState old_state = thread->osthread()->get_state(); |
3001 ThreadState old_state = thread->osthread()->get_state(); |
3020 thread->osthread()->set_state(SLEEPING); |
3002 thread->osthread()->set_state(SLEEPING); |
3021 if (os::sleep(thread, millis, true) == OS_INTRPT) { |
3003 if (os::sleep(thread, millis, true) == OS_INTRPT) { |
3022 // An asynchronous exception (e.g., ThreadDeathException) could have been thrown on |
3004 // An asynchronous exception (e.g., ThreadDeathException) could have been thrown on |