putstatic : set value of static field : index : visitFieldInsn()

Description
putstatic sets the value of the static field (also known as a class field) identified by <field-spec> to the single or double word value on the operand stack. For example, when you write the Java expression:

    java.lang.System.out = myStream;
this generates a call to getstatic like:

    aload_1    ; push object reference in local variable 1 (i.e. myStream) onto stack
               ; now use putstatic to assign it to System.out
    putstatic java/lang/System/out Ljava/io/PrintStream;
In Jasmin, putstatic takes two parameters, <field-spec> and <descriptor>. <field-spec> provides classname, the name of the class that defines the static field, as well fieldname, as the name of the field. In the example above, the <field-spec> is "java/lang/System/out", indicating that the classname is "java/lang/System" and the fieldname is "out". <descriptor> indicates the type of data held in the field, and is a standard Java type descriptor (see Chapter 4). In the example above, <descriptor> is "Ljava/io/PrintStream;", i.e. an instance of the PrintStream class.

putstatic first resolves classname into a Java class. Then it locates the fieldname in that class, determining the width of the field (in bytes) and its offset (in bytes) from the base of the class's static data. The type of the field must match <descriptor>. See Chapter 7 for more on how fields are resolved

To set the value of the field, putstatic pops either a 4-byte or 8-byte quantity off the stack (depending on the field descriptor), and truncates it to be wodth bytes long. Then it sets the bytes starting at offset and extending for width bytes in the class's static data to the new value.
Notes
Fields cannot be overriden, although they can be 'shadowed'. For example, with the two classes:

    class A { static int X; }
and
    class B extends A { static int X; }
then the runtime system will allocate storage for both the static field "A/X" and the static field "B/X". Which field is accessed is determined by the class name given in <field-spec>.
See also
putfield getfield getstatic
Stack
Before After
value ...
... ...
Bytecode
Type Description
u1 putstatic opcode = 0xB3 (179)
u2 index