-
Notifications
You must be signed in to change notification settings - Fork 273
Add brief documentation of overlay classes #2947
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
owen-mc-diffblue
merged 4 commits into
diffblue:develop
from
owen-mc-diffblue:doc/overlay-classes
Sep 14, 2018
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file added
BIN
+186 Bytes
jbmc/regression/jbmc/overlay-class/annotations/org/cprover/IgnoredMethodImplementation.class
Binary file not shown.
8 changes: 8 additions & 0 deletions
8
jbmc/regression/jbmc/overlay-class/annotations/org/cprover/IgnoredMethodImplementation.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.cprover; | ||
|
||
/** | ||
* Ignored methods are documented above | ||
* `java_bytecode_convert_classt::is_ignored_method`. | ||
*/ | ||
public @interface IgnoredMethodImplementation { | ||
} |
4 changes: 4 additions & 0 deletions
4
jbmc/regression/jbmc/overlay-class/annotations/org/cprover/OverlayClassImplementation.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
package org.cprover; | ||
|
||
/** | ||
* Overlay classes are documented above `is_overlay_class()` in | ||
* jbmc/src/java_bytecode/java_class_loader.cpp. | ||
*/ | ||
public @interface OverlayClassImplementation { | ||
} |
4 changes: 4 additions & 0 deletions
4
jbmc/regression/jbmc/overlay-class/annotations/org/cprover/OverlayMethodImplementation.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
package org.cprover; | ||
|
||
/** | ||
* Overlay methods are documented above | ||
* `java_bytecode_convert_classt::is_overlay_method`. | ||
*/ | ||
public @interface OverlayMethodImplementation { | ||
} |
Binary file not shown.
12 changes: 12 additions & 0 deletions
12
jbmc/regression/jbmc/overlay-class/ignored-method/Test.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import org.cprover.OverlayClassImplementation; | ||
import org.cprover.IgnoredMethodImplementation; | ||
|
||
@OverlayClassImplementation | ||
public class Test | ||
{ | ||
@IgnoredMethodImplementation | ||
public static void main(String[] args) | ||
{ | ||
assert(true); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
CORE | ||
Test.class | ||
--classpath `../../../../scripts/format_classpath.sh . annotations . ignored-method` --verbosity 10 | ||
^Ignoring method: 'java::Test\.main:\(\[Ljava/lang/String;\)V'$ | ||
^VERIFICATION FAILED$ | ||
^EXIT=10$ | ||
^SIGNAL=0$ | ||
-- | ||
^Skipping class Test marked with OverlayClassImplementation but found before original definition$ | ||
^Adding symbol from overlay class: method 'java::Test\.main:\(\[Ljava/lang/String;\)V'$ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,11 +118,44 @@ class java_bytecode_convert_classt:public messaget | |
// see definition below for more info | ||
static void add_array_types(symbol_tablet &symbol_table); | ||
|
||
/// Check if a method is an overlay method by searching for | ||
/// `ID_overlay_method` in its list of annotations. | ||
/// | ||
/// An overlay method is a method with the annotation | ||
/// \@OverlayMethodImplementation. They should only appear in | ||
/// [overlay classes](\ref java_class_loader.cpp::is_overlay_class). They | ||
/// will be loaded by JBMC instead of the method with the same signature | ||
/// in the underlying class. It is an error if there is no method with the | ||
/// same signature in the underlying class. It is an error if a method in | ||
/// an overlay class has the same signature as a method in the underlying | ||
/// class and it isn't marked as an overlay method or an | ||
/// [ignored method](\ref java_bytecode_convert_classt::is_ignored_method). | ||
/// | ||
/// \param method: a `methodt` object from a java bytecode parse tree | ||
/// \return true if the method is an overlay method, else false | ||
static bool is_overlay_method(const methodt &method) | ||
{ | ||
return method.has_annotation(ID_overlay_method); | ||
} | ||
|
||
/// Check if a method is an ignored method by searching for | ||
/// `ID_ignored_method` in its list of annotations. | ||
/// | ||
/// An ignored method is a method with the annotation | ||
/// \@IgnoredMethodImplementation. They will be ignored by JBMC. They are | ||
/// intended for use in | ||
/// [overlay classes](\ref java_class_loader.cpp::is_overlay_class), in | ||
/// particular for methods which must exist in the overlay class so that | ||
/// it will compile, e.g. default constructors, but which we do not want | ||
/// to overlay the corresponding method in the | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🐝 |
||
/// underlying class. It is an error if a method in | ||
/// an overlay class has the same signature as a method in the underlying | ||
/// class and it isn't marked as an | ||
/// [overlay method](\ref java_bytecode_convert_classt::is_overlay_method) | ||
/// or an ignored method. | ||
/// | ||
/// \param method: a `methodt` object from a java bytecode parse tree | ||
/// \return true if the method is an ignored method, else false | ||
static bool is_ignored_method(const methodt &method) | ||
{ | ||
return method.has_annotation(ID_ignored_method); | ||
|
@@ -468,11 +501,16 @@ void java_bytecode_convert_classt::convert( | |
{ | ||
for(const methodt &method : overlay_class.get().methods) | ||
{ | ||
if(is_ignored_method(method)) | ||
continue; | ||
const irep_idt method_identifier = | ||
qualified_classname + "." + id2string(method.name) | ||
+ ":" + method.descriptor; | ||
if(is_ignored_method(method)) | ||
{ | ||
debug() | ||
<< "Ignoring method: '" << method_identifier << "'" | ||
<< eom; | ||
continue; | ||
} | ||
if(method_bytecode.contains_method(method_identifier)) | ||
{ | ||
// This method has already been discovered and added to method_bytecode | ||
|
@@ -511,11 +549,16 @@ void java_bytecode_convert_classt::convert( | |
} | ||
for(const methodt &method : c.methods) | ||
{ | ||
if(is_ignored_method(method)) | ||
continue; | ||
const irep_idt method_identifier= | ||
qualified_classname + "." + id2string(method.name) | ||
+ ":" + method.descriptor; | ||
if(is_ignored_method(method)) | ||
{ | ||
debug() | ||
<< "Ignoring method: '" << method_identifier << "'" | ||
<< eom; | ||
continue; | ||
} | ||
if(method_bytecode.contains_method(method_identifier)) | ||
{ | ||
// This method has already been discovered while parsing an overlay | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Thanks for explaining this, I wasn't sure if
@OverlayClassImplementation
automatically turned all methods into overlay methods, of if within an overlay class methods could still be declared to be overlay methods or not.