By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,798 Members | 1,342 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,798 IT Pros & Developers. It's quick & easy.

optimization

P: n/a
nos
Does anyone know if the java compiler 1.4.2
from SUN optimizes subexpressions? I.e.
in the following two lines

int tcount = Thread.currentThread().getThreadGroup().enumerate( myThreadList);
String tcurrent = Thread.currentThread().getName();

will it evaluate Thread.currentThread();
only once?

just curious
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

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

int tcount =
Thread.currentThread().getThreadGroup().enumerate( myThreadList);
String tcurrent = Thread.currentThread().getName();

will it evaluate Thread.currentThread();
only once?

just curious


Hi,
I'm no expert, but I doubt the *compiler* could do that, since it
doesn't know that Thread.currentThread() 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.currentThread() 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/rC3YwxczzJRavJYRApZmAJ48PgCVef/bVmx4AUeIuo9Uswbn9wCgwPPj
yqrDWpeTkDQFzLoi19FliRY=
=xmxk
-----END PGP SIGNATURE-----
Jul 17 '05 #2

P: n/a
nos
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" <ch*******@hotmail.com> wrote in message
news:o71rb.3050$jy.544@clgrps13...
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

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

int tcount =
Thread.currentThread().getThreadGroup().enumerate( myThreadList);
String tcurrent = Thread.currentThread().getName();

will it evaluate Thread.currentThread();
only once?

just curious


Hi,
I'm no expert, but I doubt the *compiler* could do that, since it
doesn't know that Thread.currentThread() 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.currentThread() 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/rC3YwxczzJRavJYRApZmAJ48PgCVef/bVmx4AUeIuo9Uswbn9wCgwPPj
yqrDWpeTkDQFzLoi19FliRY=
=xmxk
-----END PGP SIGNATURE-----

Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.