optimization

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • nos

    optimization

    Does anyone know if the java compiler 1.4.2
    from SUN optimizes subexpressions? I.e.
    in the following two lines

    int tcount = Thread.currentT hread().getThre adGroup().enume rate(myThreadLi st);
    String tcurrent = Thread.currentT hread().getName ();

    will it evaluate Thread.currentT hread();
    only once?

    just curious
  • Chris

    #2
    Re: optimization

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    nos wrote:
    [color=blue]
    > Does anyone know if the java compiler 1.4.2
    > from SUN optimizes subexpressions? I.e.
    > in the following two lines
    >
    > int tcount =
    > Thread.currentT hread().getThre adGroup().enume rate(myThreadLi st);
    > String tcurrent = Thread.currentT hread().getName ();
    >
    > will it evaluate Thread.currentT hread();
    > only once?
    >
    > just curious[/color]

    Hi,
    I'm no expert, but I doubt the *compiler* could do that, since it
    doesn't know that Thread.currentT hread() doesn't have any
    side-effects. It would have to make sure it gets called twice. After
    all, it's theoretically (practically?) possible that the Thread
    implementation could be replaced later with something that does have
    side-effects. One possible place for such optimization would be a
    highly-intelligent JIT, which "knows" about its own attached runtime
    (i.e. it knows that Thread.currentT hread() has no side-effects). I
    don't think anything like this exists, though.
    - --
    Chris
    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.2.2 (GNU/Linux)

    iD8DBQE/rC3YwxczzJRavJY RApZmAJ48PgCVef/bVmx4AUeIuo9Usw bn9wCgwPPj
    yqrDWpeTkDQFzLo i19FliRY=
    =xmxk
    -----END PGP SIGNATURE-----

    Comment

    • nos

      #3
      Re: optimization

      very good point!
      on some earlier project we discovered that when
      we had two calls to the random number generator
      (not in java) that the compiler optimized it to only
      one call -- so we had to put a line number on
      the second call (FORTRAN has line numbers)

      "Chris" <chris2k01@hotm ail.com> wrote in message
      news:o71rb.3050 $jy.544@clgrps1 3...[color=blue]
      > -----BEGIN PGP SIGNED MESSAGE-----
      > Hash: SHA1
      >
      > nos wrote:
      >[color=green]
      > > Does anyone know if the java compiler 1.4.2
      > > from SUN optimizes subexpressions? I.e.
      > > in the following two lines
      > >
      > > int tcount =
      > > Thread.currentT hread().getThre adGroup().enume rate(myThreadLi st);
      > > String tcurrent = Thread.currentT hread().getName ();
      > >
      > > will it evaluate Thread.currentT hread();
      > > only once?
      > >
      > > just curious[/color]
      >
      > Hi,
      > I'm no expert, but I doubt the *compiler* could do that, since it
      > doesn't know that Thread.currentT hread() doesn't have any
      > side-effects. It would have to make sure it gets called twice. After
      > all, it's theoretically (practically?) possible that the Thread
      > implementation could be replaced later with something that does have
      > side-effects. One possible place for such optimization would be a
      > highly-intelligent JIT, which "knows" about its own attached runtime
      > (i.e. it knows that Thread.currentT hread() has no side-effects). I
      > don't think anything like this exists, though.
      > - --
      > Chris
      > -----BEGIN PGP SIGNATURE-----
      > Version: GnuPG v1.2.2 (GNU/Linux)
      >
      > iD8DBQE/rC3YwxczzJRavJY RApZmAJ48PgCVef/bVmx4AUeIuo9Usw bn9wCgwPPj
      > yqrDWpeTkDQFzLo i19FliRY=
      > =xmxk
      > -----END PGP SIGNATURE-----[/color]


      Comment

      Working...