Java Magazine, July/August 2018
ORACLE COM JAVAMAGAZINE JULY AUGUST 2018 45 libraries For example in Java bytecode a synchronized method is represented by a flag called ACC_ SYNCHRONIZED on the method so I need to remove that flag from any method that I visit However to be really sure that all the synchronization is gone I also need to know that the block form of synchronization is represented slightly differently If I have some code like this Object o synchronized o It will be turned into a sequence of bytecodes that looks a bit like this Sequence that leaves o on top of the stack monitorenter Reload o monitorexit Both monitorenter and monitorexit bytecodes consume the top of the stack and lock or unlock the object that they find there So if these opcodes were replaced with a basic pop this would strip the synchronization out of any method body that is encountered The resulting code is represented by the following two simple classes an UnsynchronizingClassVisitor and an UnsynchronizingMethodVisitor both of which extend ASM framework classes public class UnsynchronizingClassVisitor extends ClassVisitor public UnsynchronizingClassVisitor int api ClassVisitor cv
You must have JavaScript enabled to view digital editions.