-
Notifications
You must be signed in to change notification settings - Fork 0
Constant pool management
These functions generate the constant pool for the Java class file.
-
void constant_pool_start()
Initializes the constant pool. Reserves space for theconstant_pool_countand starts indexing at1. -
void constant_pool_end()
Finalizes the constant pool by patching the total entry count at the reserved location.
Each function adds an entry and increments the counter.
-
UTF-8 String →
constant_utf8(const char *string)
Stores a UTF-8 encoded string. -
Integer →
constant_integer(uint32_t value)
Stores a 4-byte integer. -
Float →
constant_float(uint32_t value)
Stores a 4-byte floating-point number. -
Long →
constant_long(uint64_t value)
Stores an 8-byte long integer (split into two 4-byte chunks). -
Double →
constant_double(uint64_t value)
Stores an 8-byte double-precision float (split into two 4-byte chunks). -
Class Reference →
constant_class(uint16_t name_index)
Stores a reference to a class (index to a UTF-8 string in the pool). -
String Reference →
constant_string(uint16_t string_index)
Stores a reference to a string (index to a UTF-8 string in the pool). -
Field Reference →
constant_fieldref(uint16_t class_index, uint16_t name_and_type_index)
Stores a reference to a field (links a class to a name-and-type pair). -
Method Reference →
constant_methodref(uint16_t class_index, uint16_t name_and_type_index)
Stores a reference to a method (links a class to a name-and-type pair). -
Interface Method Reference →
constant_interfacemethodref(uint16_t class_index, uint16_t name_and_type_index)
Stores a reference to an interface method. -
Name and Type Descriptor →
constant_nameandtype(uint16_t name_index, uint16_t descriptor_index)
Stores a name and type pair (used in method/field references).
-
void increment_cp_counter()
Increases the constant pool counter. -
void patch_u2(size_t pos, uint16_t v)
Updates a 2-byte value in the buffer. -
void patch_u4(size_t pos, uint32_t v)
Updates a 4-byte value in the buffer.
constant_pool_start();
constant_utf8("System");
constant_integer(42);
constant_class(1); // Refers to first UTF-8 entry
constant_pool_end();This will create a constant pool with a UTF-8 string, an integer, and a class reference.