Skip to content

Tuples are not specialized when passed a non-literal java primitive #19181

Open
@oridag

Description

@oridag

Compiler version

3.2.2

Minimized code

analyze.sc:

import org.openjdk.jol.info.ClassLayout

println("specialized:\n"  + ClassLayout.parseInstance((1, 2)).toPrintable())
println("not specialized:\n"  + ClassLayout.parseInstance((new java.lang.Integer(1).intValue, new java.lang.Integer(2).intValue)).toPrintable())

run:

scala-cli analyze.sc --dep org.openjdk.jol:jol-core:0.17 -S 3.2.2

Output

specialized:
scala.Tuple2$mcII$sp object internals:
OFF  SZ               TYPE DESCRIPTION                VALUE
  0   8                    (object header: mark)      0x0000000000000001 (non-biasable; age: 0)
  8   4                    (object header: class)     0x00084e88
 12   4   java.lang.Object Tuple2._1                  null
 16   4   java.lang.Object Tuple2._2                  null
 20   4                int Tuple2$mcII$sp._1$mcI$sp   1
 24   4                int Tuple2$mcII$sp._2$mcI$sp   2
 28   4                    (object alignment gap)
Instance size: 32 bytes
Space losses: 0 bytes internal + 4 bytes external = 4 bytes total

not specialized:
scala.Tuple2 object internals:
OFF  SZ               TYPE DESCRIPTION               VALUE
  0   8                    (object header: mark)     0x0000000000000001 (non-biasable; age: 0)
  8   4                    (object header: class)    0x000079d0
 12   4   java.lang.Object Tuple2._1                 1
 16   4   java.lang.Object Tuple2._2                 2
 20   4                    (object alignment gap)
Instance size: 24 bytes
Space losses: 0 bytes internal + 4 bytes external = 4 bytes total```

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions