`
iamzealotwang
  • 浏览: 121359 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Alchemy(2)------Understanding Adobe Alchemy

    博客分类:
  • As3
阅读更多

Understanding Adobe Alchemy


Adobe recently announced the first public release of a research project code-named Alchemy . Alchemy is a C/C++ to ActionScript compiler that opens up a huge new world for the Flash platform.

Automata Studios has worked closely with engineers over at Adobe for the past few months testing Alchemy and preparing some public samples. We were very happy to help present the public release at the day 2 keynote of Adobe MAX 2008 earlier this week. You can also see some video of me talking about our work porting Ogg Vorbis using Alchemy on Adobe Labs .

There is currently quite a bit of confusion about Alchemy and this article is a quick attempt to answer the most common questions about the technology. First, let’s look at what Alchemy really is and what it is doing.

One of the main pieces of Alchemy is a new backend to the LLVM compiler infrastructure . LLVM is short for Low Level Virtual Machine. The big idea behind LLVM is that the core LLVM compiler will take code in many different languages and compile it into simple RISC-like instructions that are platform neutral. Then, anyone can write a backend to LLVM that can take LLVMs simple instructions and turn them into actual executables for a given platform. Platforms include x64, ARM, PowerPC, and now ActionScript.

You may notice how much ActionScript stands out in that list. All of the rest of the members are CPUs – not programming languages. In fact, if you manage to stop Alchemy mid-compile (when it has created the ActionScript, but not yet compiled it into a SWF) and look at the ActionScript that it creates it will look like some odd hybrid of ActionScript 3 and assembly language. In fact you’ll even see sections that looks suspiciously like inline assembler. This is because the ActionScript compiler that ships with Alchemy does in fact allow for inline AVM2 byte codes.

Essentially when you compile some C or C++ code with Alchemy the end result is a class that is basically a virtual machine written in ActionScript and AVM2 bytecode. This is also why Alchemy generated SWCs are on the large side – they include everything that C or C++ may need such as the C standard library and POSIX support. For example the stringcho example that ships with Alchemy takes 54 lines of C and spits out 27415 lines of ActionScript. This is also why Alchemy can do things like its built-in “green threads” that let’s you run synchronous C asynchronously inside of the Flash Player.

In addition to the LLVM backend, Alchemy includes a set of scripts that are drop-in replacements for standard development tools like make and autoconf. This allows you to use the standard UNIX-style tool chain to create SWFs and SWCs (and thus easily recompile most existing source with Alchemy). The alc-on and alc-off scripts that ship with Alchemy are in fact swapping the standard tools for the Alchemy tools and vice versa.

The output you get from Alchemy is generally a SWC (you can get just a SWF if you want, but usually it won’t be terribly useful on its own). SWCs created from Alchemy can be used in Flex 3 (as long as the build can target FP10), Flex 4 (“Gumbo” – in public preview) and Flash CS4. While I believe there are some switches to make Alchemy compiled code target Flash Player 9, this should be avoided as there were specific changes made to Flash Player 10 that greatly increase runtime speed.

As you may have guessed by now, once C and C++ code is compiled with Alchemy into a SWF it is subject to all of the rules and limitations of a normal SWF. That means you’re still in the security sandbox, all visual output goes through the display list, and all network and file access goes through the existing classes. Under the surface, when you instantiate your Alchemy compiled library, the code is allocating a nice chunk of memory into a ByteArray. This is how Alchemy takes pointers, malloc, free, etc and makes those concepts work in ActionScript.

Knowing that Alchemy is just spitting out the same AVM2 bytecode that Flash and Flex spit out it is pretty confusing how Alchemy code could be faster than standard ActionScript. In fact, it is not faster across the board – just in specific types of operations and when the length of a task can be used to overcome Alchemy’s intrinsic overhead. Now, that’s not to say that Alchemy compiled code is slouchy by default. In fact, because LLVM does a lot of optimizations, whereas Flash and Flex have no optimization step built into their compilers, Alchemy code manages to overcome a lot of it is overhead just on its own.

Now, what are these operations that Alchemy does so well? Memory access and function calls. Alchemy compiled code utilizes new bytecodes added to FP10 for working with ByteArrays – which as you’ll remember are what make up the “RAM” in Alchemy. Function calls are faster because in ActionScript function calls require that their parameters be “boxed” and “unboxed” into and out of objects for each call. Alchemy code doesn’t have to do this.

All of this speediness can be undone though by jumping back and forth between Alchemy code and regular ActionScript. This process is called marshaling and you’ll want to keep it to a minimum. Marshaling is expensive so you’ll want to try to create calls that stay in the C code as long as possible. You’ll also want to try to limit the number of parameters you’re passing back and forth (it’s actually best to work directly with Alchemy’s “RAM” if possible).

As you can see, Alchemy is very powerful, but it is not some magic bullet. More than anything else Alchemy has the potential to drastically speed up the process of bringing existing C/C++ code to the Flash Platform – something that had to be done line-by-line by hand previously. If the ActionScript wrapper around an Alchemy compiled library is well written to take advantage of Alchemy’s strengths it is even possible to get significant speed improvements (up to an order of magnitude or so) over hand-written ActionScript.

That’s it for now, but I plan on writing more about compiling with Alchemy, using GlueGen (a special language you can use with Alchemy to somewhat automate the task of writing C-to-ActionScript glue code), and utlizing Alchemy-compiled libraries within Flash and Flex.

Finally, let me just give a public “THANK YOU!” and “OMFG U RULEZ!” to Scott Petersen(the father of alchemy), Joe Steele, and all of the other employees at Adobe that made Alchemy happen – it’s simply an awesome tool!

 

转载自:http://www.automatastudios.com/2008/11/21/understanding-adobe-alchemy/

分享到:
评论

相关推荐

    Active_Alchemy-1.1.0-py2-none-any.whl.zip

    标题 "Active_Alchemy-1.1.0-py2-none-any.whl.zip" 提供了关于这个压缩包的关键信息,其中“Active_Alchemy”是软件的名称,版本号为“1.1.0”,“py2”表示它适用于Python 2编程语言,“none”可能指的是该软件包...

    alchemy-annotations-1.4.zip

    2. **注解定义**:Alchemy-annotations定义了一系列自定义注解,如@Inject、@Singleton等,这些都是为了在应用程序中实现依赖注入、状态管理和其他高级功能而设计的。通过这些注解,开发者可以声明式地指定代码的...

    Python库 | alchemy_mock-0.1.0-py2.py3-none-any.whl

    python库。 资源全名:alchemy_mock-0.1.0-py2.py3-none-any.whl

    Laravel开发-alchemy-api

    composer require kriswallsmith/alchemy-api ``` 2. **配置API密钥**:访问IBM Watson官方网站注册账号并获取Alchemy API的API密钥。然后,在Laravel的`config/services.php`文件中添加新的服务配置项,如下: ...

    Python库 | ztfy.alchemy-0.1-py2.5.egg

    资源分类:Python库 所属语言:Python 资源全名:ztfy.alchemy-0.1-py2.5.egg 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059

    Python库 | pyams_alchemy-1.3.0-py3.9.egg

    资源分类:Python库 所属语言:Python 资源全名:pyams_alchemy-1.3.0-py3.9.egg 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059

    PyPI 官网下载 | marvin_wtforms_alchemy-0.16.10-py2.py3-none-any.whl

    标题中的"PyPI 官网下载 | marvin_wtforms_alchemy-0.16.10-py2.py3-none-any.whl"表明我们正在讨论一个从Python Package Index (PyPI) 官方网站获取的软件包。PyPI是Python社区用来存储和分发第三方Python库的地方...

    Flash页游未来新技术:Adobe Alchemy

    ### Flash页游未来新技术:Adobe Alchemy #### Adobe Alchemy 的推出目的与背景 Adobe Alchemy 是一项由 Adobe 公司推出的创新技术,旨在解决网页游戏开发者面临的性能瓶颈问题,并帮助他们利用现有的 C/C++ 代码...

    alchemy-1.0-test-sources.jar

    官方版本,亲测可用

    alchemy-1.0.2-test-sources.jar

    官方版本,亲测可用

    alchemy-1.0.1-test-sources.jar

    官方版本,亲测可用

    alchemy-full小分子结构数据集 - Alchemy 化合物结构分析

    名称:Alchemy 化合物数据集 来源:[29] 参考文献 时间范围:覆盖多个时间点,累计收集202579个样本 特征概览: - 数据规模:包含202579份样本 - 结构特性:每份数据包含平均10.10个节点和10.44个边 - 属性种类:...

    PyPI 官网下载 | WTForms-Alchemy-0.7.3.tar.gz

    在"WTForms-Alchemy-0.7.3.tar.gz"这个压缩包中,包含的是WTForms-Alchemy的0.7.3版本源代码。解压后,你可能会看到以下文件结构: - README.rst: 项目的README文件,通常包含了项目简介、安装指南、使用示例等内容...

    pandas_alchemy-0.0.2-py3-none-any.whl

    Python库是一组预先编写的代码模块,旨在帮助开发者实现特定的编程任务,无需从零开始编写代码。这些库可以包括各种功能,如数学运算、文件操作、数据分析和网络编程等。Python社区提供了大量的第三方库,如NumPy、...

    pandas_alchemy-0.0.1-py3-none-any.whl

    Python库是一组预先编写的代码模块,旨在帮助开发者实现特定的编程任务,无需从零开始编写代码。这些库可以包括各种功能,如数学运算、文件操作、数据分析和网络编程等。Python社区提供了大量的第三方库,如NumPy、...

    alchemy-1.0-sources.jar

    官方版本,亲测可用

    alchemy-1.0.2-sources.jar

    官方版本,亲测可用

    alchemy-1.0.1-sources.jar

    官方版本,亲测可用

Global site tag (gtag.js) - Google Analytics