gpt4 book ai didi

java - 在 Java 中,我可以决定我的字段存储在哪里 : in register, 缓存或 RAM?

转载 作者:行者123 更新时间:2023-12-03 21:10:25 25 4
gpt4 key购买 nike

我知道它是自动完成的 - 一条数据被访问的频率越高,它存储的处理器就越近。但是我可以用 Java 语法以某种方式影响它们的位置吗? Volatile,按照我的理解,将数据放入 3 级缓存或 RAM 中,因为它对所有线程都是可见的,对吗?

最佳答案

不,Java 语法不允许直接访问硬件。 Java language and virtual machine specification是管理如何解释 Java 代码的契约 - 它被明确地编写为针对虚拟机而不是实际的虚拟机。
来自 Section 1.2 :

The Java Virtual Machine is the cornerstone of the Java platform. Itis the component of the technology responsible for its hardware- andoperating system-independence, the small size of its compiled code,and its ability to protect users from malicious programs.

The Java Virtual Machine is an abstract computing machine. Like a realcomputing machine, it has an instruction set and manipulates variousmemory areas at run time. It is reasonably common to implement aprogramming language using a virtual machine; the best-known virtualmachine may be the P-Code machine of UCSD Pascal.


Java VM 甚至不需要可访问的寄存器或缓存。从规范的角度来看,图灵机可以很好地实现符合标准的 Java VM。

关于java - 在 Java 中,我可以决定我的字段存储在哪里 : in register, 缓存或 RAM?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64222837/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com