Skip to content
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

WFLY-10025 Use new org.jboss.modules.ClassTransformer interface in addition to j.l.i.ClassFileTransformer #11307

Merged

Conversation

scottmarlow
Copy link
Contributor

https://issues.jboss.org/browse/WFLY-10025
Note that we should remove the j.l.i.ClassFileTransformer interface after https://issues.jboss.org/browse/WFCORE-3685 changes DelegatingClassFileTransformer to use org.jboss.modules.ClassTransformer.

@scottmarlow
Copy link
Contributor Author

retest this please.

@scottmarlow
Copy link
Contributor Author

@dmlloyd could you please review? Thanks!

We had previously missed that we are supposed to return null, if the JPA persistence provider doesn't enhance the entity class. I made that change for the two #transform methods (byte[] + ByteBuffer), perhaps that will help performance as well.

@@ -752,4 +754,8 @@
DeploymentUnitProcessingException differentSearchModuleDependencies(String deployment, String searchModuleName1, String searchModuleName2);

// id = 72, value = "Could not obtain TransactionListenerRegistry from transaction manager")

@Message(id = 73, value = "Invalid class format for deployment class %s.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A message like "Transformation of class %s failed" is probably more appropriate. The details will be included in the nested exception.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

easy change, thanks

@@ -44,13 +46,47 @@ public JPADelegatingClassFileTransformer(PersistenceUnitMetadata pu) {
public byte[] transform(ClassLoader classLoader, String className, Class<?> aClass, ProtectionDomain protectionDomain, byte[] originalBuffer) throws
IllegalClassFormatException {
byte[] transformedBuffer = originalBuffer;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you've introduced the new method, it's probably better to only have the logic in one place. This method can delegate to that one simply by calling transform(classLoader, className, protectionDomain, ByteBuffer.wrap(originalBuffer)). You can factor out a private utility method to 'convert' the ByteBuffer to an array which can be used in both methods.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed as suggested, will push in a minute.

Is it okay that transform(ClassLoader, String, Class, ProtectionDomain, byte[]), will now throw IlegalStateException instead of IllegalClassFormatException?

Will org.jboss.modules.ClassTransformer need to deal with redefining already loaded classes? Currently, j.l.i.ClassFileTransformer#transform is passed "Class<?> classBeingRedefined" for redefinition, which I just pass onto the JPA persistence providers (which they probably ignore).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we do not support redefinition. Changing the exception is probably fine in this case (we're the ones who catch it after all).

boolean transformed = false;
byte[] transformedBuffer = bytes;
for (javax.persistence.spi.ClassTransformer transformer : persistenceUnitMetadata.getTransformers()) {
byte[] result = new byte[0];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assignment and allocation is pointless. If the transform call fails, an exception will be thrown; otherwise it will definitely assign result.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed.

@scottmarlow scottmarlow force-pushed the WFLY-10025_ClassTransformer_use_modules branch from 9611448 to 32f2294 Compare June 1, 2018 18:53
public ByteBuffer transform(ClassLoader classLoader, String className, ProtectionDomain protectionDomain, ByteBuffer classBytes)
throws IllegalArgumentException {
final byte[] bytes = getBytes(classBytes);
final Class<?> aClass = null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This variable is useless and can be inlined.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

final byte[] bytes = getBytes(classBytes);
final Class<?> aClass = null;
boolean transformed = false;
byte[] transformedBuffer = bytes;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having both bytes and transformedBuffer is redundant. You can just use bytes directly and drop transformedBuffer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true, will drop bytes, as I think we need transformedBuffer.

if (result != null) {
transformedBuffer = result;
transformed = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This boolean is unnecessary. The check for result is sufficient; see below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy Monday :)


return transformed ? ByteBuffer.wrap(transformedBuffer) : null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return result != null ? ByteBuffer.wrap(result) : null;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there are multiple calls to Transformer#transform and some return null but some return non-null, we need the boolean, to note that we saw at least one transformation, so we can return non-null result.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right, I missed the loop. Happy Monday

throws IllegalArgumentException {
final byte[] bytes = getBytes(classBytes);
final Class<?> aClass = null;
boolean transformed = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See line 66 comment.

@@ -751,5 +753,9 @@
@Message(id = 71, value = "Deployment '%s' specified more than one Hibernate Search module name ('%s','%s')")
DeploymentUnitProcessingException differentSearchModuleDependencies(String deployment, String searchModuleName1, String searchModuleName2);

// id = 72, value = "Could not obtain TransactionListenerRegistry from transaction manager")
// id = 72, value = "Could not obtain TransactionListenerRegistry from transaction manager.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fix seems unnecessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed the unneeded fix.

@scottmarlow scottmarlow force-pushed the WFLY-10025_ClassTransformer_use_modules branch from 32f2294 to b1e0aae Compare June 4, 2018 14:12
@scottmarlow scottmarlow force-pushed the WFLY-10025_ClassTransformer_use_modules branch from b1e0aae to c7b60a2 Compare June 6, 2018 17:05
@kabir kabir merged commit 13ce920 into wildfly:master Jun 7, 2018
@scottmarlow scottmarlow deleted the WFLY-10025_ClassTransformer_use_modules branch June 7, 2018 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants