Skip to content

Commit e64adbe

Browse files
author
Daniel Kroening
committed
work on monitorenter and monitorexit
1 parent 833bbf3 commit e64adbe

10 files changed

+104
-56
lines changed
Binary file not shown.
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
public class monitorenter1
22
{
3-
public boolean doIt(boolean b)
3+
public int doIt(int what)
44
{
5-
boolean a;
5+
int some;
6+
67
synchronized(this) {
7-
a = !b;
8+
some=what;
89
}
9-
return a;
10+
11+
return some;
1012
}
1113

1214
public void test()
1315
{
14-
assert doIt(false);
16+
assert doIt(1)==1;
1517
}
1618
}

regression/cbmc-java/monitorenter1/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
CORE
22
virtual1.class
33
--function monitorenter1.test
44
^EXIT=0$

src/java_bytecode/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ SRC = java_bytecode_language.cpp java_bytecode_parse_tree.cpp \
33
java_bytecode_convert_class.cpp java_types.cpp java_entry_point.cpp \
44
java_bytecode_typecheck_code.cpp java_bytecode_typecheck_expr.cpp \
55
java_bytecode_typecheck_type.cpp java_bytecode_internal_additions.cpp \
6-
java_class_identifier.cpp java_bytecode_parser.cpp bytecode_info.cpp \
6+
java_root_class.cpp java_bytecode_parser.cpp bytecode_info.cpp \
77
java_class_loader.cpp jar_file.cpp java_object_factory.cpp \
88
java_bytecode_convert_method.cpp
99

src/java_bytecode/java_bytecode_convert_class.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Author: Daniel Kroening, [email protected]
1313
#endif
1414

1515
#include "java_bytecode_convert_class.h"
16-
#include "java_class_identifier.h"
16+
#include "java_root_class.h"
1717
#include "java_types.h"
1818
#include "java_bytecode_convert_method.h"
1919

@@ -127,7 +127,7 @@ void java_bytecode_convert_classt::convert(const classt &c)
127127

128128
// is this a root class?
129129
if(c.extends.empty())
130-
create_class_identifier(*class_symbol);
130+
java_root_class(*class_symbol);
131131
}
132132

133133
/*******************************************************************\
@@ -169,8 +169,8 @@ void java_bytecode_convert_classt::generate_class_stub(const irep_idt &class_nam
169169
}
170170
else
171171
{
172-
// create the class identifier
173-
create_class_identifier(*class_symbol);
172+
// create the class identifier etc
173+
java_root_class(*class_symbol);
174174
}
175175
}
176176

src/java_bytecode/java_bytecode_convert_method.cpp

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,11 +1401,32 @@ codet java_bytecode_convert_methodt::convert_instructions(
14011401
binary_predicate_exprt(op[0], "java_instanceof", arg0);
14021402
}
14031403
else if(statement=="monitorenter")
1404-
warning() << "critical section with lock object is ignored ("
1405-
<< i_it->source_location << ")" << eom;
1404+
{
1405+
// becomes a function call
1406+
code_typet type;
1407+
type.return_type()=void_typet();
1408+
type.parameters().resize(1);
1409+
type.parameters()[0].type()=reference_typet(void_typet());
1410+
code_function_callt call;
1411+
call.function()=symbol_exprt("java::monitorenter", type);
1412+
call.lhs().make_nil();
1413+
call.arguments().push_back(op[0]);
1414+
call.add_source_location()=i_it->source_location;
1415+
c=call;
1416+
}
14061417
else if(statement=="monitorexit")
1407-
// just skip, is always preceeded with "monitorenter"
14081418
{
1419+
// becomes a function call
1420+
code_typet type;
1421+
type.return_type()=void_typet();
1422+
type.parameters().resize(1);
1423+
type.parameters()[0].type()=reference_typet(void_typet());
1424+
code_function_callt call;
1425+
call.function()=symbol_exprt("java::monitorexit", type);
1426+
call.lhs().make_nil();
1427+
call.arguments().push_back(op[0]);
1428+
call.add_source_location()=i_it->source_location;
1429+
c=call;
14091430
}
14101431
else
14111432
{

src/java_bytecode/java_class_identifier.cpp

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/java_bytecode/java_object_factory.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Author: Daniel Kroening, [email protected]
1313
#include <util/std_expr.h>
1414
#include <util/i2string.h>
1515
#include <util/namespace.h>
16+
#include <util/expr_util.h>
1617

1718
#include "java_object_factory.h"
1819

@@ -115,6 +116,11 @@ void gen_nondet_init(
115116
code_assignt code(me, ci);
116117
init_code.copy_to_operands(code);
117118
}
119+
else if(name=="@lock")
120+
{
121+
code_assignt code(me, gen_zero(me.type()));
122+
init_code.copy_to_operands(code);
123+
}
118124
else
119125
{
120126
assert(!name.empty());

src/java_bytecode/java_root_class.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*******************************************************************\
2+
3+
Module:
4+
5+
Author: Daniel Kroening, [email protected]
6+
7+
\*******************************************************************/
8+
9+
#include <util/symbol.h>
10+
#include <util/std_types.h>
11+
12+
#include "java_types.h"
13+
#include "java_root_class.h"
14+
15+
/*******************************************************************
16+
17+
Function: java_root_class
18+
19+
Inputs:
20+
21+
Outputs:
22+
23+
Purpose:
24+
25+
\*******************************************************************/
26+
27+
void java_root_class(symbolt &class_symbol)
28+
{
29+
struct_typet &struct_type=to_struct_type(class_symbol.type);
30+
struct_typet::componentst &components=struct_type.components();
31+
32+
{
33+
// for monitorenter/monitorexit
34+
struct_typet::componentt component;
35+
component.set_name("@lock");
36+
component.set_pretty_name("@lock");
37+
component.type()=java_boolean_type();
38+
39+
// add at the beginning
40+
components.insert(components.begin(), component);
41+
}
42+
43+
{
44+
// the class identifier is used for stuff such as 'instanceof'
45+
struct_typet::componentt component;
46+
component.set_name("@class_identifier");
47+
component.set_pretty_name("@class_identifier");
48+
component.type()=string_typet();
49+
50+
// add at the beginning
51+
components.insert(components.begin(), component);
52+
}
53+
}
54+

src/java_bytecode/java_class_identifier.h renamed to src/java_bytecode/java_root_class.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ Author: Daniel Kroening, [email protected]
66
77
\*******************************************************************/
88

9-
#ifndef CPROVER_JAVA_CLASS_IDENTIFIER_H
10-
#define CPROVER_JAVA_CLASS_IDENTIFIER_H
9+
#ifndef CPROVER_JAVA_ROOT_CLASS_H
10+
#define CPROVER_JAVA_ROOT_CLASS_H
1111

1212
#include <util/std_expr.h>
1313

14-
void create_class_identifier(
14+
// adds expected members for a root class,
15+
// which is usually java.lang.Object
16+
17+
void java_root_class(
1518
class symbolt &class_symbol);
1619

17-
#endif /* CPROVER_JAVA_CLASS_IDENTIFIER_H */
20+
#endif /* CPROVER_JAVA_ROOT_CLASS_H */

0 commit comments

Comments
 (0)