[Java] Is the effort available?

classic Classic list List threaded Threaded
24 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Re: [Java] Is the effort available?

Nicolas Cannasse
Le 03/04/2011 15:09, Cauê Waneck a écrit :

> Hi Nicolas!
>
>
>     You could maybe using NekoVM hashing that is used for object
>     representation :
>
>     http://code.google.com/p/nekovm/source/browse/trunk/vm/others.c#357
>
>
> I saw that when I was looking at the neko sources to see how reflection
> is implemented there. But what isn't clear to me is that if this hashing
> is cached somehow, or a lookup into the tableis needed for each field
> access?

The hashing is cached when we do the string -> int resolution. It will
ensure that there are no conflicts (two strings with the same hash)
which we didn't find in practice with many years of using Neko, and that
we can do the int -> string reverse, for instance when printing an object.

Since the compiler is doing the hashing at compiletime, you will get
fast field lookup because on int comparison. In order to reduce memory
usage (which is also very important) Neko is using very simple object
tables with (int,value) tuples ordered by field hash, thus providing a
O(log N) access and only integer comparisons.

Nicolas

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: [Java] Is the effort available?

Cauê W.
Wow! That's amazing!!! You can't go faster than this (without resorting to complicated runtime schemes) !
If the compiler is doing the hashing at compile-time, isn't there the possibility of collisions if you load two different modules? I'll see if it's possible to implement this in C#/Java !

2011/4/3 Nicolas Cannasse <[hidden email]>
Le 03/04/2011 15:09, Cauê Waneck a écrit :

Hi Nicolas!


   You could maybe using NekoVM hashing that is used for object
   representation :

   http://code.google.com/p/nekovm/source/browse/trunk/vm/others.c#357


I saw that when I was looking at the neko sources to see how reflection
is implemented there. But what isn't clear to me is that if this hashing
is cached somehow, or a lookup into the tableis needed for each field
access?

The hashing is cached when we do the string -> int resolution. It will ensure that there are no conflicts (two strings with the same hash) which we didn't find in practice with many years of using Neko, and that we can do the int -> string reverse, for instance when printing an object.

Since the compiler is doing the hashing at compiletime, you will get fast field lookup because on int comparison. In order to reduce memory usage (which is also very important) Neko is using very simple object tables with (int,value) tuples ordered by field hash, thus providing a O(log N) access and only integer comparisons.


Nicolas

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: [Java] Is the effort available?

Cauê W.
In reply to this post by Gamehaxe
Hey!

2011/4/3 Hugh Sanderson <[hidden email]>
Hi,
I think simple calls are ok, but things get a bit tricky when
references must be maintained - eg, haxe callbacks and context objects.
But something could certainly be done - maybe steal code from other
similar projects.  I have not thought too deeply about this.

Oh well, I guess you're right... Maybe this could work something like how it works with .Net/Mono. You can annotate a static call to actually call a .dll function. It gets a little messy due to all the different calling conventions a C++ file can have, but it works great for C files, and maybe by parsing a c .h file we could come up with enough data to make this possible. Though I don't really know how they actually handle gc on those external calls ! (no idea, really!)


I have also been thinking about neko/c++ compatibility and
v8/c++ compatibility and caching hxcpp compiles into libraries. 
I think the new macro system may be what I need to get this going.
The idea is to compile hxcpp packages into ".lib/.a" files. eg, compile
the nme hx files and the hxcpp files once and store the result locally.
Then you can simply link against these.  The next step would be to
adapt one of the scripting languages to share the hxcpp GC and
then use scripting for parts of the code and pre-compile for other bits.
This would allow you to compile fast code (eg, use a pre-compiled physics
library) without needing to mess with a c++ compiler personally.
I think neko would be a very good match here.

That would be FANTASTIC ! I can also think of many great use cases for hybrid C++/Java C++/.Net programs ! 

I don't think it would be toooo hard, just need to find some time.

: )
Well, if you have some implementation ideas, we could maybe plan to work together on this!

Cheers!
Cauê

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: [Java] Is the effort available?

Nicolas Cannasse
In reply to this post by Cauê W.
Le 03/04/2011 20:55, Cauê Waneck a écrit :
> Wow! That's amazing!!! You can't go faster than this (without resorting
> to complicated runtime schemes) !
> If the compiler is doing the hashing at compile-time, isn't there the
> possibility of collisions if you load two different modules? I'll see if
> it's possible to implement this in C#/Java !

Each neko module have a list of compile-time used identifiers, which are
registered into a global table at module loading time. We also check
this global table when using reflection.

Best,
Nicolas

--
haXe - an open source web programming language
http://haxe.org
12