Skip to content

Commit 772b603

Browse files
author
Thomas Kiley
authored
Merge pull request #1982 from NathanJPhillips/bugfix/load-object-once
Fixes related to #1816
2 parents 05a7b4a + 81ac259 commit 772b603

File tree

10 files changed

+90
-12
lines changed

10 files changed

+90
-12
lines changed
228 Bytes
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
public class Test {
2+
public void main() {}
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE symex-driven-lazy-loading-expected-failure
2+
Test.class
3+
--classpath ./NotHere.jar
4+
^EXIT=6$
5+
^SIGNAL=0$
6+
^the program has no entry point$
7+
^failed to load class `Test'$
8+
--
9+
--
10+
symex-driven lazy loading should emit "the program has no entry point" but currently doesn't
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE symex-driven-lazy-loading-expected-failure
2+
Test.class
3+
--classpath ./NotHere
4+
^EXIT=6$
5+
^SIGNAL=0$
6+
^the program has no entry point$
7+
^failed to load class `Test'$
8+
--
9+
--
10+
symex-driven lazy loading should emit "the program has no entry point" but currently doesn't
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package java.lang;
2+
3+
public class Object {
4+
public final Class<?> getClass() {
5+
return null;
6+
}
7+
8+
public int hashCode() { return 0; }
9+
10+
public boolean equals(Object obj) { return (this == obj); }
11+
12+
protected Object clone() throws CloneNotSupportedException {
13+
throw new CloneNotSupportedException();
14+
}
15+
16+
public String toString() { return "object"; }
17+
18+
public final void notify() {}
19+
20+
public final void notifyAll() {}
21+
22+
public final void wait(long timeout) throws InterruptedException {
23+
throw new InterruptedException();
24+
}
25+
26+
public final void wait(long timeout, int nanos) throws InterruptedException {
27+
wait(timeout);
28+
}
29+
30+
public final void wait() throws InterruptedException { wait(0); }
31+
32+
protected void finalize() throws Throwable { }
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE symex-driven-lazy-loading-expected-failure
2+
java/lang/Object.class
3+
4+
^EXIT=6$
5+
^SIGNAL=0$
6+
^the program has no entry point$
7+
--
8+
^failed to add class symbol java::java\.lang\.Object$
9+
--
10+
symex-driven lazy loading should emit "the program has no entry point" but currently doesn't

src/java_bytecode/java_bytecode_convert_class.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,12 @@ void java_bytecode_convert_classt::operator()(
185185
PRECONDITION(!parse_trees.empty());
186186
const irep_idt &class_name = parse_trees.front().parsed_class.name;
187187

188+
if(symbol_table.has_symbol("java::" + id2string(class_name)))
189+
{
190+
debug() << "Skip class " << class_name << " (already loaded)" << eom;
191+
return;
192+
}
193+
188194
// Add array types to the symbol table
189195
add_array_types(symbol_table);
190196

src/java_bytecode/java_class_loader.cpp

+17-12
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ java_class_loadert::parse_tree_with_overlayst &java_class_loadert::operator()(
8181
optionalt<java_bytecode_parse_treet> java_class_loadert::get_class_from_jar(
8282
const irep_idt &class_name,
8383
const std::string &jar_file,
84+
const jar_indext &jar_index,
8485
java_class_loader_limitt &class_loader_limit)
8586
{
86-
jar_indext &jar_index = jars_by_path.at(jar_file);
8787
auto jar_index_it = jar_index.find(class_name);
8888
if(jar_index_it == jar_index.end())
8989
return {};
@@ -112,9 +112,11 @@ java_class_loadert::get_parse_tree(
112112
// First add all given JAR files
113113
for(const auto &jar_file : jar_files)
114114
{
115-
read_jar_file(class_loader_limit, jar_file);
115+
jar_index_optcreft index = read_jar_file(class_loader_limit, jar_file);
116+
if(!index)
117+
continue;
116118
optionalt<java_bytecode_parse_treet> parse_tree =
117-
get_class_from_jar(class_name, jar_file, class_loader_limit);
119+
get_class_from_jar(class_name, jar_file, *index, class_loader_limit);
118120
if(parse_tree)
119121
parse_trees.push_back(*parse_tree);
120122
}
@@ -130,23 +132,26 @@ java_class_loadert::get_parse_tree(
130132

131133
// This does not read from the jar file but from the jar_filet object we
132134
// just created
133-
read_jar_file(class_loader_limit, core_models);
134-
135-
optionalt<java_bytecode_parse_treet> parse_tree =
136-
get_class_from_jar(class_name, core_models, class_loader_limit);
137-
if(parse_tree)
138-
parse_trees.push_back(*parse_tree);
135+
jar_index_optcreft index = read_jar_file(class_loader_limit, core_models);
136+
if(index)
137+
{
138+
optionalt<java_bytecode_parse_treet> parse_tree =
139+
get_class_from_jar(class_name, core_models, *index, class_loader_limit);
140+
if(parse_tree)
141+
parse_trees.push_back(*parse_tree);
142+
}
139143
}
140144

141145
// Then add everything on the class path
142146
for(const auto &cp_entry : config.java.classpath)
143147
{
144148
if(has_suffix(cp_entry, ".jar"))
145149
{
146-
read_jar_file(class_loader_limit, cp_entry);
147-
150+
jar_index_optcreft index = read_jar_file(class_loader_limit, cp_entry);
151+
if(!index)
152+
continue;
148153
optionalt<java_bytecode_parse_treet> parse_tree =
149-
get_class_from_jar(class_name, cp_entry, class_loader_limit);
154+
get_class_from_jar(class_name, cp_entry, *index, class_loader_limit);
150155
if(parse_tree)
151156
parse_trees.push_back(*parse_tree);
152157
}

src/java_bytecode/java_class_loader.h

+1
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ class java_class_loadert:public messaget
160160
optionalt<java_bytecode_parse_treet> get_class_from_jar(
161161
const irep_idt &class_name,
162162
const std::string &jar_file,
163+
const jar_indext &jar_index,
163164
java_class_loader_limitt &class_loader_limit);
164165
};
165166

0 commit comments

Comments
 (0)