Java Forum / General / August 2006
Inline assembly
samir - 07 Aug 2006 21:39 GMT Is it possible to use "inline assembly" within java code?
Daniel Dyer - 07 Aug 2006 22:00 GMT > Is it possible to use "inline assembly" within java code? For which architecture? Java programs run on virtual machines. The actual hardware could be x86, Sparc, PowerPC or something else.
Dan.
 Signature Daniel Dyer http://www.dandyer.co.uk
AndrewMcDonagh - 07 Aug 2006 22:36 GMT > Is it possible to use "inline assembly" within java code? why? what is it you are trying to achieve?
samir - 08 Aug 2006 10:00 GMT Thanks for the replies, I didn't think someone will be interested in it.
I want to use inline assembly to talk directly to the JVM (you might have figured it out, I'm addicted to C and assembly).
Also, I think that java can't deal properly with "soft based" dynamic typed objects.
Adiaux Samir
Thomas Weidenfeller - 08 Aug 2006 11:00 GMT > Thanks for the replies, I didn't think someone will be interested in > it. > > I want to use inline assembly to talk directly to the JVM (you might > have figured it out, I'm addicted to C and assembly). You would probably do more harm than good. The hotspot JIT can get confused by premature optimization and you might get slower code, not faster. I fact, Sun removed certain "optimizations" from the code generation of the compiler to allow the JIT to work better.
But if you want to try: http://asm.objectweb.org/
> Also, I think that java can't deal properly with "soft based" dynamic > typed objects. Whatever that should be. Java is (by the usual definitions), a statically typed language. You might need a miracle to turn it into a dynamic typed language.
/Thomas
 Signature The comp.lang.java.gui FAQ: ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/
Chris Uppal - 08 Aug 2006 14:36 GMT > I want to use inline assembly to talk directly to the JVM (you might > have figured it out, I'm addicted to C and assembly). I suspect you'd be better of working directly with bytecode for everything. There are a number of byte code libraries available -- ASM and BCEL are the best known. There are also some higher-level libraries which may help in one way or another. This page lists several (none of which I can vouch for in any way):
http://java-source.net/open-source/bytecode-libraries
> Also, I think that java can't deal properly with "soft based" dynamic > typed objects. Working at bytecode level gives you only a little better chance to to implement "soft typed" languages -- the JVM bytecode is a statically typed language itself (checked by the verifier) and while working at that level does at least allow you to call methods which the Java compiler wouldn't (if it didn't know in advance that they were going to exist at runtime), it doesn't provide help in recovering from situations where the method turns out not to exist after all. At least, not if you want to do anything more elaborate than throwing an exception.
However, this might interest you, if you haven't seen it already:
http://blogs.sun.com/roller/page/gbracha?entry=invokedynamic
I have no idea at all how likely it is to come to fruition.
-- chris
Daniel Dyer - 08 Aug 2006 14:48 GMT > However, this might interest you, if you haven't seen it already: > > http://blogs.sun.com/roller/page/gbracha?entry=invokedynamic A man with the job title "Computational Theologist" complaining about inventing confusing new names for old things. A Computational Theologist at Sun Microsystems no less. The same Sun Microsystems that gave us the Java version mess, the Solaris version mess and the brilliantly misleading "Sun Java Desktop".
> I have no idea at all how likely it is to come to fruition. Here's a more recent mention of the same thing:
http://www.eweek.com/article2/0,1759,1997386,00.asp?kc=EWRSS03119TX1K0000594
Dan.
 Signature Daniel Dyer http://www.dandyer.co.uk
Chris Uppal - 08 Aug 2006 15:44 GMT [me:]
> > http://blogs.sun.com/roller/page/gbracha?entry=invokedynamic > > A man with the job title "Computational Theologist" complaining about > inventing confusing new names for old things. A Computational Theologist > at Sun Microsystems no less. I rather doubt whether "Computational Theologist" really is his official job title, but if it is then it's definitely not a case of "jargon [which] has been used throughout the ages to intimidate and exclude" but rather what we, in the dynamic language world, call a "joke" (perhaps you've heard of them?). Or possibly a piss-take aimed at the various folk with "evangelist" in their titles. Or both...
FWIW, I don't -- not by a long, long, way -- include Bracha in the cluster of head-up-own-arse technolgists who have done so much to produce, promote, and develop Java into the ungainly hybrid it has become (and which, indeed, it started as -- but not so much so).
> The same Sun Microsystems that gave us the > Java version mess, the Solaris version mess and the brilliantly misleading > "Sun Java Desktop". It's not an impressive record, is it ? My own favorite was when the JVM finally gained a not-completely-brain-dead garbage collector[*] -- the "exact GC", IIRC -- and Sun had the nerve to phrase their descriptions of it as if they had /invented/ proper garbage collection !
([*] the current GC is impressive, but early Java gc was a pathetic joke).
-- chris
Daniel Dyer - 08 Aug 2006 15:56 GMT > I rather doubt whether "Computational Theologist" really is his official > job [quoted text clipped - 3 lines] > in the > dynamic language world, call a "joke" (perhaps you've heard of them?). http://bracha.org/Site/Theology.html
If it is a joke, it's not a funny one :(
> FWIW, I don't -- not by a long, long, way -- include Bracha in the > cluster of [quoted text clipped - 3 lines] > it > started as -- but not so much so). I was merely commenting on the irony of his complaints about Microsoft given his own position. My main reason for responding was the link I posted which seems to suggest that the invokedynamic thing is going to happen.
Dan.
 Signature Daniel Dyer http://www.dandyer.co.uk
bugbear - 09 Aug 2006 10:13 GMT > Thanks for the replies, I didn't think someone will be interested in > it. > > I want to use inline assembly to talk directly to the JVM (you might > have figured it out, I'm addicted to C and assembly). I'd stay with them, then, rather than trying to make Java do something it wasn't designed for.
I find that Java supports considerable freedom of expression for significantly complex programs, and "adequate" optimisation (courtesy of JIT) in tight processing loops.
I have used 'C' and assembler for performance (at one time in a world leading piece of software, which was primarily judged on performance), but hav been using Java for the last few years without too many pangs of loss.
BugBear
Chris Uppal - 08 Aug 2006 09:57 GMT > Is it possible to use "inline assembly" within java code? No.
If you want to "inline" JVM bytecode in your Java code then you could possibly do it by finding/writing a custom compiler. But there is very little point in doing that since JVM bytecode is very, very, similar to Java and there's not much that you can do at that level which you can't also do in pure java.
If you want to inline harware-level machine instructions, then you cannot do it at all. It is completely impossible.
-- chris
Oliver Wong - 08 Aug 2006 20:34 GMT >> Is it possible to use "inline assembly" within java code? > [quoted text clipped - 11 lines] > do it > at all. It is completely impossible. What if you stored the machine instructions as data, and at the appropriate time, emit them to a file, and called Runtime.exec(filename)?
- Oliver
samir - 08 Aug 2006 21:14 GMT Thanks for the links, they where very usefull (the ASM one was perfect
:).
> What if you stored the machine instructions as data, and at the > appropriate time, emit them to a file, and called Runtime.exec(filename)? Nice idea! So, i'll return (yes!) to my old gcc, lex and yacc and write an interface that will build all the necessary files and supervise the "make" process. The problem now is parsing the compilers error messages but it will be fine :)
I've always admired the auto changing code, using a JIT seems to be the right answer but inline assembly has its charms too.
Adiaux Samir
jmcgill - 08 Aug 2006 21:34 GMT > Nice idea! So, i'll return (yes!) to my old gcc, lex and yacc and write > an interface that will build all the necessary files and supervise the > "make" process. You talk about these tools as though you think they are bad things.
While I love Java for its strengths, I still have a deep appreciation for C.
samir - 10 Aug 2006 18:18 GMT > > Nice idea! So, i'll return (yes!) to my old gcc, lex and yacc and write > > an interface that will build all the necessary files and supervise the [quoted text clipped - 3 lines] > > While I love Java for its strengths, I still have a deep appreciation for C. Saluton!
I've been using C for almost all my devlpement time and I enjoy using it. But the fact that the world is moving toward OOP and AOP makes it somehow a "legacy programming language" (except for hardware and operating system cases).
Even java and C++ charm is not going to last for ever: there is the emerging taste for the dynamically typed languages and most of the developpers will vote for the simplicity of languages such as Python and Ruby. But, you know, now you have to follow the standards or you will have a kick in the a.s.
Adiaux Samir
jmcgill - 10 Aug 2006 19:00 GMT > But the fact that the world is moving toward OOP and AOP makes it > somehow a "legacy programming language" (except for hardware and > operating system cases). Parts of the world, I suppose. Some of us still live in system- and device- land :-)
samir - 10 Aug 2006 19:21 GMT Saluton!
> Parts of the world, I suppose. Some of us still live in system- and > device- land :-) Even java and friends are coming to the hardware wanderland:
http://news.com.com/2100-1001-278485.html?legacy=cnet
In addition to that, the newly born ARM processors have native support for java bytecode to make embedding java into embedded systems even easier.
Adiaux Samir
P.S: I think that making modifications to gcj will be easier than making an other preprocessor layer :-)
bugbear - 11 Aug 2006 12:21 GMT > Saluton! > [quoted text clipped - 4 lines] > > http://news.com.com/2100-1001-278485.html?legacy=cnet Hah! Look at the date - 1997. This idea was nicely superceded by JIT (and other run-time dynamic optimisation techniques)
Try googling for "dynamic optimisation" (or with a 'z') and learn...
BugBear
samir - 11 Aug 2006 19:03 GMT Saluton!
> Hah! Look at the date - 1997. This idea was nicely superceded > by JIT (and other run-time dynamic optimisation techniques) It seems that hardware isn't over with java or java isnt over with hardware :)
Look at this:
http://en.wikipedia.org/wiki/ARM_architecture#Jazelle
In addition to that, I dont think that it would be resonable that a microcontroller could be able to run a JIT task.
This days, java is "the" fashion in the programming world. Every one is willing to use it for anything. People talk about porting Linux to toasters where java is one step from seeing it's bytecode managing the guts of a big fat toaster.
> Try googling for "dynamic optimisation" (or with a 'z') > and learn... Oops... Thank you for the advice...
Adiaux Samir
Chris Uppal - 09 Aug 2006 10:08 GMT > What if you stored the machine instructions as data, and at the > appropriate time, emit them to a file, and called Runtime.exec(filename)? Or even jump directly to them with a bit of JNI magic.
But in neither case is the inserted code really being executed inline -- you don't know what the surrounding code is going to be JITed into, so you can't really do anything that you couldn't do with a normal function call (native or not).
-- chris
Gordon Beaton - 09 Aug 2006 10:49 GMT >> What if you stored the machine instructions as data, and at the >> appropriate time, emit them to a file, and called Runtime.exec(filename)? > > Or even jump directly to them with a bit of JNI magic. That's not possible on systems where code segments aren't writeable, and data segments aren't executable. I believe that's true of virtually all modern hardware.
/gordon
 Signature [ don't email me support questions or followups ] g o r d o n + n e w s @ b a l d e r 1 3 . s e
Chris Uppal - 09 Aug 2006 11:19 GMT [me:]
> > Or even jump directly to them with a bit of JNI magic. > > That's not possible on systems where code segments aren't writeable, > and data segments aren't executable. I believe that's true of > virtually all modern hardware. Ok, ok...
So /copy/ the bytes to a writable area, then change it into a code segment -- that's what the JITer has to do after all ;-)
-- chris
samir - 09 Aug 2006 14:30 GMT > [me:] > > > Or even jump directly to them with a bit of JNI magic. [quoted text clipped - 9 lines] > > -- chris That remindes me of "superposing" the code segment and the data segment using the same (copy of) GDT (x86) entry but with diffrent flags. This is used with Grub and some other bootloaders when getting to the protected mode.
This would only work if you have the access to such low level structures, and would make the java code lose it's portability.
Adiaux Samir
AndrewMcDonagh - 09 Aug 2006 22:53 GMT >> [me:] >>>> Or even jump directly to them with a bit of JNI magic. [quoted text clipped - 15 lines] > This would only work if you have the access to such low level > structures, and would make the java code lose it's portability. doing any assembler in /calling from Java, losing Java's portability.
> Adiaux > Samir Ray Thompson - 09 Aug 2006 16:00 GMT >> Is it possible to use "inline assembly" within java code? > > No. Well, since NONE of the books I've read about Java programming mention inline assembly (or even ASSEMBLY), I have to assume tht it's either impossible or impractical. So, I agree with Chris.
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|