Skip to content

Commit

Permalink
[feature] local variable size
Browse files Browse the repository at this point in the history
  • Loading branch information
lvntky committed Jun 23, 2024
1 parent e03ee8b commit bc16072
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
60 changes: 60 additions & 0 deletions sample/javap_AddMain.txt
Original file line number Diff line number Diff line change
Expand Up @@ -356,3 +356,63 @@ Constant pool:
line 7: 10
}
SourceFile: "AddMain.java"
Classfile /home/levent/Projects/CVM/sample/AddMain.class
Last modified Jun 22, 2024; size 282 bytes
SHA-256 checksum 686603e16d220775966c2568e490983b83c5b5e5725340e919941eec59436e23
Compiled from "AddMain.java"
class AddMain
minor version: 0
major version: 66
flags: (0x0020) ACC_SUPER
this_class: #7 // AddMain
super_class: #2 // java/lang/Object
interfaces: 0, fields: 0, methods: 2, attributes: 1
Constant pool:
#1 = Methodref #2.#3 // java/lang/Object."<init>":()V
#2 = Class #4 // java/lang/Object
#3 = NameAndType #5:#6 // "<init>":()V
#4 = Utf8 java/lang/Object
#5 = Utf8 <init>
#6 = Utf8 ()V
#7 = Class #8 // AddMain
#8 = Utf8 AddMain
#9 = Utf8 Code
#10 = Utf8 LineNumberTable
#11 = Utf8 main
#12 = Utf8 ([Ljava/lang/String;)I
#13 = Utf8 SourceFile
#14 = Utf8 AddMain.java
{
AddMain();
descriptor: ()V
flags: (0x0000)
Code:
stack=1, locals=1, args_size=1
0: aload_0
1: invokespecial #1 // Method java/lang/Object."<init>":()V
4: return
LineNumberTable:
line 1: 0

public static int main(java.lang.String[]);
descriptor: ([Ljava/lang/String;)I
flags: (0x0009) ACC_PUBLIC, ACC_STATIC
Code:
stack=2, locals=4, args_size=1
0: bipush 14
2: istore_1
3: bipush 15
5: istore_2
6: iload_1
7: iload_2
8: iadd
9: istore_3
10: iload_3
11: ireturn
LineNumberTable:
line 4: 0
line 5: 3
line 6: 6
line 7: 10
}
SourceFile: "AddMain.java"
4 changes: 4 additions & 0 deletions src/execute_engine/cvm_execute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

// Temporarily store codeLength globally
size_t codeLength = 0;
size_t maxLocals = 0;

/**
* Helper methods
Expand Down Expand Up @@ -101,6 +102,9 @@ const uint8_t* CVM::getByteCode(const Classfile& cf,
codeLength = attr.attribute_length;
spdlog::info("code length: {}, The attribute name index: {:#x}",
codeLength, attr.attribute_name_index);
maxLocals = (attr.info[2] << 8) |
attr.info[3]; // max_locals is a 2-byte value at offset 2
spdlog::info("maxLocals = {}", maxLocals);
return attr.info;
}
}
Expand Down

0 comments on commit bc16072

Please sign in to comment.