Laan's steps..

Feed Rss

Alchemy直接操作内存

06.08.2009, flash, haxe..., by .

今天搜到一篇文章,讲了alchemy中关于直接操作内存的一些东西:

Compiling inline ABC with Alchemy’s asc.jar, a bit different.

As I posted earlier about Alchemy, one of it’s advantages is the fact that Flash Player 10 has an implementation for actionscript byte code opcodes that are currently not supported within the ActionScript API. These opcodes allow for faster access to 1 bytearray inside the player, which you can set by accessing ApplicationDomain.currentDomain.domainMemory.

Strangely enough, that is actually opened up to AS API, presumably to allow for “regular” ActionScript access to the Alchemy memory. The actual opcodes have no ActionScript equivalent though.

Since Alchemy boils C code down to ActionScript, how does it obtain access to these opcodes ? The answer lies in the compiler which comes with Alchemy. The asc.jar in the /bin package allows for so called “inline asm”.  This type of code looks something like the following.

__asm(op(0xD2),op(0xD1),op(0x3A));

This code can be put anywhere, and the opcodes will be added to the abc bytestream. Great huh ? So, ideally, we would just switch out our asc.jar in our Flex install directory, and we could just start doing this. Well. NO.
Compc, which is used for actionscript project compilation isn’t compatible with this special asc.jar. Not too worry, we can get around this, more on that later.

之前也了解一些。正好想做一些flash优化的研究,于是详细读了一下。其实Haxe早就发布了对这些指令支持的API>>

其实就是flash10新增的一些指令(opcode),用来直接读写内存:

//直接操作内存指令
0×35:”storeAn8BitInteger”,
0×36:”storeAn16BitInteger”,
0×37:”storeAn32BitInteger”,
0×38:”storeAn32BitFlout”,
0×39:”storeAn64BitFlout”,
0x3a:”loadAn8BitInteger”,
0x3b:”loadAn16BitInteger”,
0x3c:”loadAn32BitInteger”,
0x3d:”loadAn32BitFlout”,
0x3e:”loadAn64BitFlout”,
0×50:”signExtendFrom1BitTo32″,
0×51:”signExtendFrom8BitTo32″,
0×52:”signExtendFrom16BitTo32″
就是对ApplicationDomain.domainMemory的操作了,应该是虚拟内存了。估计adobe开发这个功能是特意为Alchemy的。对于flash以及flex,目前的编译器还不会生成这些指令。

又涉及到haxe了。这个东西实在太有意思了。可以看看官方页面>>

去年的这个时候研究多一段时间。挺有意思的,特别是它周边的一些应用,很有意思。跳开flash的世界,其实会发现更多的有意思的东西。于是又是心血来潮,下了最新版本,在FlashDevelop IED中配置,然后写了个测试。呵呵,一切都很顺利。呵呵 圆满收工。

Alchemy直接操作内存 有 3 条回应

  1. Alchemy 最终还是工作于 AVM2之上的, 什么内存,什么指令, 都和操作系统没瓜葛….不要妄想耍什么小动作,只不过各你一个更细粒度优化代码的途径, 仅此而已

    回复
  2. 2011-02-10 在 17:35 骷髅小白

    同意楼上

    回复
  3. alchemy工作于avm2上?
    那llvm是什么?

    回复

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>