首页 > 编程知识 正文

android.process.acore是什么意思,emulated是什么意思在手机里

时间:2023-05-05 11:48:08 阅读:20326 作者:74

在Java世界中,对System.nanoTime ()的理解非常好。 有人说,应该使用它来代替System.currentTimemillis (,如果可能)。 总的来说,他绝对在说谎,一点也不差,但开发者应该意识到一些缺点。 同样,它们有很多共同点,但这些缺点通常特定于平台。视窗

使用QueryPerformanceCounter API实现功能,已知该API存在一些问题。 据报道,它可能发展迅速,在多处理器计算机上的速度可能非常慢。 我在网上试着寻找了QueryPerformanceCounter的工作原理和作用。 关于这个主题还没有明确的结论,但是一些投稿可以简单介绍其结构。 我说,最有用的,大概是和那个人说话。 当然,稍微搜索一下,就会找到更多,但信息大致相同。

因此,如果可用,实现似乎使用HPET。 否则,以某种形式同步TSC和CPU之间的值。 有趣的是,QueryPerformanceCounter承诺返回的值会以一定的频率增长。 这意味着,如果使用TSC和多个CPU,则CPU不仅可能具有不同的TSC值,而且可能具有不同的频率,因此可能会遇到一些困难。 请注意所有注意事项。 Microsoft建议使用SetThreadAffinityMask阻止将QueryPerformanceCounter调用到单个处理器的线程。 这显然不会发生在JVM上。

LINUX

Linux与Windows非常相似,只是更透明。 (我总算下载了源代码: )。 该值是从带有CLOCK_MONOTONIC标志的clock_gettime读取的。 对于真正的男人,源可以从Linux源的vclock_gettime.c获取。 使用TSC或HPET。 与Windows的唯一区别是,Linux甚至不尝试同步从不同CPU读取的TSC值,而是按原样返回。 也就是说,该值意味着读取时可以在依赖于CPU的依赖关系中来回切换。 此外,与Windows签订合同时,Linux不会保持固定的更改频率。 另一方面,它绝对应该提高性能。

索拉里斯

Solaris很简单。 我相信在gethrtime上可以实现与linux几乎相同的clock_gettime。 区别在于,Solaris保证计数器不会返回。 这在Linux上是可能的,但可能返回相同的值。 从源代码可以看出,这种保证是使用CAS实现的,需要与主内存同步,在多处理器机器上可能会比较昂贵。 与Linux一样,更改率可能不同。

结论

结论是阴天之王。 开发者必须认识到功能不完美,可以向后或向前跳跃。 可能不会单调变化,变化率会根据CPU的时钟速度而变化。 而且,没有很多人想象的那么快。 在我的Windows 7计算机上测试单线程时,它只比System.currentTimeMillis ()快约10%,在多线程测试中线程数与CPU数相同,但相同。 因此,一般只提供分辨率提高,在某些情况下可能很重要。 最后,请注意,即使CPU频率没有变化,也不认为该值可以可靠地映射到系统时钟。 有关详细信息,请参阅此处。

附录

附录包括各种操作系统的功能实现。 源代码来自OpenJDK v.7。

的Solaris

//gethrtimecanmovebackwardsifreadfromonecpuandthenadifferentcpu/gettimenanosisguaranteedtonotmovebackwardonsolarisinlinehrtime _ tgettimenanos ({ if (VM _ version 33603360 supports _ }//useatomiclongloadsince 32-bit x86 uses2registerstokeeplong.consthrtime _ t prev=atomic 3360: load (if (now=prev ) ret ) //same or retrograde time; consthrtime _ to bsv=atomic :3360 cmpxchg (now,(volatile jlong* ) max_hrtime,prev ); 资产(obsv=prev,' invariant '; //monotonicity//ifthecassucceededthenwe ' redoneandr

eturn "now". // If the CAS failed and the observed value "obs" is >= now then // we should return "obs". If the CAS failed and now > obs > prv then // some other thread raced this thread and installed a new value, in which case // we could either (a) retry the entire operation, (b) retry trying to install now // or (c) just return obs. We use (c). No loop is required although in some cases // we might discard a higher "now" value in deference to a slightly lower but freshly // installed obs value. That's entirely benign -- it admits no new orderings compared // to (a) or (b) -- and greatly reduces coherence traffic. // We might also condition (c) on the magnitude of the delta between obs and now. // Avoiding excessive CAS operations to hot RW locations is critical. // See http://blogs.sun.com/dave/entry/cas_and_cache_trivia_invalidate return (prev == obsv) ? now : obsv ; } else { return oldgetTimeNanos(); }}

的Linux

jlong os::javaTimeNanos() { if (Linux::supports_monotonic_clock()) { struct timespec tp; int status = Linux::clock_gettime(CLOCK_MONOTONIC, &tp); assert(status == 0, "gettime error"); jlong result = jlong(tp.tv_sec) * (1000 * 1000 * 1000) + jlong(tp.tv_nsec); return result; } else { timeval time; int status = gettimeofday(&time, NULL); assert(status != -1, "linux error"); jlong usecs = jlong(time.tv_sec) * (1000 * 1000) + jlong(time.tv_usec); return 1000 * usecs; }}

视窗

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; }}

参考:

System.nanoTime()背后是什么? 来自我们的JCG合作伙伴   Stas博客上的 Stanislav Kobylansky。 热点虚拟机内部:时钟,计时器和计划事件 当心QueryPerformanceCounter() 为Windows实施持续更新的高分辨率时间提供程序 游戏计时和多核处理器 高精度事件计时器(维基百科) 时间戳计数器(维基百科)

翻译自: https://www.javacodegeeks.com/2012/02/what-is-behind-systemnanotime.html

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。