Skip to content

Commit d1b8314

Browse files
author
Owen Jones
committed
Document, overlay classes, overlay methods and ignored methods
Future improvements: - move this documentation to a better place - add tests for ignored methods
1 parent a6108ec commit d1b8314

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

jbmc/src/java_bytecode/java_bytecode_convert_class.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,43 @@ class java_bytecode_convert_classt:public messaget
118118
// see definition below for more info
119119
static void add_array_types(symbol_tablet &symbol_table);
120120

121+
/// Check if a method is an overlay method by searching for
122+
/// `ID_overlay_method` in its list of annotations.
123+
///
124+
/// An overlay method is a method with the annotation
125+
/// \@OverlayMethodImplementation. They should only appear in
126+
/// [overlay classes](\ref java_class_loader.cpp::is_overlay_class). They
127+
/// will be loaded by JBMC instead of the corresponding method in the
128+
/// underlying class. It is an error if there is no corresponding
129+
/// method in the underlying class. It is an error if a method in the overlay
130+
/// class matches a method in the underlying class and it isn't marked as
131+
/// an overlay method or an
132+
/// [ignored method](\ref java_bytecode_convert_classt::is_ignored_method).
133+
///
134+
/// \param method: a `methodt` object from a java bytecode parse tree
135+
/// \return true if the method is an overlay method, else false
121136
static bool is_overlay_method(const methodt &method)
122137
{
123138
return method.has_annotation(ID_overlay_method);
124139
}
125140

141+
/// Check if a method is an ignored method by searching for
142+
/// `ID_ignored_method` in its list of annotations.
143+
///
144+
/// An ignored method is a method with the annotation
145+
/// \@IgnoredMethodImplementation. They will be ignored by JBMC. They are
146+
/// intended for use in
147+
/// [overlay classes](\ref java_class_loader.cpp::is_overlay_class), in
148+
/// particular for methods which must exist in the overlay class so that
149+
/// it will compile, e.g. default constructors, but which we do not want
150+
/// to overlay the corresponding method in the
151+
/// underlying class. It is an error if a method in the overlay class
152+
/// matches a method in the underlying class and it isn't marked as
153+
/// an [overlay method](\ref java_bytecode_convert_classt::is_overlay_method)
154+
/// or an ignored method.
155+
///
156+
/// \param method: a `methodt` object from a java bytecode parse tree
157+
/// \return true if the method is an overlay method, else false
126158
static bool is_ignored_method(const methodt &method)
127159
{
128160
return method.has_annotation(ID_ignored_method);

jbmc/src/java_bytecode/java_class_loader.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,22 @@ java_class_loadert::parse_tree_with_overlayst &java_class_loadert::operator()(
6969
}
7070

7171
/// Check if class is an overlay class by searching for `ID_overlay_class` in
72-
/// its list of annotations. TODO(nathan) give a short explanation about what
73-
/// overlay classes are.
74-
/// \param c: a `classt` object from a java byte code parse tree
72+
/// its list of annotations.
73+
///
74+
/// An overlay class is a class with the annotation
75+
/// \@OverlayClassImplementation. They serve the following purpose. When the JVM
76+
/// searches the classpath for a particular class, it uses the first one
77+
/// that matches, and ignores any later matching ones. JBMC, however,
78+
/// will take account of other matching ones which are overlay classes. The
79+
/// overlay classes can change the methods of the first matching class in the
80+
/// following ways: adding a field (by having a new field), adding a method
81+
/// (by having a new method) or
82+
/// [changing the definition of a method](\ref java_bytecode_convert_classt::is_overlay_method).
83+
/// When there is a method which is required for the overlay class to compile
84+
/// but which should not be an overlay method then it should be marked as an
85+
/// [ignored method](\ref java_bytecode_convert_classt::is_ignored_method).
86+
///
87+
/// \param c: a `classt` object from a java bytecode parse tree
7588
/// \return true if parsed class is an overlay class, else false
7689
static bool is_overlay_class(const java_bytecode_parse_treet::classt &c)
7790
{

0 commit comments

Comments
 (0)