Skip to content

Commit ba7e06f

Browse files
author
Daniel Kroening
committed
precompute the category of the classpath entry
1 parent 5dbd48c commit ba7e06f

File tree

2 files changed

+57
-31
lines changed

2 files changed

+57
-31
lines changed

jbmc/src/java_bytecode/java_class_loader.cpp

Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,15 @@ java_class_loadert::parse_tree_with_overlayst &java_class_loadert::operator()(
7070

7171
void java_class_loadert::add_classpath_entry(const std::string &path)
7272
{
73-
classpath_entries.push_back(path);
73+
if(has_suffix(path, ".jar"))
74+
{
75+
classpath_entries.push_back(classpath_entryt(classpath_entryt::JAR, path));
76+
}
77+
else
78+
{
79+
classpath_entries.push_back(
80+
classpath_entryt(classpath_entryt::DIRECTORY, path));
81+
}
7482
}
7583

7684
optionalt<java_bytecode_parse_treet> java_class_loadert::get_class_from_jar(
@@ -131,40 +139,44 @@ java_class_loadert::get_parse_tree(
131139
// Rummage through the class path
132140
for(const auto &cp_entry : classpath_entries)
133141
{
134-
if(has_suffix(cp_entry, ".jar"))
135-
{
136-
jar_index_optcreft index = read_jar_file(cp_entry);
137-
if(!index)
138-
continue;
139-
optionalt<java_bytecode_parse_treet> parse_tree =
140-
get_class_from_jar(class_name, cp_entry, *index);
141-
if(parse_tree)
142-
parse_trees.emplace_back(std::move(*parse_tree));
143-
}
144-
else
142+
switch(cp_entry.kind)
145143
{
146-
// Look in the given directory
147-
const std::string class_file = class_name_to_file(class_name);
148-
const std::string full_path =
149-
#ifdef _WIN32
150-
cp_entry + '\\' + class_file;
151-
#else
152-
cp_entry + '/' + class_file;
153-
#endif
154-
155-
if(!class_loader_limit.load_class_file(class_file))
156-
continue;
157-
158-
if(std::ifstream(full_path))
144+
case classpath_entryt::JAR:
159145
{
160-
debug()
161-
<< "Getting class `" << class_name << "' from file " << full_path
162-
<< eom;
146+
jar_index_optcreft index = read_jar_file(cp_entry.path);
147+
if(!index)
148+
continue;
163149
optionalt<java_bytecode_parse_treet> parse_tree =
164-
java_bytecode_parse(full_path, get_message_handler());
150+
get_class_from_jar(class_name, cp_entry.path, *index);
165151
if(parse_tree)
166152
parse_trees.emplace_back(std::move(*parse_tree));
167153
}
154+
break;
155+
156+
case classpath_entryt::DIRECTORY:
157+
{
158+
// Look in the given directory
159+
const std::string class_file = class_name_to_file(class_name);
160+
const std::string full_path =
161+
#ifdef _WIN32
162+
cp_entry.path + '\\' + class_file;
163+
#else
164+
cp_entry.path + '/' + class_file;
165+
#endif
166+
167+
if(!class_loader_limit.load_class_file(class_file))
168+
continue;
169+
170+
if(std::ifstream(full_path))
171+
{
172+
debug() << "Getting class `" << class_name << "' from file "
173+
<< full_path << eom;
174+
optionalt<java_bytecode_parse_treet> parse_tree =
175+
java_bytecode_parse(full_path, get_message_handler());
176+
if(parse_tree)
177+
parse_trees.emplace_back(std::move(*parse_tree));
178+
}
179+
}
168180
}
169181
}
170182

@@ -226,7 +238,8 @@ void java_class_loadert::load_entire_jar(
226238
if(!jar_index)
227239
return;
228240

229-
classpath_entries.push_front(jar_path);
241+
classpath_entries.push_front(
242+
classpath_entryt(classpath_entryt::JAR, jar_path));
230243

231244
for(const auto &e : jar_index->get())
232245
operator()(e.first);

jbmc/src/java_bytecode/java_class_loader.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,21 @@ class java_class_loadert:public messaget
119119
/// information.
120120
std::string java_cp_include_files;
121121

122+
/// An entry in the classpath
123+
struct classpath_entryt
124+
{
125+
using kindt = enum { JAR, DIRECTORY };
126+
kindt kind;
127+
std::string path;
128+
129+
classpath_entryt(kindt _kind, const std::string &_path)
130+
: kind(_kind), path(_path)
131+
{
132+
}
133+
};
134+
122135
/// List of entries in the classpath
123-
std::list<std::string> classpath_entries;
136+
std::list<classpath_entryt> classpath_entries;
124137

125138
/// Classes to be explicitly loaded
126139
std::vector<irep_idt> java_load_classes;

0 commit comments

Comments
 (0)