Skip to content

float a = 1+1; costs 17 bytecode. #400

Open

Description

@revalo
int bc_base = Clock.getBytecodeNum();
float a = 1 + 1;
System.out.println("Bytecode Cost: " + (Clock.getBytecodeNum() - bc_base));

This prints out 17, which I feel shouldn't be the case for an addition.

Activity

  1. lnductor commented on Jan 14, 2017

    @lnductor
    Contributor

    (It was actually 2, and the printing/calculating bytecode part used 15 alone)

  2. kazimuth commented on Jan 14, 2017

    @kazimuth
    Contributor
    float z = 1 + 1;

    generates:

     L0
        LINENUMBER 8 L0
        FCONST_2
        FSTORE 1
        LDC 2
        INVOKESTATIC battlecode/instrumenter/inject/RobotMonitor.incrementBytecodes (I)V
    

    Which is what would be expected.

    int bc_base = Clock.getBytecodeNum();
    float a = 1 + 1;
    System.out.println("Bytecode Cost: " + (Clock.getBytecodeNum() - bc_base));
    
      L0
        LINENUMBER 11 L0
        INVOKESTATIC battlecode/common/Clock.getBytecodeNum ()I
        ISTORE 1
        LDC 1
        INVOKESTATIC battlecode/instrumenter/inject/RobotMonitor.incrementBytecodes (I)V
       L1
        LINENUMBER 12 L1
        FCONST_2
        FSTORE 2
        LDC 2
        INVOKESTATIC battlecode/instrumenter/inject/RobotMonitor.incrementBytecodes (I)V
       L2
        LINENUMBER 13 L2
        GETSTATIC battlecode/instrumenter/inject/System.out : Ljava/io/PrintStream;
        NEW java/lang/StringBuilder
        DUP
        INVOKESPECIAL java/lang/StringBuilder.<init> ()V
        LDC "Bytecode Cost: "
        INVOKEVIRTUAL java/lang/StringBuilder.append (Ljava/lang/String;)Ljava/lang/StringBuilder;
        LDC 14
        INVOKESTATIC battlecode/instrumenter/inject/RobotMonitor.incrementBytecodes (I)V
        INVOKESTATIC battlecode/common/Clock.getBytecodeNum ()I
        ILOAD 1
        ISUB
        INVOKEVIRTUAL java/lang/StringBuilder.append (I)Ljava/lang/StringBuilder;
        INVOKEVIRTUAL java/lang/StringBuilder.toString ()Ljava/lang/String;
        INVOKEVIRTUAL java/io/PrintStream.println (Ljava/lang/String;)V
        LDC 12
        INVOKESTATIC battlecode/instrumenter/inject/RobotMonitor.incrementBytecodes (I)V
       L3
        LINENUMBER 14 L3
        LDC 1
        INVOKESTATIC battlecode/instrumenter/inject/RobotMonitor.incrementBytecodes (I)V
        RETURN
       L4
        LOCALVARIABLE rc Lbattlecode/common/RobotController; L0 L4 0
        LOCALVARIABLE bc_base I L1 L4 1
        LOCALVARIABLE a F L2 L4 2
        MAXSTACK = 4
        MAXLOCALS = 3
    
  3. kazimuth commented on Jan 14, 2017

    @kazimuth
    Contributor

    I still want to look into unexpected bytecode costs, so I'll keep this open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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