Scala中一个空类的大小是多少?
我使用 SizeEstimator 来获取一个空类的大小。但是我得到的大小是 1368(字节),这看起来比我预期的要高很多。
.class
文件大小吗?package mypackage
class EmptyClass {
}
对于我来说,在Windows上使用Java 1.8.0_121和Scala 2.11,它的大小为527个字节(文件大小将根据包名称而变化,因为文件包含类和包名称)。
javap
工具显示文件中包含的数据:
$ javap -c -v -cp my-app/target/scala-2.11/classes mypackage.EmptyClass
Classfile /.../mypackage/EmptyClass.class
Last modified 17-Jul-2017; size 527 bytes
MD5 checksum d97a3d664755c085417b469bb84f982b
Compiled from "EmptyClass.scala"
public class mypackage.EmptyClass
minor version: 0
major version: 52
flags: ACC_PUBLIC, ACC_SUPER
Constant pool:
#1 = Utf8 mypackage/EmptyClass
#2 = Class #1 // mypackage/EmptyClass
#3 = Utf8 java/lang/Object
#4 = Class #3 // java/lang/Object
#5 = Utf8 EmptyClass.scala
#6 = Utf8 Lscala/reflect/ScalaSignature;
#7 = Utf8 bytes
#8 = Utf8 E1A!
\tQQ)9uscm]:
\r\t\"\=qC\mZ3MA\t)i)1oY1mC&1:L(+4\t
5\rqJg.?)yC\t
= Utf8 <init>
#10 = Utf8 ()V
#11 = NameAndType #9:#10 // "<init>":()V
#12 = Methodref #4.#11 // java/lang/Object."<init>":()V
#13 = Utf8 this
#14 = Utf8 Lmypackage/EmptyClass;
#15 = Utf8 Code
#16 = Utf8 LocalVariableTable
#17 = Utf8 LineNumberTable
#18 = Utf8 SourceFile
#19 = Utf8 RuntimeVisibleAnnotations
#20 = Utf8 ScalaInlineInfo
#21 = Utf8 ScalaSig
{
public mypackage.EmptyClass();
descriptor: ()V
flags: ACC_PUBLIC
Code:
stack=1, locals=1, args_size=1
0: aload_0
1: invokespecial #12 // Method java/lang/Object."<init>":()V
4: return
LocalVariableTable:
Start Length Slot Name Signature
0 5 0 this Lmypackage/EmptyClass;
LineNumberTable:
line 5: 0
}
SourceFile: "EmptyClass.scala"
RuntimeVisibleAnnotations:
0: #6(#7=s#8)
Error: unknown attribute
ScalaInlineInfo: length = 0x9
01 00 00 01 00 09 00 0A 00
Error: unknown attribute
ScalaSig: length = 0x3
05 00 00