Skip to content

Commit f765a0d

Browse files
author
Matthias Güdemann
committed
Rename, some more comments
1 parent 01dcda5 commit f765a0d

File tree

2 files changed

+55
-38
lines changed

2 files changed

+55
-38
lines changed

src/java_bytecode/java_bytecode_parse_tree.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ class java_bytecode_parse_treet
173173
bool is_abstract=false;
174174
bool is_enum=false;
175175
bool is_public=false, is_protected=false, is_private=false;
176-
bool read_attribute_bootstrapmethods = false;
176+
bool attribute_bootstrapmethods_read = false;
177177
size_t enum_elements=0;
178178

179179
enum class method_handle_typet
@@ -184,8 +184,9 @@ class java_bytecode_parse_treet
184184
UNKNOWN_HANDLE
185185
};
186186

187-
struct lambda_method_handlet
187+
class lambda_method_handlet
188188
{
189+
public:
189190
method_handle_typet handle_type;
190191
irep_idt lambda_method_name;
191192
irep_idt interface_type;

src/java_bytecode/java_bytecode_parser.cpp

+52-36
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class java_bytecode_parsert:public parsert
5353
method_handle_typet;
5454
typedef java_bytecode_parse_treet::classt::lambda_method_handlest
5555
lambda_method_handlest;
56-
typedef java_bytecode_parse_treet::classt::lambda_method_handlest
56+
typedef java_bytecode_parse_treet::classt::lambda_method_handle_mapt
5757
lambda_method_handle_mapt;
5858

5959
java_bytecode_parse_treet parse_tree;
@@ -134,7 +134,7 @@ class java_bytecode_parsert:public parsert
134134
void get_class_refs();
135135
void get_class_refs_rec(const typet &);
136136
void parse_local_variable_type_table(methodt &method);
137-
void parse_methodhandle(const pool_entryt &, lambda_method_handlet &);
137+
void parse_method_handle(const pool_entryt &, lambda_method_handlet &);
138138

139139
void skip_bytes(std::size_t bytes)
140140
{
@@ -1418,11 +1418,11 @@ void java_bytecode_parsert::rclass_attribute(classt &parsed_class)
14181418
else if(attribute_name == "BootstrapMethods")
14191419
{
14201420
INVARIANT(
1421-
!parsed_class.read_attribute_bootstrapmethods,
1421+
!parsed_class.attribute_bootstrapmethods_read,
14221422
"only one BootstrapMethods argument is allowed in a class file");
14231423

14241424
// mark as read in parsed class
1425-
parsed_class.read_attribute_bootstrapmethods = true;
1425+
parsed_class.attribute_bootstrapmethods_read = true;
14261426
u2 num_bootstrap_methods = read_u2();
14271427
for(size_t i = 0; i < num_bootstrap_methods; i++)
14281428
{
@@ -1434,7 +1434,7 @@ void java_bytecode_parsert::rclass_attribute(classt &parsed_class)
14341434
debug() << "INFO: parse BootstrapMethod handle "
14351435
<< num_bootstrap_arguments << " #args"
14361436
<< eom;
1437-
parse_methodhandle(entry, handle);
1437+
parse_method_handle(entry, handle);
14381438
if(
14391439
handle.handle_type ==
14401440
method_handle_typet::BOOTSTRAP_METHOD_HANDLE_ALT ||
@@ -1465,29 +1465,47 @@ void java_bytecode_parsert::rclass_attribute(classt &parsed_class)
14651465
// CONSTANT_Double
14661466
// CONSTANT_MethodHandle
14671467
// CONSTANT_MethodType
1468-
u2 arg_index1 = read_u2();
1469-
u2 arg_index2 = read_u2();
1470-
u2 arg_index3 = read_u2();
14711468

1472-
// skip rest
1469+
// We read the three arguments here to see whether they correspond to
1470+
// our hypotheses for this being a lambda function entry.
1471+
1472+
u2 argument_index1 = read_u2();
1473+
u2 argument_index2 = read_u2();
1474+
u2 argument_index3 = read_u2();
1475+
1476+
// The additional arguments for the altmetafactory call are skipped,
1477+
// as they are currently not used. We verify though that they are of
1478+
// CONSTANT_Integer type, cases where this does not hold will be
1479+
// analyzed further.
1480+
bool recognized = true;
14731481
for(size_t i = 3; i < num_bootstrap_arguments; i++)
1474-
read_u2();
1482+
{
1483+
u2 skipped_argument = read_u2();
1484+
recognized |= pool_entry(skipped_argument).tag == CONSTANT_Integer;
1485+
}
1486+
if(!recognized)
1487+
{
1488+
debug() << "format of BootstrapMethods entry not recognized"
1489+
<< eom;
1490+
return;
1491+
}
14751492

1476-
const pool_entryt &arg1 = pool_entry(arg_index1);
1477-
const pool_entryt &arg2 = pool_entry(arg_index2);
1478-
const pool_entryt &arg3 = pool_entry(arg_index3);
1493+
const pool_entryt &interface_type_argument =
1494+
pool_entry(argument_index1);
1495+
const pool_entryt &method_handle_argument =
1496+
pool_entry(argument_index2);
1497+
const pool_entryt &method_type_argument = pool_entry(argument_index3);
14791498

1480-
if(!(arg1.tag == CONSTANT_MethodType &&
1481-
arg2.tag == CONSTANT_MethodHandle &&
1482-
arg3.tag == CONSTANT_MethodType))
1499+
if(!(interface_type_argument.tag == CONSTANT_MethodType &&
1500+
method_handle_argument.tag == CONSTANT_MethodHandle &&
1501+
method_type_argument.tag == CONSTANT_MethodType))
14831502
return;
14841503

1485-
lambda_method_handlet real_handle;
1504+
lambda_method_handlet lambda_method_handle;
14861505
debug() << "INFO: parse lambda handle" << eom;
1487-
const pool_entryt &lambda_entry = pool_entry(arg_index2);
1488-
parse_methodhandle(lambda_entry, real_handle);
1506+
parse_method_handle(method_handle_argument, lambda_method_handle);
14891507
if(
1490-
real_handle.handle_type !=
1508+
lambda_method_handle.handle_type !=
14911509
method_handle_typet::LAMBDA_METHOD_HANDLE)
14921510
{
14931511
lambda_method_handlet empty_handle;
@@ -1498,37 +1516,37 @@ void java_bytecode_parsert::rclass_attribute(classt &parsed_class)
14981516
}
14991517
else
15001518
{
1501-
real_handle.interface_type = pool_entry(arg1.ref1).s;
1502-
real_handle.method_type = pool_entry(arg3.ref1).s;
1519+
lambda_method_handle.interface_type = pool_entry(interface_type_argument.ref1).s;
1520+
lambda_method_handle.method_type = pool_entry(method_type_argument.ref1).s;
15031521
parsed_class.lambda_method_handle_map[parsed_class.name].push_back(
1504-
real_handle);
1522+
lambda_method_handle);
15051523
debug()
15061524
<< "lambda function reference "
1507-
<< id2string(real_handle.lambda_method_name) << " in class \""
1525+
<< id2string(lambda_method_handle.lambda_method_name) << " in class \""
15081526
<< parsed_class.name << "\""
15091527
<< "\n interface type is "
1510-
<< id2string(pool_entry(arg1.ref1).s)
1528+
<< id2string(pool_entry(interface_type_argument.ref1).s)
15111529
<< "\n method type is "
1512-
<< id2string(pool_entry(arg3.ref1).s)
1530+
<< id2string(pool_entry(method_type_argument.ref1).s)
15131531
<< eom;
15141532
}
15151533
}
15161534
else
15171535
{
1518-
// skip arguments here
1536+
// skip bytes to align for next entry
15191537
for(size_t i = 0; i < num_bootstrap_arguments; i++)
15201538
read_u2();
1521-
error() << "ERROR: num_bootstrap_arguments must be 3" << eom;
1539+
error() << "ERROR: num_bootstrap_arguments must be at least 3" << eom;
15221540
}
15231541
}
15241542
else
15251543
{
15261544
lambda_method_handlet empty_handle;
15271545
parsed_class.lambda_method_handle_map[parsed_class.name].push_back(
15281546
empty_handle);
1529-
// skip arguments here
1547+
// skip bytes to align for next entry
15301548
for(size_t i = 0; i < num_bootstrap_arguments; i++)
1531-
read_u2();
1549+
read_u2();
15321550
error() << "ERROR: could not parse BootstrapMethods entry" << eom;
15331551
}
15341552
}
@@ -1665,9 +1683,9 @@ void java_bytecode_parsert::parse_local_variable_type_table(methodt &method)
16651683
/// Read method handle pointed to from constant pool entry at index, return type
16661684
/// of method handle and name if lambda function is found.
16671685
/// \param entry: the constant pool entry of the methodhandle_info structure
1668-
/// \param[out]: the method_handle type of the methodhandle_structure, either
1669-
/// for a recognized bootstrap method, for a lambda function or unknown
1670-
void java_bytecode_parsert::parse_methodhandle(
1686+
/// \param[out] handle: the method_handle type of the methodhandle_structure,
1687+
/// either for a recognized bootstrap method, for a lambda function or unknown
1688+
void java_bytecode_parsert::parse_method_handle(
16711689
const pool_entryt &entry,
16721690
lambda_method_handlet &handle)
16731691
{
@@ -1694,17 +1712,15 @@ void java_bytecode_parsert::parse_methodhandle(
16941712
"lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/"
16951713
"MethodType;)Ljava/lang/invoke/CallSite;")
16961714
handle.handle_type = method_handle_typet::BOOTSTRAP_METHOD_HANDLE;
1697-
16981715
// names seem to be lambda$$POSTFIX$NUM
16991716
// where $POSTFIX is $FUN for a function name in which the lambda is define
17001717
// "static" when it is a static member of the class
17011718
// "new" when it is a class variable, instantiated in <init>
1702-
if(has_prefix(id2string(pool_entry(nameandtype_entry.ref1).s), "lambda$"))
1719+
else if(has_prefix(id2string(pool_entry(nameandtype_entry.ref1).s), "lambda$"))
17031720
{
17041721
handle.lambda_method_name = pool_entry(nameandtype_entry.ref1).s;
17051722
handle.handle_type = method_handle_typet::LAMBDA_METHOD_HANDLE;
17061723
}
1707-
17081724
else if(
17091725
method_name ==
17101726
"java/lang/invoke/LambdaMetafactory.altMetafactory(Ljava/lang/invoke/"

0 commit comments

Comments
 (0)