harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tim Ellison <t.p.elli...@gmail.com>
Subject Re: [classlib] mem
Date Mon, 26 Jun 2006 20:33:18 GMT
Geir Magnusson Jr wrote:
> Tim Ellison wrote:
>> Geir Magnusson Jr wrote:
>>> Except...
>>>
>>> 1) They aren't as Jimmy suggests, at least the one's I'm looking at.
>>>
>>> 2) the implementation in hymem.c just calls malloc()
>>>
>>> I'm confused.
>> Hopefully you are no longer confused after Oliver's explanation.
> 
> Yes, although I am still confused why you would want to do this.

(I hope I see what you are confused about, but correct me if I'm wrong)

> We have an implementation in hymem.c :
> 
>   hymem_alloc_memory( HyPortLib *, int )

That is the actual function that allocates memory, and in this case it
is platform specific, eventually calling HeapAlloc on Windows and malloc
on Linux.

This function is (deliberately) not exported from the hyprt.dll so you
cannot call it directly.  You have to call it via the function pointer
table ...

    <sidebar>There is also a similar function called
      hymem_allocate_memory_callSite that has an extra
      param to help debug the memory allocation calling
      site)</sidebar>

> which looks just like
> 
>   hymem_alloc_memory(int)
> 
> (if you use the right header)

This is a macro defined in portlib.h that adds syntactic sugar so you
can write hymem_alloc_memory(int) and the compiler will expand it into
the function table look-up for you.

...
#define hymem_allocate_memory(param1)
privatePortLibrary->mem_allocate_memory(privatePortLibrary,param1)
...

where 'privatePortLibrary' was obtained most likely from a JNIEnv struct
or a JavaVM struct etc. and 'mem_allocate_memory' is the member in the
function table (as defined in hyport.h) that contains the address of the
function 'hymem_allocate_memory()' described above.

See the definition, in portpriv.h, for
static HyPortLibrary MasterPortLibraryTable = ...

Of course, you can reference that member directly if you so choose, and
as written elsewhere if you are dealing with multiple tables the
syntactic sugar doesn't help and you must reference it in full.

  <sidebar>Just noticed that the hyport.h contains this directive
    #undef hymem_allocate_memory
    #define hymem_allocate_memory(param1) \
      privatePortLibrary-> \
        mem_allocate_memory_callSite(privatePortLibrary,param1, \
                                     HY_GET_CALLSITE())
    so we are actually using the _callSite slot each time.</sidebar>

> and it calls what might be two radically different things.

You lost me here ...

The macro always expands out to a reference like this:

privatePortLibrary	     (local var, defined by PORTLIB... macro)
 -> mem_allocate_memory      (address of function hymem_allocate_memory)
 (privatePortLibrary,param1) (invocation)

I guess that the confusion is caused by the HyPortLib struct containing
a member called 'mem_allocate_memory' that has the address of a function
called 'hymem_allocate_memory'?

> Why do we have himem.c?  Should we rename?   Toss?

(assuming himem.c == hymem.c)

Do you mean rename the file / function / struct member / macro or all of
the above ;-) ?

Regards,
Tim

-- 

Tim Ellison (t.p.ellison@gmail.com)
IBM Java technology centre, UK.


---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org


Mime
View raw message