Skip to content

Commit c14677b

Browse files
committed
Java frontend: don't advertise ignored methods
Some org.cprover.CProver methods are always ignored by java-bytecode-convert-method (they are left with no body), but they are currently advertised to language_filest as available, making it harder for a driver program to discern when it should introduce a stub. This change stops advertising them, so they look more like other stub methods.
1 parent 15ce938 commit c14677b

File tree

4 files changed

+54
-22
lines changed

4 files changed

+54
-22
lines changed

jbmc/src/java_bytecode/java_bytecode_convert_method.cpp

+3-22
Original file line numberDiff line numberDiff line change
@@ -2824,32 +2824,13 @@ void java_bytecode_convert_method(
28242824
java_string_library_preprocesst &string_preprocess,
28252825
const class_hierarchyt &class_hierarchy)
28262826
{
2827-
static const std::unordered_set<std::string> methods_to_ignore
2828-
{
2829-
"nondetBoolean",
2830-
"nondetByte",
2831-
"nondetChar",
2832-
"nondetShort",
2833-
"nondetInt",
2834-
"nondetLong",
2835-
"nondetFloat",
2836-
"nondetDouble",
2837-
"nondetWithNull",
2838-
"nondetWithoutNull",
2839-
"notModelled",
2840-
"atomicBegin",
2841-
"atomicEnd",
2842-
"startThread",
2843-
"endThread",
2844-
"getCurrentThreadID"
2845-
};
2846-
28472827
if(std::regex_match(
28482828
id2string(class_symbol.name),
28492829
std::regex(".*org\\.cprover\\.CProver.*")) &&
2850-
methods_to_ignore.find(id2string(method.name))!=methods_to_ignore.end())
2830+
cprover_methods_to_ignore.count(id2string(method.name)))
28512831
{
2852-
// Ignore these methods, rely on default stubbing behaviour.
2832+
// Ignore these methods; fall back to the driver program's
2833+
// stubbing behaviour.
28532834
return;
28542835
}
28552836

jbmc/src/java_bytecode/java_bytecode_language.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -843,11 +843,36 @@ const select_pointer_typet &
843843
void java_bytecode_languaget::methods_provided(
844844
std::unordered_set<irep_idt> &methods) const
845845
{
846+
static std::string cprover_class_prefix = "java::org.cprover.CProver.";
847+
846848
// Add all string solver methods to map
847849
string_preprocess.get_all_function_names(methods);
848850
// Add all concrete methods to map
849851
for(const auto &kv : method_bytecode)
852+
{
853+
const std::string &method_id = id2string(kv.first);
854+
855+
// Avoid advertising org.cprover.CProver methods that the Java frontend will
856+
// never provide bodies for (java_bytecode_convert_method always leaves them
857+
// bodyless with intent for the driver program to stub them):
858+
if(has_prefix(method_id, cprover_class_prefix))
859+
{
860+
std::size_t method_name_end_offset =
861+
method_id.find(':', cprover_class_prefix.length());
862+
INVARIANT(
863+
method_name_end_offset != std::string::npos,
864+
"org.cprover.CProver method should have a postfix type descriptor");
865+
866+
const std::string method_name =
867+
method_id.substr(
868+
cprover_class_prefix.length(),
869+
method_name_end_offset - cprover_class_prefix.length());
870+
871+
if(cprover_methods_to_ignore.count(method_name))
872+
continue;
873+
}
850874
methods.insert(kv.first);
875+
}
851876
// Add all synthetic methods to map
852877
for(const auto &kv : synthetic_methods)
853878
methods.insert(kv.first);

jbmc/src/java_bytecode/java_utils.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -426,3 +426,25 @@ bool is_non_null_library_global(const irep_idt &symbolid)
426426
"java::java.lang.System.in"};
427427
return non_null_globals.count(symbolid);
428428
}
429+
430+
/// Methods belonging to the class org.cprover.CProver that should be ignored
431+
/// (not converted), leaving the driver program to stub them if it wishes.
432+
const std::unordered_set<std::string> cprover_methods_to_ignore
433+
{
434+
"nondetBoolean",
435+
"nondetByte",
436+
"nondetChar",
437+
"nondetShort",
438+
"nondetInt",
439+
"nondetLong",
440+
"nondetFloat",
441+
"nondetDouble",
442+
"nondetWithNull",
443+
"nondetWithoutNull",
444+
"notModelled",
445+
"atomicBegin",
446+
"atomicEnd",
447+
"startThread",
448+
"endThread",
449+
"getCurrentThreadID"
450+
};

jbmc/src/java_bytecode/java_utils.h

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Author: Daniel Kroening, [email protected]
99
#ifndef CPROVER_JAVA_BYTECODE_JAVA_UTILS_H
1010
#define CPROVER_JAVA_BYTECODE_JAVA_UTILS_H
1111

12+
#include <unordered_set>
13+
1214
#include <util/message.h>
1315
#include <util/std_expr.h>
1416
#include <util/symbol_table.h>
@@ -108,4 +110,6 @@ resolve_inherited_componentt::inherited_componentt get_inherited_component(
108110

109111
bool is_non_null_library_global(const irep_idt &);
110112

113+
extern const std::unordered_set<std::string> cprover_methods_to_ignore;
114+
111115
#endif // CPROVER_JAVA_BYTECODE_JAVA_UTILS_H

0 commit comments

Comments
 (0)