<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
    <title></title>
  </head>
  <body text="#000000" bgcolor="#ffffff">
    On 02/11/2010 11:02, Guillaume Sauthier wrote:
    <blockquote cite="mid:4CCFEFE0.4010700@ow2.org" type="cite">Hi Mark
      <br>
      It's nice to have your view on the this subject (even if it
      disassemble my current plan ;) )
      <br>
      <br>
      Le 28/10/2010 18:17, Mark Proctor a &eacute;crit :
      <br>
      <blockquote type="cite">I actually want to move away from compile
        time generated bytecode inside
        <br>
        of the packages. Instead I want to move to just keeping
        validated
        <br>
        Strings that can be executed via MVEL. Additional we would use
        ASM to
        <br>
        bytecode compile often used strings at runtime.
        <br>
        &nbsp;&nbsp; </blockquote>
      <br>
      Isn't it the role of the MVEL Optimizers (I've read they have
      something based on ASM) ?
      <br>
      BTW, are theses classes generated when rule Package are compiled ?
      <br>
    </blockquote>
    I'm actually implementing this as an MVEL optimisation. At the
    moment MVEL only ASM's setters and getters. I want full "flat" code
    generation so effectively the generated code is standalone, even if
    it was generated from mvel. There is no ETA for this.<br>
    <blockquote cite="mid:4CCFEFE0.4010700@ow2.org" type="cite">
      <br>
      <blockquote type="cite">So I think giving you direct access to
        generated bytecode would be a bad
        <br>
        thing, it's internal and unstable and you can be sure we'll
        change it as
        <br>
        we want.
        <br>
        &nbsp;&nbsp; </blockquote>
      <br>
      In a way, I don't care of what is inside the bytecode.
      <br>
      I'm only giving it to a bytecode parsing tool (aQute's Bnd) that
      will see what needs to be imported. So if there is some bytecode,
      I'm happy. if you change what code is generated, that will not
      affect me because Bnd will see that the imports have changed and
      will construct the bundle's manifest appropriately.
      <br>
      <br>
      I only need the bytecode (and an API to get them cleanly ;) ).
      <br>
    </blockquote>
    Get BND to accept a String of imports, and write an ant utility to
    extract them from Drools. <br>
    <blockquote cite="mid:4CCFEFE0.4010700@ow2.org" type="cite">
      <br>
      <blockquote type="cite">What you want is to ensure that certain
        types are imported so Drools can
        <br>
        see them, right?
        <br>
      </blockquote>
      Yes, I want to ensure that generated classes in the bundle have
      all their imports/requirements fulfilled.
      <br>
      <blockquote type="cite">So instead we should be looking at some
        sort of
        <br>
        analysis tool to provide this, we sort of have this already, but
        it
        <br>
        won't be complete for your purposes but can be extended. So it
        tells you
        <br>
        want classes are used and were, and you can use the drl parser
        to
        <br>
        extract imports etc.
        <br>
        &nbsp;&nbsp; </blockquote>
      <br>
      Can you give me some pointer(s) on what Drools currently have ?
      <br>
    </blockquote>
    The Drools DRL parser produces a Descr model of classes that
    provides things like imports.<br>
    <blockquote cite="mid:4CCFEFE0.4010700@ow2.org" type="cite">
      <br>
      <blockquote type="cite">The resouce type you suggest won't work.
        The generated class is just for
        <br>
        the consequence or some aslects of the "when" it is not the
        entire rule,
        <br>
        so in itself is not a complete resource.
        <br>
      </blockquote>
      <br>
      Sure, a Package stores more than just the bytecode of generated
      stuff.
      <br>
      But I was thinking that if theses pre-compiled classes where
      already in the bundle, it was a waste of resources to also have
      them in the serialized Package resource...
      <br>
      <br>
      <blockquote type="cite">Plus again I'd rather move
        <br>
        complete away from this pre-compiled concept and more to
        validated
        <br>
        strings with on the fly generation.
        <br>
        &nbsp;&nbsp; </blockquote>
      <br>
      Usually, this is this (uncontrolled for OSGi) on-the-fly
      generation that cause some harms.
      <br>
      <br>
      <blockquote type="cite">That said there is a need for environments
        like app-engine which don't
        <br>
        allow runtime bytecode generation and people want the perf boost
        of
        <br>
        bytecode to have fully pre-compiled rule sets.
        <br>
      </blockquote>
      <br>
      Theses are good use cases too. Considering that OSGi "don't allow"
      runtime bytecode generation :)
      <br>
      <br>
      <blockquote type="cite">&nbsp; I would consider
        <br>
        something like this, where a .jar has all the pre-compiled
        rules. But we
        <br>
        are a long way from this, first we need to get an ASM rule
        compiler
        <br>
        working, that can compile a complete rule, then we can look into
        a full
        <br>
        pre-compiled ruleset.
        <br>
        &nbsp;&nbsp; </blockquote>
      <br>
      What do you call a full pre-compiled ruleset ?
      <br>
      With my limited understanding, I consider an ASM compiler just
      like the old java compiler (it's just faster): it's another way to
      produce the same thing: executable bytecode.
      <br>
      So I don't see how moving from eclipse compiler to ASM will make
      things better for me.
      <br>
    </blockquote>
    yes I more meant we'll be revisiting how we do compiled stuff in
    Drools when we redo the ASM based compiler as an extension to MVEL.
    At this point we'll also look at allowing the bytecode to just be
    stored externally, such as in a zip. That would provide what you
    need, but we just aren't there yet. So for now maybe stick with
    descr analysis, which will work regardless of java or mvel dialec
    etc.<br>
    <blockquote cite="mid:4CCFEFE0.4010700@ow2.org" type="cite">
      <br>
      <br>
      So if I want to sum up the discussion at this point we have:
      <br>
      * Only reflection trick to access generated bytecode
      <br>
      * Analysis tools may be appropriate to have some insights of what
      will be generated
      <br>
      * Rule Pre-compilation is currently not available
      <br>
    </blockquote>
    The current way bytecode is stored we aren't going to expose in a
    manner you want, it's just exposing way too many internals for
    things we want to change soon. And users tend to shoult at us if we
    change things they are using. you can always do a patch that does
    what you need and worked off that patched version of drools.<br>
    <blockquote cite="mid:4CCFEFE0.4010700@ow2.org" type="cite">
      <br>
      --G
      <br>
      <br>
      <blockquote type="cite">Mark
        <br>
        On 26/10/2010 08:49, Guillaume Sauthier wrote:
        <br>
        &nbsp;&nbsp;
        <blockquote type="cite">Thanks for your answer Edson.
          <br>
          <br>
          The reason I have is that runtime generated stuff usually
          don't fit well
          <br>
          in an OSGi model.
          <br>
          <br>
          When you take a bundle, it has a statically defined set of
          "imported
          <br>
          packages". that means that when the bundle has been compiled,
          a list of
          <br>
          packages to be wired in at deployment time has been computed.
          This list
          <br>
          of packages if inferred from what the .class files (in the
          bundle)
          <br>
          requires to be executed (think of them as external
          dependencies).
          <br>
          <br>
          Now if we generate some classes at runtime in an OSGi
          environment, we
          <br>
          can see that generated classes can have different (or
          additional)
          <br>
          requirements in terms of java packages. So usually, with OSGi,
          that ends
          <br>
          up by adding a special header called DynamicImport-Package
          into the
          <br>
          MANIFEST, with the side effects of breaking modularity :-(
          <br>
          <br>
          This is what I want to avoid by having access to the generated
          classes
          <br>
          at the compilation phase: I can then use this bytecode (IOW
          giving it to
          <br>
          Bnd [1]) to complete the Import-Package MANIFEST header with
          the right
          <br>
          set of imported java packages.
          <br>
          <br>
          As a second issue, less important for the moment and more
          runtime
          <br>
          oriented this time, I would like to know if/how we can add a
          new kind of
          <br>
          Resource.
          <br>
          Once we have generated the bytecode in the compilation phase,
          we can
          <br>
          assume that all the stuff is already here in the bundle. Why
          can't we
          <br>
          use it ?
          <br>
          I've seen the PKG Resource type, but it's some kind of
          serialization of
          <br>
          a whole Package, couldn't it be possible to have a new Package
          type (or
          <br>
          way to create a Package) that can use the ClassLoader to get
          access to
          <br>
          the already present bundle's resources instead of using the
          byte[] from
          <br>
          the serialized Package ?
          <br>
          <br>
          WDYT?
          <br>
          <br>
          Thanks
          <br>
          --G
          <br>
          <br>
          [1]. <a class="moz-txt-link-freetext" href="http://www.aqute.biz/Code/Bnd">http://www.aqute.biz/Code/Bnd</a>
          <br>
          <br>
          Le 25/10/2010 21:26, Edson Tirelli a &eacute;crit :
          <br>
          &nbsp;&nbsp;&nbsp;&nbsp;
          <blockquote type="cite">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Not exactly sure how helpful
            would it be to store the generated
            <br>
            bytecodes in an osgi bundle. Anyway, there is no API right
            now to do
            <br>
            that, but you can use reflection to achieve the same:
            <br>
            <br>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PackageCompilationData data =
            pkg.getPackageCompilationData();
            <br>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Field field =
            PackageCompilationData.class.getDeclaredField( "store" );
            <br>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; field.setAccessible( true );
            <br>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Map&lt;String, byte[]&gt;&nbsp;&nbsp;&nbsp; store =
            (Map&lt;String, byte[]&gt;) field.get( data );
            <br>
            <br>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If you can justify the need for such an API, I guess
            we could be
            <br>
            convinced to add one.
            <br>
            <br>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Edson
            <br>
            <br>
            <br>
            <br>
            <br>
            2010/10/25 Guillaume
            Sauthier<a class="moz-txt-link-rfc2396E" href="mailto:guillaume.sauthier@ow2.org">&lt;guillaume.sauthier@ow2.org&gt;</a>:
            <br>
            <br>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <blockquote type="cite">Hi team
              <br>
              <br>
              I've tried the IRC (without much success I admit), maybe
              here someone will
              <br>
              have some thoughts to share :)
              <br>
              <br>
              I'm looking for a way to "intercept" the classes being
              generated by the
              <br>
              drools compiler.
              <br>
              I've seen that the classes bytecode is stored deep in
              <br>
              PackageStore/JavaDialectRuntimeData, so deep that I cannot
              easily access it
              <br>
              :)
              <br>
              The objective is to be able to give theses classes to Bnd
              (I want to store
              <br>
              all of that in an OSGi bundle) so that appropriate
              Import-Packages can be
              <br>
              computed. That will avoid to have DynamicImport-Packages
              all around my
              <br>
              bundles :)
              <br>
              <br>
              Currently, what I get from the drools compiler is a
              <br>
              Collection&lt;KnowledgePackage&gt;&nbsp;&nbsp;&nbsp; but I have no API
              (or didn't find any) to
              <br>
              access (or know) the classes generated by the compiler.
              <br>
              <br>
              Any ideas ?
              <br>
              Thanks
              <br>
              --Guillaume
              <br>
              <br>
              _______________________________________________
              <br>
              rules-dev mailing list
              <br>
              <a class="moz-txt-link-abbreviated" href="mailto:rules-dev@lists.jboss.org">rules-dev@lists.jboss.org</a>
              <br>
              <a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/rules-dev">https://lists.jboss.org/mailman/listinfo/rules-dev</a>
              <br>
              <br>
              <br>
              <br>
              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </blockquote>
            <br>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </blockquote>
          _______________________________________________
          <br>
          rules-dev mailing list
          <br>
          <a class="moz-txt-link-abbreviated" href="mailto:rules-dev@lists.jboss.org">rules-dev@lists.jboss.org</a>
          <br>
          <a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/rules-dev">https://lists.jboss.org/mailman/listinfo/rules-dev</a>
          <br>
          <br>
          <br>
          &nbsp;&nbsp;&nbsp;&nbsp; </blockquote>
        <br>
        _______________________________________________
        <br>
        rules-dev mailing list
        <br>
        <a class="moz-txt-link-abbreviated" href="mailto:rules-dev@lists.jboss.org">rules-dev@lists.jboss.org</a>
        <br>
        <a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/rules-dev">https://lists.jboss.org/mailman/listinfo/rules-dev</a>
        <br>
        <br>
        <br>
        &nbsp;&nbsp; </blockquote>
      <pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
rules-dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:rules-dev@lists.jboss.org">rules-dev@lists.jboss.org</a>
<a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/rules-dev">https://lists.jboss.org/mailman/listinfo/rules-dev</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>