class Par extends java.lang.Object{ Stack layout: top_of_stack

class Par extends java.lang.Object{
Stack layout: top_of_stack, ..., bottom of stack
Par(int); //Static dispatch, instance method, 2 parameters (hidden/
the object being
initialized, plus int passed in), 0 locals
Code:
Stack: <empty>
0: aload_0
Stack: reference of type Par
1: invokespecial #1; //Method java/lang/Object."<init>":()V
Stack: <empty>
4: aload_0
Stack: reference of type Par
5: bipush 7
Stack: 7, reference of type Par
7: putfield #2; //Field field3:I
Stack: <empty>
10: aload_0
Stack: reference of type Par
11: iload_1
Stack: int value (from argument), reference of type Par
12: putfield #3; //Field field4:I
Stack: <empty>
15: return
Par(); //Static dispatch, instance method, 1 parameter (hidden/the
object being
initialized), 0 locals
Code:
Stack: <empty>
0: aload_0
Stack: reference of type Par
1: invokespecial #1; //Method java/lang/Object."<init>":()V
Stack: <empty>
4: aload_0
Stack: reference of type Par
5: bipush 7
Stack: 7, reference of type Par
7: putfield #2; //Field field3:I
Stack: <empty>
10: return
static void test1(int); //Static dispatch, 1 parameter passed in
1 local variable (object type and instance of Par)
Code:
Stack: <empty>
0: new #4; //class Par
Stack: reference of type Par
3: dup
Stack: reference of type Par, reference of type Par
4: iload_0
Stack: int value (argument passed in), reference of type Par,
reference of type Par
5: iconst_1
Stack: 1, int value (argument passed in), reference of type
Par, reference of type Par
6: isub
Stack: int value (result of subtraction), reference of type
Par, reference of type Par
7: invokespecial #5; //Method "<init>":(I)V
Stack: reference of type Par
10: astore_1
Stack: <empty>
11: aload_1
Stack: reference of type Par
12: dup
Stack: reference of type Par, reference of type Par
13: getfield #2; //Field field3:I
Stack: int value, reference of type Par
16: iconst_1
Stack: int value, int value, reference of type Par
17: iadd
Stack: int value, reference of type Par
18: putfield #2; //Field field3:I
Stack: <empty>
21: return
void test3(); //Dynamic dispatch, 1 parameter (hidden/the object being
initialized), 0 locals
Code:
Stack: <empty>
0: return
void test4(int); //Dynamic dispatch, 2 parameters (1 hidden/the object
being initialized, 1 integer), 0 locals
Code:
Stack: <empty>
0: aload_0
Stack: reference of type Par
1: iload_1
Stack: int value, reference of type Par
2: ldc #6; //int 1999999
Stack: int value, int value, reference of type Par
4: iadd
Stack: int value, reference of type Par
5: putfield #3; //Field field4:I
Stack: <empty>
8: getstatic #7; //Field field1:I
Stack: int value (field1's type)
11: iconst_1
Stack: int value, int value
12: iadd
Stack: int value
13: putstatic #7; //Field field1:I
Stack: <empty>
16: return
static void main(java.lang.String[]); //Static dispatch, 1 parameter,
0 locals
Code:
Stack: <empty>
0: aload_0
Stack: java.lang.String array reference
1: arraylength
Stack: int
2: invokestatic #8; //Method test1:(I)V
Stack: <empty>
5: return
}
parameter names can differ b/c they are lost in translation:
class Par {
static int field1;
int field3 = 7;
int field4;
Par(int k) { field4 = k; }
Par() { }
static void test1(int k) {
//question from class:
//Are values (7 and default) assigned
//the object's fields in the
//constructor as instructions or by
//runtime? see bytecode for the answer
Par p = new Par(k-1);
p.field3++;
}
void test3() { }
void test4(int i) {
field4 = i+1999999;
Par.field1++;
}
static void main(String args[]) {
Par.test1(args.length);
}
}
1 / 3 100%

class Par extends java.lang.Object{ Stack layout: top_of_stack

La catégorie de ce document est-elle correcte?
Merci pour votre participation!

Faire une suggestion

Avez-vous trouvé des erreurs dans linterface ou les textes ? Ou savez-vous comment améliorer linterface utilisateur de StudyLib ? Nhésitez pas à envoyer vos suggestions. Cest très important pour nous !