-
Notifications
You must be signed in to change notification settings - Fork 276
[TG-2478] Make Bootstrap methods available in method/instruction conversion #1937
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0a49697
37afd9a
a518393
bf04c93
a8ac3d4
078dc0f
3585f73
844bb20
8b172b4
823f2a7
d57fe53
212da75
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -306,6 +306,25 @@ code_typet member_type_lazy( | |
return to_code_type(member_type_from_descriptor); | ||
} | ||
|
||
/// Retrieves the symbol of the lambda method associated with the given | ||
/// lambda method handle (bootstrap method). | ||
/// \param lambda_method_handles Vector of lambda method handles (bootstrap | ||
/// methods) of the class where the lambda is called | ||
/// \param index Index of the lambda method handle in the vector | ||
/// \return Symbol of the lambda method if the method handle does not have an | ||
/// unknown type | ||
optionalt<symbolt> java_bytecode_convert_methodt::get_lambda_method_symbol( | ||
const java_class_typet::java_lambda_method_handlest &lambda_method_handles, | ||
const size_t &index) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
{ | ||
const symbol_exprt &lambda_method_handle = lambda_method_handles.at(index); | ||
// If the lambda method handle has an unknown type, it does not refer to | ||
// any symbol (it is a symbol expression with empty identifier) | ||
if(!lambda_method_handle.get_identifier().empty()) | ||
return symbol_table.lookup_ref(lambda_method_handle.get_identifier()); | ||
return {}; | ||
} | ||
|
||
/// This creates a method symbol in the symtab, but doesn't actually perform | ||
/// method conversion just yet. The caller should call | ||
/// java_bytecode_convert_method later to give the symbol/method a body. | ||
|
@@ -555,7 +574,11 @@ void java_bytecode_convert_methodt::convert( | |
current_method=method_symbol.name; | ||
method_has_this=code_type.has_this(); | ||
if((!m.is_abstract) && (!m.is_native)) | ||
method_symbol.value=convert_instructions(m, code_type, method_symbol.name); | ||
method_symbol.value = convert_instructions( | ||
m, | ||
code_type, | ||
method_symbol.name, | ||
to_java_class_type(class_symbol.type).lambda_method_handles()); | ||
} | ||
|
||
const bytecode_infot &java_bytecode_convert_methodt::get_bytecode_info( | ||
|
@@ -926,7 +949,8 @@ static unsigned get_bytecode_type_width(const typet &ty) | |
codet java_bytecode_convert_methodt::convert_instructions( | ||
const methodt &method, | ||
const code_typet &method_type, | ||
const irep_idt &method_name) | ||
const irep_idt &method_name, | ||
const java_class_typet::java_lambda_method_handlest &lambda_method_handles) | ||
{ | ||
const instructionst &instructions=method.instructions; | ||
|
||
|
@@ -1211,7 +1235,19 @@ codet java_bytecode_convert_methodt::convert_instructions( | |
else if(statement=="invokedynamic") | ||
{ | ||
// not used in Java | ||
code_typet &code_type=to_code_type(arg0.type()); | ||
code_typet &code_type = to_code_type(arg0.type()); | ||
|
||
const optionalt<symbolt> &lambda_method_symbol = get_lambda_method_symbol( | ||
lambda_method_handles, | ||
code_type.get_int(ID_java_lambda_method_handle_index)); | ||
if(lambda_method_symbol.has_value()) | ||
debug() << "Converting invokedynamic for lambda: " | ||
<< lambda_method_symbol.value().name << eom; | ||
else | ||
debug() << "Converting invokedynamic for lambda with unknown handle " | ||
"type" | ||
<< eom; | ||
|
||
const code_typet::parameterst ¶meters(code_type.parameters()); | ||
|
||
pop(parameters.size()); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -843,6 +843,7 @@ void java_bytecode_parsert::rconstant_pool() | |
it->expr.id("invokedynamic"); | ||
const pool_entryt &nameandtype_entry=pool_entry(it->ref2); | ||
typet type=type_entry(nameandtype_entry.ref2); | ||
type.set(ID_java_lambda_method_handle_index, it->ref1); | ||
it->expr.type()=type; | ||
} | ||
break; | ||
|
@@ -1776,9 +1777,9 @@ java_bytecode_parsert::parse_method_handle(const method_handle_infot &entry) | |
const name_and_type_infot &name_and_type = | ||
ref_entry.get_name_and_type(pool_entry_lambda); | ||
|
||
const std::string method_name = | ||
const std::string method_ref = | ||
class_entry.get_name(pool_entry_lambda) + "." + | ||
name_and_type.get_name(pool_entry_lambda) + | ||
name_and_type.get_name(pool_entry_lambda) + ':' + | ||
name_and_type.get_descriptor(pool_entry_lambda); | ||
|
||
lambda_method_handlet lambda_method_handle; | ||
|
@@ -1791,6 +1792,7 @@ java_bytecode_parsert::parse_method_handle(const method_handle_infot &entry) | |
// "new" when it is a class variable, instantiated in <init> | ||
lambda_method_handle.lambda_method_name = | ||
name_and_type.get_name(pool_entry_lambda); | ||
lambda_method_handle.lambda_method_ref = method_ref; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could be a |
||
lambda_method_handle.handle_type = | ||
method_handle_typet::LAMBDA_METHOD_HANDLE; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ Author: Daniel Kroening, [email protected] | |
#include <util/std_types.h> | ||
#include <util/c_types.h> | ||
#include <util/optional.h> | ||
#include <util/std_expr.h> | ||
|
||
class java_class_typet:public class_typet | ||
{ | ||
|
@@ -30,6 +31,30 @@ class java_class_typet:public class_typet | |
{ | ||
return set(ID_access, access); | ||
} | ||
|
||
typedef std::vector<symbol_exprt> java_lambda_method_handlest; | ||
|
||
const java_lambda_method_handlest &lambda_method_handles() const | ||
{ | ||
return (const java_lambda_method_handlest &)find( | ||
ID_java_lambda_method_handles) | ||
.get_sub(); | ||
} | ||
|
||
java_lambda_method_handlest &lambda_method_handles() | ||
{ | ||
return (java_lambda_method_handlest &)add(ID_java_lambda_method_handles) | ||
.get_sub(); | ||
} | ||
|
||
void add_lambda_method_handle(const irep_idt &identifier) | ||
{ | ||
lambda_method_handles().emplace_back(identifier); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't appear to be quite right, due to the mix an match of move semantics and const references. My understanding is that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, thank you for explaining how this works, I was wondering where the conversion from irep_idt to symbol_exprt was happening. I had previously been reading about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
void add_unknown_lambda_method_handle() | ||
{ | ||
lambda_method_handles().emplace_back(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could you please add a comment that explains why this works? I imagine it is because |
||
} | ||
}; | ||
|
||
inline const java_class_typet &to_java_class_type(const typet &type) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"... does not have an unknown ..." maybe better "... have a known ..." ?