code在Java中注入/总成内联? [英] Code injecting/assembly inlining in Java?

查看:226
本文介绍了code在Java中注入/总成内联?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道Java是一种安全的语言,但需要矩阵计算的时候,我可以试一下快?
我学习C ++,数字火星编译器和FASM __asm​​ {}。我想做Java中的相同。我怎样才能内联汇编codeS的功能呢?这甚至可能?

I know Java is a secure language but when matrix calculations are needed, can I try something faster? I am learning __asm{} in C++, Digital-Mars compiler and FASM. I want to do the same in Java. How can I inline assembly codes in functions? Is this even possible?

事情是这样的:

pushf
push ax
push bx
mov al,[var]
mov ah,0h
mov bl,04h
div bl
mov [var],ah
pop bx
pop ax
popf

System.out.println(var[0]);

我不希望使用code-注射器。我想看看英特尔的风格说明。

I don't want to use a code-injector. I want to see the Intel style instructions.

推荐答案

有是使这种事情不可能在原则上你的Java code和底层硬件之间的抽象层;你可以在技术上不知道你的code重新psented基础计算机上$ P $,因为相同的字节code可以在不同的处理器和不同的架构上运行。

There is a layer of abstraction between your Java code and the underlying hardware that makes this kind of thing impossible in principle; you technically can't know how your code is represented on the underlying machine, since the same bytecode can run on different processors and different architectures.

你有什么正式的可以的做的是使用的 Java本地接口(JNI)从Java code调用本地code。该调用的开销是巨大的,并与Java共享数据是相当昂贵的,所以这应该只对本地code体面大小的块中。

What you officially can do is use the Java Native Interface (JNI) to call native code from your Java code. The call overhead is substantial, and sharing data with Java is fairly expensive, so this should be used only for decent-sized chunks of native code.

在理论上,这样的延伸应该是可能的,虽然。可以想见Java编译器有针对性的特定的平台,并允许装配逃逸。编译器将不得不公布其ABI,所以你知道调用约定。我不知道任何事,但是。但也有几个 编译器 可用的编译Java直接为本地code;它可能其中一人支持这样的事情我不知道或可以扩展这样做。

In theory, such an extension should be possible, though. One can imagine a Java compiler that targeted a specific platform and allowed assembly escapes. The compiler would have to publish its ABI, so you'd know the calling conventions. I'm not aware of any that do, however. But there are several compilers available that compile Java directly to native code; it's possible one of them supports something like this without my knowing, or could be extended to do so.

最后,在不同的级别总共有字节code装配的JVM,如茉莉。一个字节code和汇编让你写的机器code表示直接针对的JVM,有时你可以比的javac 编译器可以生成写出更好的code。这是好玩,在任何情况下。

Finally, on a different level altogether, there are bytecode assemblers for the JVM, like Jasmin. A bytecode assembler lets you write "machine code" that targets the JVM directly, and sometimes you can write better code than the javac compiler can generate. It's fun to play with, in any event.

这篇关于code在Java中注入/总成内联?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆