2 Replies Latest reply: Feb 13, 2012 9:03 AM by Flavia Rainone RSS

    $@ usage

    Flavia Rainone Master

      Hi!

      I am using byteman to intercept a method call. However, I am having problems when I try to use $@.

      If I try to assign $@ to a variable, at BIND, it works. But I need to retrieve the element at position 0 of the array $@.

      Is there a way to do this?

      This is how my rule looks right now:

       

       

      RULE avoid deadlock caused by extra locks in this script
      CLASS org.jboss.msc.service.ServiceContainerImpl
      METHOD install
      AT INVOKE ServiceControllerImpl.commitInstallation
      BIND serviceName = $@0.getName().getSimpleName();
      IF serviceName.equals("C") AND incrementCounter("run avoid deadlock only once, on service B first removal2") == 1 AND !flagged("parents undemanded, no risk of deadlock")
      DO
          debug("avoiding deadlock, holding commitInstallation until doUndemandParents is done"),
          waitFor("parents undemanded, no risk of deadlock"),
          debug("proceeding with commitInstallation")
      ENDRULE
      

       

      I get a ParseException at the BIND line.

        • 1. Re: $@ usage
          Andrew Dinn Master

          Hi Flavia,

           

          Flavia Rainone wrote:

           

          Hi!

          I am using byteman to intercept a method call. However, I am having problems when I try to use $@.

          If I try to assign $@ to a variable, at BIND, it works. But I need to retrieve the element at position 0 of the array $@.

          Is there a way to do this?

           

          Well, $@ is an Object[]. So, to retrieve element 0 you use $@[0] -- easy-peasy, just like Java :-)

           

          Of course, the resulting value has type Object which is not a lot of use to you unless you pass it into a helper to do a cast.

           

          Now, on that subject, I have been thinking of adding some form of cast operation to  Byteman  e.g. something like this

           

          . . .

          BIND serviceController : ServiceController = cast(ServiceControllerImpl, $@[0]);

               serviceName = serviceController.getName().getSimpleName();

          IF . . .

           

          Or maybe even just adding automatic coercion where it is clear that a specific type is expected e.g.

           

          . . .

          BIND serviceController : ServiceController = $@[0];

               serviceName = serviceController.getName().getSimpleName();

          IF . . .

           

          Anyway, I have not really come up with a good clear model for how to add this. So, until I do you will have to use a helper to do anything useful with $@[0].

          • 2. Re: $@ usage
            Flavia Rainone Master

            Thanks Andrew. I tried:

             

            BIND serviceController: ServiceController = $@[0]
            

             

            But, since it didn't work, I assumed that there was a different sintax to access $@[0].

             

            The helper solved my problem!