1 2 3 4 Previous Next 51 Replies Latest reply on Mar 17, 2009 6:10 AM by kabirkhan Go to original post
      • 15. Re: MutableClassInfo?
        stalep

        we also need to add support for adding classes to the classpool with a byte[] and the posibility to get a byte[] representation of a MutableClassInfo instance.

        adding classes to the classpool could be solved with a utilclass or via some sort of ClassPool interface, the way this is done in javassist:

        ByteArrayClassPath cp = new ByteArrayClassPath(className, classfileBuffer);
        pool.insertClassPath(cp);


        byte[] representation of the class will be added to MutableClassInfo interface:
        public interface MutableClassInfo extends ClassInfo
        {
         ...
         /**
         * Converts the class to a Class file.
         * After this method is called, no modifications to the class is allowed.
         *
         * @return
         */
         byte[] toByteCode();
        }


        • 16. Re: MutableClassInfo?
          alesj

          Why do all these MutableX take MutableY as parameters?
          e.g.

          public interface MutableMethodInfo extends MethodInfo
          {
           void setReturnType(MutableClassInfo returnType);
          

          Why would you force a MutableY as a return type?

          "stale.pedersen@jboss.org" wrote:

          The usage of the Class parameter needs to be removed, internal methods using it will just use the CtClass object.

          How does this effect the (weak type) cache?

          "stale.pedersen@jboss.org" wrote:

          The question is the method getType(), can we just remove it altogether? -its been marked as deprecated.

          You can, but then you have to fix all MC code. :-)
          Unfortunately we have quite a few places where we use it.
          MDR, Kernel, ...

          "stale.pedersen@jboss.org" wrote:

          Is there a reason why the JMI constructor is public? if not it should be set to package protected.

          Add a TODO, so we fix this with the future minor release,
          where we can break the api. :-)

          "stale.pedersen@jboss.org" wrote:

          We need functionality to get the method signature from a method. This could be implemented in a utilclass, but i would rather see it added to the MethodInfo interface.

          Signature API is part of MDR sub-project.

          "stale.pedersen@jboss.org" wrote:

          We might also need a method like ClassInfo.getClassLoader(), but i guess Kabir/Adrian know more about that.

          I guess if you have a permission check you're fine?

          "stale.pedersen@jboss.org" wrote:

          Javassist have a lot of functionality to create new methods/constructors/etc that i dont think we need to support directly in MCI, but rather create some util classes to do that. Im thinking of classes/methods like: CtNewMethod.copy/abstractMethod/getter/setter/delegator/etc.

          This can come in when ever you have the time, it's a feature not a task.

          • 17. Re: MutableClassInfo?
            stalep

             

            "alesj" wrote:
            Why do all these MutableX take MutableY as parameters?
            e.g.
            public interface MutableMethodInfo extends MethodInfo
            {
             void setReturnType(MutableClassInfo returnType);
            

            Why would you force a MutableY as a return type?

            mostly because then we are sure that we will get a CtClass instance within the parameter. there is also a String parameter if you would prefer to use that. it makes little sense to have a ClassInfo param since then we would just do the same work internally as with the String param.

            "alesj" wrote:

            "stale.pedersen@jboss.org" wrote:

            The usage of the Class parameter needs to be removed, internal methods using it will just use the CtClass object.

            How does this effect the (weak type) cache?

            "stale.pedersen@jboss.org" wrote:

            The question is the method getType(), can we just remove it altogether? -its been marked as deprecated.

            You can, but then you have to fix all MC code. :-)
            Unfortunately we have quite a few places where we use it.
            MDR, Kernel, ...

            hm, ok. after talking to Kabir we could add logic to the getType() method that if the class isnt loaded, we could try to weave it on demand.

            "alesj" wrote:

            "stale.pedersen@jboss.org" wrote:

            We need functionality to get the method signature from a method. This could be implemented in a utilclass, but i would rather see it added to the MethodInfo interface.

            Signature API is part of MDR sub-project.

            its another signature, this is something similar to CtBehaviour.getSignature(). imo it belongs in MMI.

            is it ok if i start commit to jboss-reflect? i can exclude the new files in the pom if needed.


            • 18. Re: MutableClassInfo?
              alesj

               

              "stale.pedersen@jboss.org" wrote:

              mostly because then we are sure that we will get a CtClass instance within the parameter. there is also a String parameter if you would prefer to use that. it makes little sense to have a ClassInfo param since then we would just do the same work internally as with the String param.

              I still don't see why it has to be a MutableCI.

              "stale.pedersen@jboss.org" wrote:

              its another signature, this is something similar to CtBehaviour.getSignature(). imo it belongs in MMI.

              Why do you need it?
              How it should look like?

              Why isn't the one in MDR good enough?
              Afaik AOP already uses MDR.

              btw: there is a Javassist kind of Signature:
              - http://anonsvn.jboss.org/repos/jbossas/projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/spi/signature/javassist/
              I already use it in annotation scanning.

              "stale.pedersen@jboss.org" wrote:

              is it ok if i start commit to jboss-reflect? i can exclude the new files in the pom if needed.

              I don't wanna sound pita, but let's finish this discussion first.


              • 19. Re: MutableClassInfo?
                stalep

                 

                "alesj" wrote:
                I still don't see why it has to be a MutableCI.

                no reason besides the the one i postes above really. when i discussed this with Kabir we figured that people using Mutable* interfaces would probably work with Mutable objects, then it made sense to support both MCI and String. but what do you suggest? only String or CI? - as i said above, using CI doesnt give any value to the String parameter thats already there.

                "alesj" wrote:

                Why isn't the one in MDR good enough?
                Afaik AOP already uses MDR.

                btw: there is a Javassist kind of Signature:
                - http://anonsvn.jboss.org/repos/jbossas/projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/spi/signature/javassist/
                I already use it in annotation scanning.

                yup, that would work, but since it it only have CtMethod as an argument we either need to add a method to MMI (that again would use mdr) or add a method to mdr to support a MMI/MCI interface. personally i just feel that such a method is something that "belongs" in MMI/MCI, but its not a big thing either.

                • 20. Re: MutableClassInfo?
                  kabirkhan

                  - http://anonsvn.jboss.org/repos/jbossas/projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/spi/signature/javassist/

                  Seems to fit the main usage we have in jboss aop. Later when using the mdr in aop we can create the mdr signatures from MethodInfo etc

                  "stale.pedersen@jboss.org" wrote:

                  mostly because then we are sure that we will get a CtClass instance within the parameter. there is also a String parameter if you would prefer to use that. it makes little sense to have a ClassInfo param since then we would just do the same work internally as with the String param.


                  Maybe as Ales says we should not have MutableCI as parameters. If just CI is used, we can check internally if it is of the correct type (JavassistClassInfo), otherwise fall back to the String impl and look it up from the name. It saves us having to look it up every time.

                  "alesj" wrote:

                  "stale.pedersen@jboss.org" wrote:

                  The usage of the Class parameter needs to be removed, internal methods using it will just use the CtClass object.

                  How does this effect the (weak type) cache?

                  That is an implementation detail that needs to be reworked internally. Having Class as the key for this won't work since we don't want the class to be loaded. Internally the weak type cache stores class names in a map of cl, so this methods can work
                  TypeInfoFactory.getTypeInfo(String name, ClassLoader cl)
                  

                  The use of WeakClassCache by Javassist will need revisiting so that it does not try to load the class every time we try to look something up since that is not needed by the underlying implementation.

                  "alesj" wrote:

                  "stale.pedersen@jboss.org" wrote:

                  is it ok if i start commit to jboss-reflect? i can exclude the new files in the pom if needed.

                  I don't wanna sound pita, but let's finish this discussion first.

                  Create a wiki page with the work in progress?

                  • 21. Re: MutableClassInfo?
                    stalep

                     

                    "kabir.khan@jboss.com" wrote:

                    "alesj" wrote:

                    How does this effect the (weak type) cache?

                    That is an implementation detail that needs to be reworked internally. Having Class as the key for this won't work since we don't want the class to be loaded. Internally the weak type cache stores class names in a map of cl, so this methods can work
                    TypeInfoFactory.getTypeInfo(String name, ClassLoader cl)
                    

                    The use of WeakClassCache by Javassist will need revisiting so that it does not try to load the class every time we try to look something up since that is not needed by the underlying implementation.

                    im looking into JavassistTypeInfoFactoryImpl and JavassistTypeInfo with the goal of getting them Mutable compliant (eg. no usage of Class).

                    the last remaining problem i have with this is JavassistTypeInfo.getType(). with my changes this method will always return null, but this is breaking the testsuite since there are tests that depends on this returning the actual class.

                    from my point of view the getType() method do not have any meaning for a MutableClassInfo since the type isnt defined yet before the class has been frozen/loaded.

                    so either we can change the getType() method or we need to create a new implementation of JavassistTypInfo that is mutable compliant.

                    for reference, take a look at the diff here:http://github.com/stalep/jboss-reflect/commit/a1a396c2203d63ae487fc1dfc21806f35577fb7e

                    "kabir.khan@jboss.com" wrote:

                    Create a wiki page with the work in progress?

                    atm im using git as a vcs, you can all take a look at it here:
                    http://github.com/stalep/jboss-reflect - note that i can push changes from the git repo back to jboss-reflect svn when wanted.

                    ill be posting design ideas/thoughts on a wiki too.

                    • 22. Re: MutableClassInfo?
                      stalep

                      regarding the changes to WeakClassCache ive only created a simple compare method to make sure that the cached object actually is correct.
                      take a look at the commit above for the implementation details.

                      - suggestions on better a solution to the WeakClassCache problem is wanted if we still want to make JavassistTypeInfo mutable compliant. if we end up creating another implementation we can do something different.

                      - yes, i know we need to change the caching of the getDeclaredMethods/Constructors/Fields for the mutable implementation, but im waiting with that untill we decide on what to do with JTI.

                      • 23. Re: MutableClassInfo?
                        stalep

                        - or we can just get the classrepresentation from the ctclass like:

                        public Class<? extends Object> getType()
                        {
                         if(clazz == null)
                         clazz = ctClass.toClass(); //catch some exception
                         return clazz;
                        }

                        - this would cause the MCI/ctClass to be frozen, but as long as we document it it might be ok?

                        • 24. Re: MutableClassInfo?
                          stalep

                          im just wondering a bit about the usage of SignatureKey in JavassistMethodInfo. it doesnt seem to add any vaule that i can see. first of all its only used in the method JavassistMethodInfo.getName() where the name can be fetched from the CtMethod object instead.
                          with a mutable methodinfo it lack even more meaning since the method parameters and name dont need to be defined when creating the method.

                          i can understand the usage of SignatureKey in JavassistTypeInfo as it is used as a key for the maps that hold methods, fields, and constructors.
                          - even though a better solution would probably to use the signature of the method/field/constructor as the map key instead of SignatureKey (atleast it would be more efficient).

                          please explain the reason of having the SignatureKey in JavassistMethodInfo, and if there isnt a good reason ill remove it.

                          • 25. Re: MutableClassInfo?
                            alesj

                             

                            "stale.pedersen@jboss.org" wrote:

                            - even though a better solution would probably to use the signature of the method/field/constructor as the map key instead of SignatureKey (atleast it would be more efficient).

                            What does javassist return as CtBehavior::getSignature?
                            How does it look like?
                            I guess you get the same string even for diff instances of the same method/field/constructor?

                            "stale.pedersen@jboss.org" wrote:

                            please explain the reason of having the SignatureKey in JavassistMethodInfo, and if there isnt a good reason ill remove it.

                            I also don't see any reason to keep it.

                            My guess would be that there was no CtBehavior::getSignature at the time of writing this, Adrian?
                            You can definitely try to change the methods map in JavassistTypeInfo to keep things under this new string signature key.

                            • 26. Re: MutableClassInfo?
                              stalep

                               

                              "alesj" wrote:

                              What does javassist return as CtBehavior::getSignature?
                              How does it look like?
                              I guess you get the same string even for diff instances of the same method/field/constructor?

                              yes, using the method signature will create duplicate keys if methods got the same parameter signature. but using CtBehaviour.getLongName() (which add the class and methodname to the signature) we will always be sure that we have a unique key. eg for a method like: Pojo.foo(String), CtBehaviour.getLongName() would return Pojo.foo(java.lang.String).

                              • 27. Re: MutableClassInfo?

                                 

                                "stale.pedersen@jboss.org" wrote:
                                "alesj" wrote:

                                What does javassist return as CtBehavior::getSignature?
                                How does it look like?
                                I guess you get the same string even for diff instances of the same method/field/constructor?

                                yes, using the method signature will create duplicate keys if methods got the same parameter signature. but using CtBehaviour.getLongName() (which add the class and methodname to the signature) we will always be sure that we have a unique key. eg for a method like: Pojo.foo(String), CtBehaviour.getLongName() would return Pojo.foo(java.lang.String).


                                There was a previous discussion about adding class name to the signature.
                                We ended up doing a halfway solution with the DeclaredMethodSignature
                                since we didn't have time to test changing the existing signatures.

                                • 28. Re: MutableClassInfo?
                                  alesj

                                   

                                  "adrian@jboss.org" wrote:

                                  There was a previous discussion about adding class name to the signature.
                                  We ended up doing a halfway solution with the DeclaredMethodSignature
                                  since we didn't have time to test changing the existing signatures.

                                  But this was in MDR, not Reflect. ;-)

                                  • 29. Re: MutableClassInfo?
                                    stalep

                                    im writing a few tests for the mutable implementation and there are part of the existing api that i feel are a bit cumberstone. example:

                                    MutableClassInfo mci = new JavassistTypeInfoFactoryImpl().getMutable("Pojo", null);
                                    MutableMethodInfo bar = mci.getDeclaredMethod("bar", new TypeInfo[] {(TypeInfo) new JavassistTypeInfoFactoryImpl().get("java.lang.String", Thread.currentThread().getContextClassLoader()) });

                                    how about adding methods like:
                                    public MethodInfo getDeclaredMethod(String methodName, String[] methodArgs);

                                    - to ClassInfo that by default use the classloader already defined in the TypeInfoFactory instance. if the user need to specify another classloader they will need to use the current method.
                                    its easy to implement and makes it easier to use so its well worth it imo.