Skip to content

SIPUSH bytecode is not used for short integer constant  #33

@kiszk

Description

@kiszk

When I compiled the simple program using janinoc with janino 3.0.7, I realized that the compiled java bytecode does not use sipush java bytecode, but it uses ldc java bytecode. While it functionally works correctly, the generated java bytecode consumes an additional constant pool entry.
When I compiled this program using javac in OpenJDK8, the generated java bytecode uses sipush.

public class CP2 {
  static public void main(String[] argv) {
    int i = 32767;
  }
}
Classfile /home/ishizaki/Spark/PR/lsof/spark/CP2.class
  Last modified Nov 24, 2017; size 263 bytes
  MD5 checksum 8759300e8265dce5114c34a53ae853d0
  Compiled from "CP2.java"
public class CP2
  minor version: 0
  major version: 49
  flags: ACC_PUBLIC, ACC_SUPER
Constant pool:
   #1 = Utf8               CP2
   #2 = Class              #1             // CP2
   #3 = Utf8               java/lang/Object
   #4 = Class              #3             // java/lang/Object
   #5 = Utf8               SourceFile
   #6 = Utf8               CP2.java
   #7 = Utf8               main
   #8 = Utf8               ([Ljava/lang/String;)V
   #9 = Integer            32767
  #10 = Utf8               LineNumberTable
  #11 = Utf8               Code
  #12 = Utf8               <init>
  #13 = Utf8               ()V
  #14 = NameAndType        #12:#13        // "<init>":()V
  #15 = Methodref          #4.#14         // java/lang/Object."<init>":()V
{
  public static void main(java.lang.String[]);
    descriptor: ([Ljava/lang/String;)V
    flags: ACC_PUBLIC, ACC_STATIC
    Code:
      stack=1, locals=2, args_size=1
         0: ldc           #9                  // int 32767
         2: istore_1
         3: return
      LineNumberTable:
        line 3: 0
        line 2: 3

  public CP2();
    descriptor: ()V
    flags: ACC_PUBLIC
    Code:
      stack=1, locals=1, args_size=1
         0: aload_0
         1: invokespecial #15                 // Method java/lang/Object."<init>":()V
         4: return
      LineNumberTable:
        line 1: 0
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions