CACAO
sun_misc_Perf.cpp
Go to the documentation of this file.
1 /* src/native/vm/openjdk/sun_misc_Perf.cpp - sun/misc/Perf
2 
3  Copyright (C) 1996-2013
4  CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5  Copyright (C) 2009 Theobroma Systems Ltd.
6 
7  This file is part of CACAO.
8 
9  This program is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License as
11  published by the Free Software Foundation; either version 2, or (at
12  your option) any later version.
13 
14  This program is distributed in the hope that it will be useful, but
15  WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22  02110-1301, USA.
23 
24 */
25 
26 
27 #include "config.h"
28 
29 #include "native/jni.hpp"
30 #include "native/native.hpp"
31 
32 #include "toolbox/logging.hpp"
33 
34 #include "vm/utf8.hpp"
35 #include "vm/vm.hpp"
36 #include "vm/jit/builtin.hpp"
37 
38 static jlong initial_timer;
39 
40 // Native functions are exported as C functions.
41 extern "C" {
42 
43 /*
44  * Class: sun/misc/Perf
45  * Method: registerNatives
46  * Signature: ()V
47  */
48 JNIEXPORT void JNICALL Java_sun_misc_Perf_registerNatives(JNIEnv *env, jclass clazz)
49 {
50  /* The native methods of this function are already registered in
51  _Jv_sun_misc_Perf_init() which is called during VM
52  startup. */
53 }
54 
55 
56 /*
57  * Class: sun/misc/Perf
58  * Method: attach
59  * Signature: (Ljava/lang/String;II)Ljava/nio/ByteBuffer;
60  */
61 JNIEXPORT jobject JNICALL Java_sun_misc_Perf_attach(JNIEnv *env, jobject _this, jstring user, jint lvmid, jint mode)
62 {
63  log_println("Java_sun_misc_Perf_attach: Not supported!");
64  return NULL;
65 }
66 
67 
68 /*
69  * Class: sun/misc/Perf
70  * Method: createByteArray
71  * Signature: (Ljava/lang/String;II[BI)Ljava/nio/ByteBuffer;
72  */
73 JNIEXPORT jobject JNICALL Java_sun_misc_Perf_createByteArray(JNIEnv *env, jobject _this, jstring name, jint variability, jint units, jbyteArray value, jint max_length)
74 {
75  log_println("Java_sun_misc_Perf_createByteArray: Not supported!");
76  return NULL;
77 }
78 
79 static uint64_t dummy_perf;
80 
81 /*
82  * Class: sun/misc/Perf
83  * Method: createLong
84  * Signature: (Ljava/lang/String;IIJ)Ljava/nio/ByteBuffer;
85  */
86 JNIEXPORT jobject JNICALL Java_sun_misc_Perf_createLong(JNIEnv *env, jobject _this, jstring name, jint variability, jint units, jlong value)
87 {
88  return env->functions->NewDirectByteBuffer(env, &dummy_perf, sizeof(dummy_perf));
89 }
90 
91 
92 /*
93  * Class: sun/misc/Perf
94  * Method: detach
95  * Signature: (Ljava/nio/ByteBuffer;)V
96  */
97 JNIEXPORT void JNICALL Java_sun_misc_Perf_detach(JNIEnv *env, jobject _this, jobject bb)
98 {
99  log_println("Java_sun_misc_Perf_detach: Not supported!");
100 }
101 
102 
103 /*
104  * Class: sun/misc/Perf
105  * Method: highResCounter
106  * Signature: ()J
107  */
108 JNIEXPORT jlong JNICALL Java_sun_misc_Perf_highResCounter(JNIEnv *env, jobject _this)
109 {
110  return builtin_nanotime()/1000 - initial_timer;
111 }
112 
113 
114 /*
115  * Class: sun/misc/Perf
116  * Method: highResFrequency
117  * Signature: ()J
118  */
119 JNIEXPORT jlong JNICALL Java_sun_misc_Perf_highResFrequency(JNIEnv *env, jobject _this)
120 {
121  return 1000000;
122 }
123 
124 } // extern "C"
125 
126 
127 /* native methods implemented by this file ************************************/
128 
129 static JNINativeMethod methods[] = {
130  { (char*) "registerNatives", (char*) "()V", (void*) (uintptr_t) &Java_sun_misc_Perf_registerNatives },
131  { (char*) "attach", (char*) "(Ljava/lang/String;II)Ljava/nio/ByteBuffer;", (void*) (uintptr_t) &Java_sun_misc_Perf_attach },
132  { (char*) "createByteArray", (char*) "(Ljava/lang/String;II[BI)Ljava/nio/ByteBuffer;", (void*) (uintptr_t) &Java_sun_misc_Perf_createByteArray },
133  { (char*) "createLong", (char*) "(Ljava/lang/String;IIJ)Ljava/nio/ByteBuffer;", (void*) (uintptr_t) &Java_sun_misc_Perf_createLong },
134  { (char*) "detach", (char*) "(Ljava/nio/ByteBuffer;)V", (void*) (uintptr_t) &Java_sun_misc_Perf_detach },
135  { (char*) "highResCounter", (char*) "()J", (void*) (uintptr_t) &Java_sun_misc_Perf_highResCounter },
136  { (char*) "highResFrequency", (char*) "()J", (void*) (uintptr_t) &Java_sun_misc_Perf_highResFrequency },
137 };
138 
139 
140 /* _Jv_sun_misc_Perf_init ******************************************************
141 
142  Register native functions.
143 
144 *******************************************************************************/
145 
147 {
149 
150  Utf8String u = Utf8String::from_utf8("sun/misc/Perf");
151 
154 }
155 
156 
157 /*
158  * These are local overrides for various environment variables in Emacs.
159  * Please do not remove this and leave it at the end of the file, where
160  * Emacs will automagically detect them.
161  * ---------------------------------------------------------------------
162  * Local variables:
163  * mode: c++
164  * indent-tabs-mode: t
165  * c-basic-offset: 4
166  * tab-width: 4
167  * End:
168  * vim:noexpandtab:sw=4:ts=4:
169  */
Table containing all native methods registered with the VM.
Definition: native.hpp:132
NativeMethods & get_nativemethods()
Definition: vm.hpp:128
JNIEXPORT jlong JNICALL Java_sun_misc_Perf_highResCounter(JNIEnv *env, jobject _this)
void register_methods(Utf8String classname, const JNINativeMethod *methods, size_t count)
Register native methods with the VM.
Definition: native.cpp:242
_Jv_JNIEnv JNIEnv
Definition: jni.hpp:112
#define NATIVE_METHODS_COUNT
Definition: native.hpp:45
JNIEXPORT void JNICALL Java_sun_misc_Perf_registerNatives(JNIEnv *env, jclass clazz)
static jlong initial_timer
JNIEXPORT void JNICALL Java_sun_misc_Perf_detach(JNIEnv *env, jobject _this, jobject bb)
JNIEnv jclass jobject const char * name
Definition: jvmti.h:312
void log_println(const char *text,...)
Definition: logging.cpp:193
JNIEXPORT jobject JNICALL Java_sun_misc_Perf_createByteArray(JNIEnv *env, jobject _this, jstring name, jint variability, jint units, jbyteArray value, jint max_length)
void _Jv_sun_misc_Perf_init(void)
JNIEXPORT jlong JNICALL Java_sun_misc_Perf_highResFrequency(JNIEnv *env, jobject _this)
s8 builtin_nanotime(void)
Definition: builtin.cpp:2043
static Utf8String from_utf8(const char *, size_t)
Definition: utf8.cpp:335
static JNINativeMethod methods[]
JNIEXPORT jobject JNICALL Java_sun_misc_Perf_createLong(JNIEnv *env, jobject _this, jstring name, jint variability, jint units, jlong value)
static uint64_t dummy_perf
static VM * get_current()
Definition: vm.hpp:99
JNIEXPORT jobject JNICALL Java_sun_misc_Perf_attach(JNIEnv *env, jobject _this, jstring user, jint lvmid, jint mode)