Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Missing stackmap generation for woven code

In the last couple of days, I've been trying to read up on ASM, ClassWriter, ClassReader, Visitors (and Visitor pattern), etc.  And although I'm understanding more about how these things work, I'm still a little bit at a loss how to write a simple ClassReader and rewrite it with a proper stackmap.  I've seen that the ClassReader has a parameter to ignore stackmaps, and ClassWriter has one to write the stackmap, but now I just have to figure out the missing glue logic - there doesn't seem to be an obvious way to read and entire class and rewrite it.  I seem to have to identify each part of the class individually (ie: methods, fields, constants, etc).  So I'm sure I'm missing something.  I hoped it would be a lot easier to simply say something like : ClassWriter.write ( ClassReader.readClass( MyClass.class) ), but it doesn't seem to be so straightforward.

As for the library in question, it's an ancient persistence library called Kodo.  It uses (is backed?) by OpenJPA 0.9.5-incubating - just to give an idea how old this product is.  For those who haven't heard of Kodo before (I had never heard of it before starting on this project), it was a commercial implementation of JDO before JPA was even released.  Produced by a company called Solarmetrics, which was then bought by BEA, and then acquired by Oracle.  The product has been dead for 10 years already.  

As part of the JDO build process, there is a class enhancer which updates all the persistent classes, adding FK fields, mappings between classes, etc.  This build process is in the form of an ant task.  I have since managed to wrap the ant process in an antrun plugin to make it "maven-ish", but haven't been able to properly debug the process to fully understand what it is doing.  I have dug out what I think is the class though : org.apache.openjpa.enhance.PCEnhancer.  This class uses Serp (also produced by BEA, I think) as the bytecode manipualtion library.  Current version I'm using is Serp 1.13.  I can't tell if newer Serp generates the stackmap or not, but I did determine that newer versions of OpenJPA (ie: v2+) introduced ASM to update the stackmap after Serp (kind of like what I'm looking to do).  I'm trying to copy that magic now, but it's more involved that I would have liked (includes reverse engineering the ant plugin to rebuild it as a maven plugin, etc).

If anyone can assist me, I'd be happy to learn more about bytecode manipulation, etc.  I've been a longtime user of AJ, but I've never really looked at how it does its magic.

Thanks,

Eric

On Sun, Oct 8, 2017 at 8:26 AM, Alexander Kriegisch <alexander@xxxxxxxxxxxxxx> wrote:
I do hope that someone can help you with that, Eric. But just in case nobody can, I think a software developer should always strive to improve the status quo and always have a plan B.

Having said that, I think that a JDO lib from 2004 sounds like a good reason to either upgrade it or get rid of it. The former is probably not an option because I assume you would have done so already if it was that simple. But maybe it is an option. I also think your odds would be much better if you named the library and its version here instead of keeping it secret. Maybe someone has migrated it before and can help you with a hint on how to do so with as little pain as possible.

Other ways to get rid of the library would be to patch it if you have access to the source code. Or maybe the lib itself uses something like asm or BCEL under the hood and you can upgrade the dependency, maybe getting more standardised class files as a result. Or - my favourite idea because it sounds fun to implement - you could consider to reimplement the JDO functionalities by yourself via **AspectJ**! You would have ITD and alll the other nice tools at your disposal. Hell, if I was not so busy, I would even like to give it a try myself. :-)

Good luck
-- 
Alexander Kriegisch


Am 07.10.2017 um 19:49 schrieb Eric B <ebenzacar@xxxxxxxxx>:

While I don't disagree with your answer, I dont have the first clue how to fix a legacy jdo library (circa 2004) that performs byte enhancement and does not write the stackmap.    Are there libraries to manipulate/generate a stackmap? 

Is there anything else can I do in the meantime to unblock the situation? 

Thanks
Eric


On Oct 7, 2017 12:11 AM, "Alexander Kriegisch" <alexander@xxxxxxxxxxxxxx> wrote:
I know that this is not the answer you are looking for, but my suggestion is to heal the illness instead of taking pills against its symptoms. Go fix your problem in the other module which requires noverify in the first place. Generating broken bytecode does not sound like a wise approach to me.

--
Alexander Kriegisch


> Am 07.10.2017 um 02:55 schrieb Eric B <ebenzacar@xxxxxxxxx>:
>
> I'm running into a problem with AspectJ 1.8.10, and not sure how to resolve this.
>
> I have a multi-module maven build.  One of my modules requires running an ant task (using the antrun-maven-plugin) with the jvm -noverify flag.  Consequently, I run the entire maven build using the -noverify flag.
>
> However, my last module in my build is an AspectJ module.  When I try to compile it using the aspectj-maven-plugin, I get the following error thrown:
>
> [ERROR] Failed to execute goal org.codehaus.mojo:aspectj-maven-plugin:1.10:compile (default) on project adams-aspects: AJC compiler errors:
> [ERROR] abort ABORT -- (BCException) Unable to find Asm for stackmap generation (Looking for 'aj.org.objectweb.asm.ClassReader'). Stackmap generation for woven code is required to avoid verify errors on a Java 1.7 or higher runtime
> [ERROR] when weaving type webapp.tiles.AthleteBasedForm
> [ERROR] when weaving classes
> [ERROR] when weaving
> [ERROR] when batch building BuildConfig[null] #Files=8 AopXmls=#0
> [ERROR]
>
>
> So I'm a bit in a bind.  I can't figure out any way to reconcile both requirements - that module1 needs to run a plugin with the -noverify parameter, and the aspectj plugin that needs to run it without.
>
> Is there anyway I can disable the need for the stackmap generation to exist in AJ 1.8.10?  I've looked for parameters I can pass to ajc but can't find any.
>
> Thanks,
>
> Eric
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> To change your delivery options, retrieve your password, or unsubscribe from this list, visit
> https://dev.eclipse.org/mailman/listinfo/aspectj-users

_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-users

_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-users

_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-users


Back to the top