网通传世私服发布网 本站提供超变态传奇外传私服,传奇外传私服,传奇世界中变私发服,最新传奇外传私服!
基于浏览器的Linux - ce123的专栏 - 博客频道 - CSDN.NET[30期] 10条PHP编程习惯助你找工作 - 战地日记LAM
文章作者:网通传世私服发布网 文章来源:http://WWW.ZNLKD.COM/ 更新时间:2012-02-23 

What is the expected boot time of Linux with the emulator ?

Here are some figures:

===========================================================================

根据作者的描述,该模拟器的初衷是了解现在 JavaScript 引擎的工作,尤其是 Firefox 4 的 Jaeger Monkey 和 Chrome 的 V8,这个探索的结果,可以被用来:

This PC emulator is written in Javascript. The emulated hardware consists in the following devices:

图1 最新版本(内核版本为3.0.4)

Javascript PC Emulator - FAQ

这是一台完全通过JavaScript写成的、使用QEMU模拟x86指令集的、运行在浏览器(我的FireFox运行正常)上的虚拟机。这台机上面运行着一套2.6.20内核的Linux OS,这里的“运行”和以前一些WebOS或者JavaScript模拟DOS的程序并不是一回事,这里的OS就是完完全全运行在客户端浏览器上的,各种交互并不会传送到服务端或者委派到cmd.exe这些程序上执行,说白了这就是一台这实实在在运行的Linux虚拟机,这台虚拟机的相关信息可以在作者公布的Tech页面看到。也可以自己登录到虚拟机上查一下。

下面是虚拟块设备和本地存储的一些介绍:

Devices

Currently there is no synchronization between the PIT frequency and the real time, so there is a variable drift between the time returned by Linux (try the "date" command) and the real time.

CPU Emulation

Some of the code is inspired from my x86 dynamic translator present in, but there are important differences because here it is an interpreter. The CPU is close to a 486 compatible x86 without FPU. The lack of FPU is not a problem when running Linux as Operating System because it contains a FPU emulator. In order to be able to run Linux, a complete MMU is implemented. The exact restrictions of the emulated CPU are:

    There is no network emulation at this point.

    A troubling thing is that the PC emulator is slower using V8 than Jaeger Monkey (I used the 32 bit version for both). I have no precise explanation yet because I only looked at the Jeager Monkey code so far.

    图2 最新版本(支持本地存储,可以将文件系统镜像保存到本地或上传)

    发现文件系统是用BusyBox做的,可以使用大多数Linux的命令,还可以用tab来自动补全操作时的命令。


    Schematically, the process works in the following way:

    A block device driver is added to the Linux kernel. This allows a user to operate with
    a 'device' written in JavaScript. This device is bound to the virtual machine using the
    same I/O ports as a floppy disk. The device driver itself uses a temporary testing major
    device node, id 250. Theoretically, it allows dynamic device node allocation, but I have
    not tested this.

    On the JavaScript side, a lot of caching occurs because the local storage interface is
    quite slow. I therefore decided to cache the total 'disk' in memory, because it's about
    1M anyway. Writes are cached as well, and are 'flushed' once the driver has transferred
    a complete sector.

    For more details, see the source code.


    Is my privacy respected ?

    Which browser should I use to try the PC emulator ?

    Javascript PC Emulator - News

    Is it possible to emulate a VGA card and all the missing devices to launch say FreeDOS or Windows ?

    Javascript PC Emulator - FAQ

    How can I scroll back in the terminal ?

    Use Ctrl-Up, Ctrl-Down, Ctrl-PageUp and Ctrl-PageDown.

    How can I copy data to the Virtual Machine ?

      To copy binary data, you canit on the PC using (assuming you use Linux):

      Linux distribution

      Javascript PC Emulator - Technical Notes

      By- May 23, 2011

      The UART (serial port) does not support FIFO mode. Perhaps it could help to improve the display speed.

      BrowserHostBoot time (s)
      Firefox 5.0.1Core2 Quad 2.3 GHz4.0
      Firefox 6 betaSamsung Galaxy S232.5

      The disk image is just a ram disk image loaded at boot time. It contains a filesystem generated withcontaining. I added my toy C compilerand my unfinished but usable emacs clone. There is also a small MS-DOS .COM launcher I use to test the 16 bit emulation with a tiny .COM program to compute pi and a small.

        The code is written in pure Javascript using the. A slightly slower fallback mode is implemented for browsers missing this support. For the exact list of supported browsers, see the. In any case, a fast Javascript engine is needed to have good performance.

          图2 另一个版本(可通过clipboard设备在用户和虚拟机中Linux传递信息)

          Is my privacy respected ?

          Yes. What you type in the Virtual Machine stays in your browser. No data is sent back to the server.

          Devices

          Javascript terminal

          Although I could have reused the excellent, I decided to write my own because I was curious to see how it could be done. The main problem is the key handling which is different among browsers and OSes, as described.

          Linux distribution

          I compiled a 2.6.20 Linux kernel (I guess any other version would work provided there is still an FPU emulator). The Linux kernel configuration, patch and the source code of the Linux starter (kind of BIOS) are available:.

          This PC emulator is written in Javascript. The emulated hardware consists in the following devices:

          Is there some source code available ?

          开发者创建了一个虚拟块设备,它能在HTML5本地储存中储存数据,块设备可以分区和格式化。部分源码(),运行方法是点击(http://stud.hro.nl/0814604/jslinuxdemo/emulator.html),登录名为root。

          How can I copy data from the Virtual Machine ?

          Javascript

          I happen to be interested by the implementation of Javascript engines these days - but I don't know yet if I will write my own any time soon ! Anyway, this emulator was a way to learn how to write optimized code for recent Javascript engines, in particular Jaeger Monkey (for Firefox 4) and V8 (for Chrome).

          A clipboard device (seen as/dev/clipboardin the emulator) was added to allow exchange of data between the emulator and the outside world.

          How can I copy data to the Virtual Machine ?

          Javascript terminal

          ===========================================================================


          如何实现的:

          CPU Emulation

          For optimal performance, your browser should support the. Firefox 4.x and Chrome 11 have such support.

          The current version of Chrome 12 beta is reported to have apreventing to run the emulator.

          This project allows the virtual machine to access a persistent block device. This means
          a user can format and partition this device inside it's virtual machine. Because this disk
          is then stored in the HTML5 local storage(存储在HTML5本地存储中), a return to the emulator's web page allows a
          user to reopen the block device. All data stored on the disk can therefore be read again.

          I added some tricks which are not present in QEMU to be more precise when emulating unaligned load/stores at page boundaries. The condition code emulation is also more efficient than the one in QEMU.



          过去的几周对我来说是一段相当复杂的经历。我们公司进行了大裁员,我是其中之一,但却体验到了其中的乐趣。我从来没有被开除过,所以很难不去想得太多。我开始浏览招聘板块,一个全职PHP程序员的职位很吸引人,所以我寄去了简历并获得了面试机会。在面试之间,我和其主要的程序员们在咨询电话中聊了聊,最后他们给我出了一套测试题,其中有一道很耐人寻味。

            找出以下代码的错误之处:
          [php]
          <?function baz($y $z) {
          $x = new Array();
          $x[sales] = 60;
          $x[profit] = 20:
          foreach($x as $key = $value) {
          echo $key+" "+$value+"<BR>";
          }
          }
          [/php]
            你能找到几个呢?

            如果你发现函数参数列表中少了逗号、“new Array()”是不正确的、行末用了冒号而不是分号、foreach中没有用“=>”及用“+”来连接字符串,那恭喜你,你找到了所有的错误,你已经掌握了PHP编程的基础。

            现在我来说说我是怎么冒险岛sf这道题的。我当然也找出了以上这些问题,但我更进一步。比如,你有没有发现在数组索引里没有用引号将字符串括起来?虽然这不会造成严重错误,但这是一个编码错误。另外,你注意到在echo一行它使用了双引号而不是单引号吗?使用了PHP开始标志的缩写形式?并且没有用 “<br/>”而是用了“<BR>”?

            在找出了实际错误后,我又在上面找到的问题后面加了注释。这足够让这份答卷从“正确”转变为“发人深省”了,这也给我的申请加了不少分,所以他们决定聘用我。(但最后我拒绝了,因为我喜欢紧凑的生活节奏,并将自己的PHP 技能奉献给我的客户,而不是一家涉猎电信魔域sf场的公司。我需要一个舞台来大展身手。)

            那么接下来就来看看我写的10条PHP编程习惯吧:

          1、使用单引号括起来的字符串

            当使用双引号来括字符串时,PHP解释器会对其进行变量替换、转义等操作,如“\n”。如果你只想输出一个基本的字符串,就用单引号吧,这样会节省一些资源。当然,如果你需要进行变量替换的,那就必须用双引号了,但其他情况下还是用单引号吧。

          2、字符串的输出

            你认为以下哪一条语句的运行速度最快?

          print "Hi my name is $a. I am $b";
          echo "Hi my name is $a. I am $b";
          echo "Hi my name is ".$a.". I am ".$b;
          echo "Hi my name is ",$a,". I am ",$b;
          echo 'Hi my name is ',$a,'. I am ',$b;

            也许这看起来很奇怪,但事实上最后一条的运行速度是最快的。print比echo要慢,在字符串中进行变量替换时会慢,而连接字符串要比用逗号连接来得慢,最后一句则是第一个习惯的体现。所以,不在字符串中进行变量替换不仅会加快程序运行速度,也会让你的代码在任何语法高亮显示的编辑器中显得更为易懂(变量会被高亮显示出来)。很少人知道echo的参数可以用逗号连接,且速度会比字符串连接要来得快。最后再用上第一个习惯,那这条语句就非常好了。

          3、在数组索引中使用单引号

            正如你在上面的测试题中所看到的,我指出了$x[sales]从严格意义上来说是错误的,索引应该被括起来,即$x['sales']。这是因为PHP 会将没有括起来的索引辨认为“裸”字符串,并把它解释为一个常量。当找不到该常量的定义时,才将其解释为一个字符串,所以这条语句才是可运行的。把索引括起来可以省去这部分工作,如果将来正好要用这一字符串定义常量时也就不会有错误了。我甚至听说这样做要快七倍左右的时间,虽然我没有亲自测试过。更多关于这一话题的讨论,请看PHP手册“数组”一章中的的“数组的能与不能”一节。

          4、不要使用开始标志的缩写形式

            你正在使用这样的符号吗?“<?”是非常糟糕的符号,它会引起与XML解释器的冲突。而且一旦你发布了这些代码,那么使用者就必须修改php.ini文件来打开对此符号的支持。所以实在没有理由去使用这种形式。用“<?php“吧。

          5、尽量不要使用正则表达式

            在进行常规的字符串操作时,尽可能不要去使用正则表达式(preg和ereg系列函数)。str_replace函数要比preg_replace快得多,甚至strtr函数也要比str_replace来得快。省去这些不必要的麻烦吧,你的老板会感谢你的。

          6、不要在循环声明中使用函数

            这个问题不单单出现在PHP中,你可以在其他语言的代码中经常看到:

          差:for($i=0;$i<count($array);$i++){...}

          好:$count=count($array);for($i=0;$i<$count;$i++){...}

            这因该很好解释,但许多人就是想少写一行代码而浪费了系统资源。如果在循环声明中使用了count函数,那每次循环都会调用一次。如果你的循环次数很多,那就会浪费非常多的时间。

          7、永远不要使用register_globals和magic quotes

            这是两个很古老的功能,在当时(十年前)也许是一个好方法,但现在看来并非如此。老版本的PHP在安装时会默认打开这两个功能,这会引起安全漏洞、编程错误及其他的问题,如只有用户输入了数据时才会创建变量等。如今这两个功能都被舍弃了,所以每个程序员都应该避免使用。如果你过去的程序有使用这两项功能,那就尽快将其剔除吧。

          8、一定要对变量进行初始化(这里的“初始化”指的是“声明”——译者注)

            当需要没有初始化的变量,PHP解释器会自动创建一个变量,但依靠这个特性来编程并不是一个好主意。这会造成程序的粗糙,或者使代码变得另人迷惑,因为你需要探寻这个变量是从哪里开始被创建的。另外,对一个没有初始化的变量进行递增操作要比初始化过的来得慢。所以对变量进行初始化会是个不错的主意。

          9、对代码进行注释

            这个问题已经提过很多次了,但再多次也不够。我知道有些地方是不聘用不对代码进行注释的程序员的。我在前一次工作面试后和副总、面试官一起浏览我写的代码,当他们对我所做的代码注释印象深刻,还了解了一下我的这一习惯。一天之后,我得到了这个工作。

            我知道有些自称为PHP大师的人声称自己的代码写得很好,不需要添加什么注释。在我看来,这些人都是垃圾。学一写注释的规范和技巧,熟悉一下phpDocumentor或Doxygen之类的注释辅助软件,都是值得的。

          10、遵循一个编程规范

            关于这一点,是你需要在面试中询问你潜在的老板的,问问他们正在使用什么编程规范。PEAR?Zend?内部规范?要提及你正在使用的编程规范,不管是你自己创建的,还是目前普遍流行的一种。对于PHP这种松松垮垮的语言来说,如果没有一个好的编程规范,那么那些代码就会看起来想一堆垃圾。发臭的,令人作呕的垃圾。一些基本的规范包括空格规范、打括号匹配、命名风格等。这对任何一个追求高质量的代码的人来说都是必须的。

            有人说:“我讨厌你的4个空格的缩进。”我要说,什么?用4个空格来缩进?这比用制表符过占用3个字符的空间。更重要的是,只要是使用比记事本高级的编辑器,你可以自定义制表符的缩进值。所以每个程序员都可以以其最习惯的方式来看代码。可以时设置为4,也可以设置为0(如果你是个受虐狂)。反正我不在乎,但你就是不能用空格来缩进!

            总的来说,我希望以上这些编程习惯可以对你有所帮助。如果你想在面试中留下好印象,只需要一些小细节就可以了。

          When will there be network support ?

          QEMU模拟器项目创始人Fabrice Bellard开发了在JavaScript中运行的模拟器,允许用户在浏览器上(支持Firefox 4和Google Chrome 11)启动Linux。现在,另一位开发者Fabrice Bellard的JS/Linux,允许模拟器启动较新的内核版本linux kernel 3.0.4,同时支持永久储存

          另一个版本的地址为

          Javascript

          How can I scroll back in the terminal ?

            jslinux 简单分析
            jslinux:用JavaScript写出一个PC模拟器,上面运行Linux (The code is written in pure Javascript using Typed Arrays which are available in recent browsers.)
            1、主页面 (http://bellard.org/jslinux/) 很简单,主要调用了 如下两个 js 文件。
            http://bellard.org/jslinux/term.js
            http://bellard.org/jslinux/cpux86.js
            2、term.js 里也没有发现什么特殊的地方;
            3、cpux86.js 使用到一个 load_binary 的函数,查看了一下实现,是通过 XMLHttpRequest 来取如下三个 bin 文件(使用Typed Arrays 操作二进制文件):
            http://bellard.org/jslinux/vmlinux26.bin
            http://bellard.org/jslinux/root.bin
            http://bellard.org/jslinux/linuxstart.bin
            uuencode myfile myfile > myfile.txt
            Then you copymyfile.txtto the Linux VM and uudecode it by doing:
            uudecode < /dev/clipboard

            How can I copy data from the Virtual Machine ?

            The procedure is the reverse of the previous one:
              For binary files, you canuuencodein the VM anduudecodeon the host.

              When will there be network support ?

              It is relatively easy to add a virtual network interface. The problem is to make it communicate with other hosts, so at this point it is not my priority. For example, due to security restrictions, it is only possible to communicate with the web site hosting the VM or with cooperating servers. Moreover, only specific types of network protocols can be handled because no raw TCP connection nor raw UDP packets can be sent due to API restrictions and security reasons.

              Is it possible to emulate a VGA card and all the missing devices to launch say FreeDOS or Windows ?

              Yes, it is possible but since the current VM is quite slow, only old OSes (such as Windows 3 or MSDOS) would be really usable.

              Is there some source code available ?

              In the, an archive is given which explains how to build the various binary images.

              The readable source code of the JS PC emulator itself is not yet available. At this point, any mirroring or redistribution of the code needs my explicit permission.

              What is the expected boot time of Linux with the emulator ?

              What's the use ?

              Which browser should I use to try the PC emulator ?

              The following browsers are officially supported:

                Javascript PC Emulator - News

                  What's the use ?

                  I did it for fun, just because newer Javascript Engines are fast enough to do complicated things. Real use could be:

                    图3 所有支持的命令


                    Javascript PC Emulator - Technical Notes


                    浏览次数:
                    最新文章
                    ·基于浏览器的Linux - ce123的专栏 - 博
                    ·星意志消沉票房接二连三失利的新导演阿
                    ·别让眼睛习惯了泪水
                    ·产品常识-蒲光杰的文章-企博网职业博客
                    ·拉脱维亚战队escalate宣布他们添加
                    ·如果公民社会不强大比如刚才提的媒体万
                    ·技术日志詹鹏的日志 詹鹏的博客-ZOL博客
                    ·地产成温州烫手山芋
                    ·浩鑫发布ION 2迷你主机 厚仅3.3厘米。-
                    ·艾瑞视点:2011Q2腾讯财报显示游戏总收
                    热门文章
                    ·基于浏览器的Linux - ce123的专栏 - 博
                    ·星意志消沉票房接二连三失利的新导演阿
                    ·别让眼睛习惯了泪水
                    ·产品常识-蒲光杰的文章-企博网职业博客
                    ·如果公民社会不强大比如刚才提的媒体万
                    ·拉脱维亚战队escalate宣布他们添加
                    ·技术日志詹鹏的日志 詹鹏的博客-ZOL博客
                    ·地产成温州烫手山芋
                    ·浩鑫发布ION 2迷你主机 厚仅3.3厘米。-
                    ·艾瑞视点:2011Q2腾讯财报显示游戏总收
                    Copyright 2003-2009 网通传世私服发布网 http://WWW.ZNLKD.COM/ All Rights Reserved (注:本站只投放1.76传奇私服)
                    请使用1024*768分辨率浏览本站以达到最佳视觉效果
                    备案号:赣ICP备08001576号