openJDK上有完整的JDK源代码,JDK源代码由C++、Java、C、汇编 这四种语言组成。JVM主体是C++写的,JNI部分是C,工具类是Java写的,JVM里混有汇编代码。路径:openjdk-7-fcs-src-b147\jdk\src\share\native\java\lang\System.c 找到这个
?
1 2 3 4 5 6 | /* Only register the performance-critical methods */ static
JNINativeMethod methods[] = {
{
"currentTimeMillis"
,
"()J"
,(
void
*)&JVM_CurrentTimeMillis},
{
"nanoTime"
,
"()J"
,(
void
*)&JVM_NanoTime},
{
"arraycopy"
,
"("
OBJ
"I"
OBJ
"II)V"
, (
void
*)&JVM_ArrayCopy}, };
|
?
1 2 3 4 5 6 7 8 9 10 11 12 | jlong os::javaTimeNanos() {
if
(!has_performance_count) {
return
javaTimeMillis() * NANOS_PER_MILLISEC;
// the best we can do.
}
else
{
LARGE_INTEGER current_count;
QueryPerformanceCounter(¤t_count);
double
current = as_long(current_count);
double
freq = performance_frequency;
jlong
time
= (jlong)((current/freq) * NANOS_PER_SEC);
return
time
;
} } |
?
推荐阅读
- Integer常量池结合源码解析
- Java基础|Java 打印空心等腰三角形(方法2)
- gradle 每次运行都会下载依赖的解决办法
- 使用vector代替数组
- 如何获取ResultSet的行数和列数
- Java 时间戳格式化
- Java基础|Android开发——JVM、Dalvik以及ART的区别
- XML|XML报文转Map
- Java 8 时间,字符串和Long时间戳互转
- JAVA基础|JAVA基础(TreeMap键是Student值是String案例)