Add Proxy support for JPF on Java 11 #356
Merged
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.
This patch adds Proxy support for JPF on Java 11 and some unit tests. It should fix the following two failing unit tests, which are parts of #274.
I have tested locally and found that it fixes these two test cases with no more regressions (7 failing tests left now).
Problem Analysis
In OpenJDK 11,
Proxy.newInstance()
involves too much code that JPF currently does not fully support; we need to add a model class forjava.lang.reflect.Proxy
and use JPF's way to implement a simpler one but with the same functionality.Basic Idea
According to doc of
getProxyClass()
, a Proxy is defined by its classloader and theList
of interfaces to implement (the order is important). But in fact, a Proxy's implementation is solely defined by theList
of interfaces it implements (which can be evident by the signature of JDK's proxy generation methodProxyGenerator.generateProxyClass(final String name, Class<?>[] interfaces, int accessFlags)
).We can use the
List
of interfaces to get a unique name of aProxy
class, then use JDK'sProxyGenerator.generateProxyClass
to generate the classfile of it (and cache it in theresolvedClasses
), and finally define the class.Discussions
In OpenJDK 8's implementation,
Proxy.newProxyInstance()
doesn't involve that much code which JPF cannot handle. All we need to do is to implement the native methodProxy.defineClass0()
.