java - 最大实时大小和最大实时计数没有意义

标签 java scala profiling jmc java-mission-control

在“内存”选项卡中查看时,我有一个类的最大实时大小为 8.96 GiB,而最大实时计数为 401,000,000。

这是一个 Scala Cons class 是 Byte 类型的 LinkedList 中的元素。 按照这个逻辑,401M 字节是 401 MiB(可能是某个常量的倍),所以我不明白为什么实时大小是 8.96 GiB,这要大几个数量级。

enter image description here

有人可以帮我理解这一点吗?

最佳答案

根据Java Object Layout ::

的工具实例大小
scala.collection.immutable.$colon$colon

是24字节

➜ java -cp scala-library-2.13.3.jar:jol-cli.jar org.openjdk.jol.Main internals 'scala.collection.immutable.$colon$colon'
# WARNING: Unable to attach Serviceability Agent. You can try again with escalated privileges. Two options: a) use -Djol.tryWithSudo=true to try with sudo; b) echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
# Running 64-bit HotSpot VM.
# Using compressed oop with 3-bit shift.
# Using compressed klass with 3-bit shift.
# WARNING | Compressed references base/shifts are guessed by the experiment!
# WARNING | Therefore, computed addresses are just guesses, and ARE NOT RELIABLE.
# WARNING | Make sure to attach Serviceability Agent to get the reliable addresses.
# Objects are 8 bytes aligned.
# Field sizes by type: 4, 1, 1, 2, 2, 4, 4, 8, 8 [bytes]
# Array element sizes: 4, 1, 1, 2, 2, 4, 4, 8, 8 [bytes]

Instantiated the sample instance via public scala.collection.immutable.$colon$colon(java.lang.Object,scala.collection.immutable.List)

scala.collection.immutable.$colon$colon object internals:
 OFFSET  SIZE                              TYPE DESCRIPTION                               VALUE
      0     4                                   (object header)                           01 00 00 00 (00000001 00000000 00000000 00000000) (1)
      4     4                                   (object header)                           00 00 00 00 (00000000 00000000 00000000 00000000) (0)
      8     4                                   (object header)                           77 0c 02 f8 (01110111 00001100 00000010 11111000) (-134083465)
     12     4                  java.lang.Object $colon$colon.head                         null
     16     4   scala.collection.immutable.List $colon$colon.next                         null
     20     4                                   (loss due to the next object alignment)
Instance size: 24 bytes
Space losses: 0 bytes internal + 4 bytes external = 4 bytes total

因此

401,000,000 * 24 byte = 9.62 Gigabtye = 8.96 Gigibyte

这是有道理的,因为除了标准对象头之外,:: 还至少存储对头尾部的引用

case class::[+A](head: A, next: List[A])

关于java - 最大实时大小和最大实时计数没有意义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62729022/

相关文章:

scala - 为什么 IDEA 在返回 Future of None 时会发出警告?

java - JProfiler 7.2.2 远程 JVM 崩溃

c# - 在哪里可以找到用于 Visual Studio 2008 中的 C# 应用程序的探查器?

java - 使用 AsyncHttpClient 的剩余文件上传客户端的示例代码

scala - Scala IDE 有 *.sbt 语法高亮支持吗?

java - 如何以编程方式设置android :background ="?android:attr/selectableItemBackground"?

scala - Play /记录/打印响应正文/遍历枚举器/缓冲正文

Java Mission Control 显示 "few profiling samples",为什么,我的其他选项是什么?

java - 在派生类对象上调用父类函数(Java)

java - 不同大小数组的吞吐量不同