Google Groups Home
Help | Sign in
Message from discussion Performance characteristics of mutable static primitives?
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Marcelo Fukushima  
View profile
 More options Apr 3, 7:37 pm
From: "Marcelo Fukushima" <takesh...@gmail.com>
Date: Thu, 3 Apr 2008 20:37:06 -0300
Local: Thurs, Apr 3 2008 7:37 pm
Subject: Re: [jvm-l] Re: Performance characteristics of mutable static primitives?
On 4/3/08, John Cowan <johnwco...@gmail.com> wrote:

>  On Thu, Apr 3, 2008 at 7:01 PM, John Rose <John.R...@sun.com> wrote:

>  >  Yes.  You can then cast it to the subclass and go on from there.

> That's what I had hoped, but the JLS doesn't actually seem to guarantee this.

>  >  > If so, that provides a different approach
>  >  > to thread-local state, where the state is held in the instance
>  >  > variables of MyThread objects, and the JVM is used to thread them
>  >  > through :-) the code until the point where they're needed.

>  >  That's how Java thread locals are implemented in the JVM.

> I don't understand how that can be, as I can create as many
>  ThreadLocals as I want.  They can't all fit in the Thread object,
>  surely.  And how can reference to them be fast if they have to
>  indirect through a Thread subclass object?

the source for ThreadLocal explains the first bit:

public void set(T value) {
        Thread t = Thread.currentThread();
        ThreadLocalMap map = getMap(t);
        if (map != null)
            map.set(this, value);
        else
            createMap(t, value);
    }

apparently, every thread has a map that holds all ThreadLocal's registered

>  >  You can only use this approach if (a) you control the creation of the
>  >  thread and can specify your own subclass for it,

> That's what I had in mind.

>  >  You might be interested to know that Hotspot intrinsifies
>  >  Thread.currentThread to a couple of instructions; it's cheap.  We did
>  >  that to make things like thread locals efficient.

> Good.

>  --
>  GMail doesn't have rotating .sigs, but you can see mine at
>  http://www.ccil.org/~cowan/signatures

--
[]'s
Marcelo Takeshi Fukushima

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google