Skip to content

Commit 7089709

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 779fa71 commit 7089709

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
@@ -2821,32 +2821,13 @@ void java_bytecode_convert_method(
28212821
java_string_library_preprocesst &string_preprocess,
28222822
const class_hierarchyt &class_hierarchy)
28232823
{
2824-
static const std::unordered_set<std::string> methods_to_ignore
2825-
{
2826-
"nondetBoolean",
2827-
"nondetByte",
2828-
"nondetChar",
2829-
"nondetShort",
2830-
"nondetInt",
2831-
"nondetLong",
2832-
"nondetFloat",
2833-
"nondetDouble",
2834-
"nondetWithNull",
2835-
"nondetWithoutNull",
2836-
"notModelled",
2837-
"atomicBegin",
2838-
"atomicEnd",
2839-
"startThread",
2840-
"endThread",
2841-
"getCurrentThreadID"
2842-
};
2843-
28442824
if(std::regex_match(
28452825
id2string(class_symbol.name),
28462826
std::regex(".*org\\.cprover\\.CProver.*")) &&
2847-
methods_to_ignore.find(id2string(method.name))!=methods_to_ignore.end())
2827+
cprover_methods_to_ignore.count(id2string(method.name)))
28482828
{
2849-
// Ignore these methods, rely on default stubbing behaviour.
2829+
// Ignore these methods; fall back to the driver program's
2830+
// stubbing behaviour.
28502831
return;
28512832
}
28522833

jbmc/src/java_bytecode/java_bytecode_language.cpp

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