Getting thread-local mem..

Tom Rodriguez Thomas.Rodriguez at Sun.COM
Fri Dec 7 07:59:17 PST 2007


ThreadLocalAllocBuffer isn't what you think.  It's a piece of the new 
generation that's been reserved for allocation by a particular thread. 
It's purely done to speed up Java allocation.

We usually just allocate any thread specific structures out of malloc 
and hang them off the thread, freeing them in the destructor.  Arena may 
be more like what you want.  It's a chunk of memory which is allocated 
sequentially like ResourceAreas but it can be reclaimed all at once.  If 
you aren't doing a lot of allocation it's not very efficient space wise 
though since it allocates chunks up front and I think the chunks are 
relatively large.  There's no explicit freeing either.

tom

Peter Helfer wrote:
> The thing is, that I will not only allocate mem in one context, but 
> rather multiple times, so I cannot use a ResourceMark; I could use 
> AllocateHeap(size_t size, const char* name) /  FreeHeap(void* p) - but I 
> thought it would be of interest to keep the objects closely together, so 
> not much paging happens because of dispersedness... this is why I would 
> like to have it on a thread-local basis....
> 
> Regards, Peter
> 
> 
> 2007/12/7, Keith McGuigan <Keith.McGuigan at sun.com 
> <mailto:Keith.McGuigan at sun.com>>:
> 
> 
>     If you need the memory to stay alive only within a particular
>     function scope
>     (even a high-level one), you can use resource memory, which is
>     thread-specific
>     and is automatically cleaned up by a ResourceMark.  It is not global
>     memory,
>     though - it will be reclaimed when the ResourceMark destructor is
>     called.  But
>     if you put it at a high enough level maybe this will do what you need?
> 
>     Take a look at allocation.hpp for info on this and other
>     possibilities (for
>     example if you are going to allocate out of C-heap, there are
>     routines in there
>     for doing that too).
> 
>     --
>     - Keith
> 
>     Peter Helfer wrote:
>      > I need some thread-local memory, which is not GC'd, but on death of
>      > thread freed for sure (although I would call free for each alloced
>      > elem). I've seen | threadLocalAllocBuffer.hpp
>      >
>     <file:///home/sgeorg/workspace/doxygenized/html/db/d09/threadLocalAllocBuffer_8hpp-
>     source.html>
>      > which offers HeapWord* allocate(size_t size) - but where is the
>      > corresponding free(HeapWord* ) ?
>      >
>      > Or is there a better alternative - apart from using malloc/free
>     directly ?
>      >
>      >
>      > Regards, Peter
>      > |
> 
> 



More information about the hotspot-runtime-dev mailing list