473,320 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

optimization

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
2 1485
-----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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Alex Vinokur | last post by:
For instance, we need to measure performance of assignment 'ch1 = ch2' where ch1 and ch2 are of char type. We need to do that for different optimization levels of the same compiler. Here is...
9
by: Rune | last post by:
Is it best to use double quotes and let PHP expand variables inside strings, or is it faster to do the string manipulation yourself manually? Which is quicker? 1) $insert = 'To Be';...
5
by: AC Slater | last post by:
Whats the simplest way to change a single stored procedures query optimization level? In UDB8 that is. /F
2
by: Eugene | last post by:
I am trying to set query optimization class in a simple SQL UDF like this: CREATE FUNCTION udftest ( in_item_id INT ) SPECIFIC udftest MODIFIES SQL DATA RETURNS TABLE( location_id INT,...
12
by: WantedToBeDBA | last post by:
Hi all, db2 => create table emp(empno int not null primary key, \ db2 (cont.) => sex char(1) not null constraint s_check check \ db2 (cont.) => (sex in ('m','f')) \ db2 (cont.) => not enforced...
24
by: Kunal | last post by:
Hello, I need help in removing if ..else conditions inside for loops. I have used the following method but I am not sure whether it has actually helped. Below is an example to illustrate what I...
21
by: mjbackues at yahoo | last post by:
Hello. I'm having a problem with the Visual Studio .net (2003) C++ speed optimization, and hope someone can suggest a workaround. My project includes many C++ files, most of which work fine...
5
by: wkaras | last post by:
I've compiled this code: const int x0 = 10; const int x1 = 20; const int x2 = 30; int x = { x2, x0, x1 }; struct Y {
2
by: db2admin | last post by:
hi, I have query which runs great when optimization level is changed to 3 but does not run fine with default optimization level of 5. since this is a query in java code, i do not know how can i...
20
by: Ravikiran | last post by:
Hi Friends, I wanted know about whatt is ment by zero optimization and sign optimization and its differences.... Thank you...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.