Skip to content

Add --java-no-load-class option #2013

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

Merged
merged 1 commit into from
Apr 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/java_bytecode/java_bytecode_convert_class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@ class java_bytecode_convert_classt:public messaget
message_handlert &_message_handler,
size_t _max_array_length,
method_bytecodet &method_bytecode,
java_string_library_preprocesst &_string_preprocess)
java_string_library_preprocesst &_string_preprocess,
const std::unordered_set<std::string> &no_load_classes)
: messaget(_message_handler),
symbol_table(_symbol_table),
max_array_length(_max_array_length),
method_bytecode(method_bytecode),
string_preprocess(_string_preprocess)
string_preprocess(_string_preprocess),
no_load_classes(no_load_classes)
{
}

Expand All @@ -51,7 +53,9 @@ class java_bytecode_convert_classt:public messaget
// add array types to the symbol table
add_array_types(symbol_table);

bool loading_success=parse_tree.loading_successful;
const bool loading_success =
parse_tree.loading_successful &&
!no_load_classes.count(id2string(parse_tree.parsed_class.name));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer using .find or explicitly checking on 0 here, but no blocker

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about emitting a debug message in that case? Then you could also add a regression test

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug message would print EVERY class. I don't think it's such a good idea. We could however with that option simplify some test-gen regression tests.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd only send to debug the classes that were not loaded due to the setting of the new parameter. That could be used to validate the functioning in a regression test and would not create too much additional output.

if(loading_success)
convert(parse_tree.parsed_class);

Expand Down Expand Up @@ -81,6 +85,7 @@ class java_bytecode_convert_classt:public messaget

// see definition below for more info
static void add_array_types(symbol_tablet &symbol_table);
std::unordered_set<std::string> no_load_classes;
};

/// Auxiliary function to extract the generic superclass reference from the
Expand Down Expand Up @@ -667,14 +672,16 @@ bool java_bytecode_convert_class(
message_handlert &message_handler,
size_t max_array_length,
method_bytecodet &method_bytecode,
java_string_library_preprocesst &string_preprocess)
java_string_library_preprocesst &string_preprocess,
const std::unordered_set<std::string> &no_load_classes)
{
java_bytecode_convert_classt java_bytecode_convert_class(
symbol_table,
message_handler,
max_array_length,
method_bytecode,
string_preprocess);
string_preprocess,
no_load_classes);

try
{
Expand Down
4 changes: 3 additions & 1 deletion src/java_bytecode/java_bytecode_convert_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Author: Daniel Kroening, [email protected]
#ifndef CPROVER_JAVA_BYTECODE_JAVA_BYTECODE_CONVERT_CLASS_H
#define CPROVER_JAVA_BYTECODE_JAVA_BYTECODE_CONVERT_CLASS_H

#include <unordered_set>
#include <util/symbol_table.h>
#include <util/message.h>

Expand All @@ -25,7 +26,8 @@ bool java_bytecode_convert_class(
message_handlert &message_handler,
size_t max_array_length,
method_bytecodet &,
java_string_library_preprocesst &string_preprocess);
java_string_library_preprocesst &string_preprocess,
const std::unordered_set<std::string> &no_load_classes);

void mark_java_implicitly_generic_class_type(
const irep_idt &class_name,
Expand Down
24 changes: 16 additions & 8 deletions src/java_bytecode/java_bytecode_language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ void java_bytecode_languaget::get_language_options(const cmdlinet &cmd)
java_load_classes.insert(
java_load_classes.end(), values.begin(), values.end());
}
if(cmd.isset("java-no-load-class"))
{
const auto &values = cmd.get_values("java-no-load-class");
no_load_classes = {values.begin(), values.end()};
}

const std::list<std::string> &extra_entry_points=
cmd.get_values("lazy-methods-extra-entry-point");
Expand Down Expand Up @@ -576,13 +581,15 @@ bool java_bytecode_languaget::typecheck(
java_class_loader.class_map.find("java.lang.Object");
if(it!=java_class_loader.class_map.end())
{
if(java_bytecode_convert_class(
it->second,
symbol_table,
get_message_handler(),
max_user_array_length,
method_bytecode,
string_preprocess))
if(
java_bytecode_convert_class(
it->second,
symbol_table,
get_message_handler(),
max_user_array_length,
method_bytecode,
string_preprocess,
no_load_classes))
{
return true;
}
Expand All @@ -605,7 +612,8 @@ bool java_bytecode_languaget::typecheck(
get_message_handler(),
max_user_array_length,
method_bytecode,
string_preprocess))
string_preprocess,
no_load_classes))
{
return true;
}
Expand Down
5 changes: 4 additions & 1 deletion src/java_bytecode/java_bytecode_language.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ Author: Daniel Kroening, [email protected]
"(java-cp-include-files):" \
"(lazy-methods)" \
"(lazy-methods-extra-entry-point):" \
"(java-load-class):"
"(java-load-class):" \
"(java-no-load-class):"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be useful to document (in the help string) what that method does and how it interacts with the other options.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Help for both java-load-class and java-no-load-class is located in test-gen. I'll create another PR that moves them here.


#define JAVA_BYTECODE_LANGUAGE_OPTIONS_HELP /*NOLINT*/ \
" --no-core-models don't load internally provided models for core classes in\n"/* NOLINT(*) */ \
Expand Down Expand Up @@ -181,6 +182,8 @@ class java_bytecode_languaget:public languaget
synthetic_methods_mapt synthetic_methods;
stub_global_initializer_factoryt stub_global_initializer_factory;
class_hierarchyt class_hierarchy;
// List of classes to never load
std::unordered_set<std::string> no_load_classes;
};

std::unique_ptr<languaget> new_java_bytecode_language();
Expand Down