1/*
2 * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26#include <jni.h>
27#include "jvm.h"
28#include "management.h"
29#include "sun_management_ThreadImpl.h"
30
31JNIEXPORT void JNICALL
32Java_sun_management_ThreadImpl_setThreadContentionMonitoringEnabled0
33  (JNIEnv *env, jclass cls, jboolean flag)
34{
35    jmm_interface->SetBoolAttribute(env, JMM_THREAD_CONTENTION_MONITORING, flag);
36}
37
38JNIEXPORT void JNICALL
39Java_sun_management_ThreadImpl_setThreadCpuTimeEnabled0
40  (JNIEnv *env, jclass cls, jboolean flag)
41{
42    jmm_interface->SetBoolAttribute(env, JMM_THREAD_CPU_TIME, flag);
43}
44
45JNIEXPORT void JNICALL
46Java_sun_management_ThreadImpl_setThreadAllocatedMemoryEnabled0
47  (JNIEnv *env, jclass cls, jboolean flag)
48{
49    jmm_interface->SetBoolAttribute(env, JMM_THREAD_ALLOCATED_MEMORY, flag);
50}
51
52JNIEXPORT void JNICALL
53Java_sun_management_ThreadImpl_getThreadInfo1
54  (JNIEnv *env, jclass cls, jlongArray ids, jint maxDepth,
55   jobjectArray infoArray)
56{
57    jmm_interface->GetThreadInfo(env, ids, maxDepth, infoArray);
58}
59
60JNIEXPORT jobjectArray JNICALL
61Java_sun_management_ThreadImpl_getThreads
62  (JNIEnv *env, jclass cls)
63{
64    return JVM_GetAllThreads(env, cls);
65}
66
67JNIEXPORT jlong JNICALL
68Java_sun_management_ThreadImpl_getThreadTotalCpuTime0
69  (JNIEnv *env, jclass cls, jlong tid)
70{
71    return jmm_interface->GetThreadCpuTimeWithKind(env, tid, JNI_TRUE /* user+sys */);
72}
73
74JNIEXPORT void JNICALL
75Java_sun_management_ThreadImpl_getThreadTotalCpuTime1
76  (JNIEnv *env, jclass cls, jlongArray ids, jlongArray timeArray)
77{
78    jmm_interface->GetThreadCpuTimesWithKind(env, ids, timeArray,
79                                             JNI_TRUE /* user+sys */);
80}
81
82JNIEXPORT jlong JNICALL
83Java_sun_management_ThreadImpl_getThreadUserCpuTime0
84  (JNIEnv *env, jclass cls, jlong tid)
85{
86    return jmm_interface->GetThreadCpuTimeWithKind(env, tid, JNI_FALSE /* user */);
87}
88
89JNIEXPORT void JNICALL
90Java_sun_management_ThreadImpl_getThreadUserCpuTime1
91  (JNIEnv *env, jclass cls, jlongArray ids, jlongArray timeArray)
92{
93    jmm_interface->GetThreadCpuTimesWithKind(env, ids, timeArray,
94                                             JNI_FALSE /* user */);
95}
96
97JNIEXPORT void JNICALL
98Java_sun_management_ThreadImpl_getThreadAllocatedMemory1
99  (JNIEnv *env, jclass cls, jlongArray ids, jlongArray sizeArray)
100{
101    jmm_interface->GetThreadAllocatedMemory(env, ids, sizeArray);
102}
103
104JNIEXPORT jobjectArray JNICALL
105Java_sun_management_ThreadImpl_findMonitorDeadlockedThreads0
106  (JNIEnv *env, jclass cls)
107{
108    return jmm_interface->FindCircularBlockedThreads(env);
109}
110
111JNIEXPORT jobjectArray JNICALL
112Java_sun_management_ThreadImpl_findDeadlockedThreads0
113  (JNIEnv *env, jclass cls)
114{
115    return jmm_interface->FindDeadlocks(env, JNI_FALSE /* !object_monitors_only */);
116}
117
118JNIEXPORT void JNICALL
119Java_sun_management_ThreadImpl_resetPeakThreadCount0
120  (JNIEnv *env, jclass cls)
121{
122    jvalue unused;
123    unused.i = 0;
124    jmm_interface->ResetStatistic(env, unused, JMM_STAT_PEAK_THREAD_COUNT);
125}
126
127JNIEXPORT void JNICALL
128Java_sun_management_ThreadImpl_resetContentionTimes0
129  (JNIEnv *env, jobject dummy, jlong tid)
130{
131    jvalue value;
132    value.j = tid;
133    jmm_interface->ResetStatistic(env, value, JMM_STAT_THREAD_CONTENTION_TIME);
134}
135
136JNIEXPORT jobjectArray JNICALL
137Java_sun_management_ThreadImpl_dumpThreads0
138  (JNIEnv *env, jclass cls, jlongArray ids, jboolean lockedMonitors, jboolean lockedSynchronizers)
139{
140    return jmm_interface->DumpThreads(env, ids, lockedMonitors, lockedSynchronizers);
141}
142