常用链接

统计

最新评论

#

perl print @

#!/usr/bin/perl
@rocks=qw(ab cd ef gh);
print @rocks; #打印出abcdefgh
print @rocks."\n"; #打印4

posted @ 2009-02-18 15:00 九宝 阅读(331) | 评论 (0)编辑 收藏

关于java的JIT知识(转)

什么是JIT

JIT是just in time,即时编译技术。使用该技术,能够加速java程序的执行速度。下面,就对该技术做个简单的讲解。

首先,我们大家都知道,通常javac将程序源代码编译,转换成java字节码,JVM通过解释字节码将其翻译成对应的机器指令,逐条读入,逐条解释翻译。很显然,经过解释执行,其执行速度必然会比可执行的二进制字节码程序慢。为了提高执行速度,引入了JIT技术。

在运行时JIT会把翻译过的机器码保存起来,已备下次使用,因此从理论上来说,采用该JIT技术可以,可以接近以前纯编译技术。下面我看看,JIT的工作过程。

JIT 编译过程

JIT编译启用时(默认是启用的),JVM读入.class文件解释后,将其发给JIT编译器。JIT编译器将字节码编译成本机机器代码,下图展示了该过程。

什么是JIT

JIT是just in time,即时编译技术。使用该技术,能够加速java程序的执行速度。下面,就对该技术做个简单的讲解。

首先,我们大家都知道,通常javac将程序源代码编译,转换成java字节码,JVM通过解释字节码将其翻译成对应的机器指令,逐条读入,逐条解释翻译。很显然,经过解释执行,其执行速度必然会比可执行的二进制字节码程序慢。为了提高执行速度,引入了JIT技术。

在运行时JIT会把翻译过的机器码保存起来,已备下次使用,因此从理论上来说,采用该JIT技术可以,可以接近以前纯编译技术。下面我看看,JIT的工作过程。

JIT 编译过程

JIT编译启用时(默认是启用的),JVM读入.class文件解释后,将其发给JIT编译器。JIT编译器将字节码编译成本机机器代码,下图展示了该过程。


Graphic

 

通过上面的解释,我们了解了JIT的工作原理及过程,同样也发现了个问题,由于JIT对每条字节码都进行编译,造成了编译过程负担过重。为了避免这种情况,当前的JIT只对经常执行的字节码进行编译,如循环等。

需要说明的是,JIT并不总是奏效,不能期望JIT一定能够加速你代码执行的速度,更糟糕的是她有可能降低代码的执行速度。这取决于你的代码结构,当然很多情况下我们还是能够如愿以偿的。

posted @ 2009-01-13 14:18 九宝 阅读(2126) | 评论 (0)编辑 收藏

[Embedded]嵌入式 Linux 的根文件系统 - rootfs (转)

* 嵌入式系统中主要的存储介质 Flash 是稀有资源,为数不多的 RAM 也是。在嵌入式
系统开发中,开发人员十分珍惜这两种资源,也想出了许多办法解决资源短缺的问题。
* Linux 中,rootfs 是必不可少的。PC 上主要实现有 ramdisk 和直接挂载 HD(
Harddisk,硬盘) 上的根文件系统;嵌入式中一般不从 HD 启动,而是从 Flash 启
动,最简单的方法是将 rootfs load 到 RAM 的 RAMDisk,稍复杂的就是 直接从
Flash 读取的 Cramfs,更复杂的是在 Flash 上分区,并构建 JFFS2 等文件系统。
* RAMDisk 将制作好的 rootfs 压缩后写入 Flash,启动的时候由 Bootloader load 到
RAM,解压缩,然后挂载到 /。这种方法操作简单,但是在 RAM 中的文件系统不是压
缩的,因此需要占用许多嵌入式系统中稀有资源 RAM。
* initrd 是 RAMDisk 的格式,kernel 2.4 之前都是 image-initrd,Kernel 2.5 引入
了 cpio-initrd,大大简化了 Linux 的启动过程,附合 Linux 的基本哲学:Keep it
simple, stupid(KISS). 不过,cpio-initrd 作为新的格式,还没有经过广泛测试,
嵌入式 Linux 中主要采用的还是 image-initrd。
* Cramfs 是 Linus 写的很简单的文件系统,有很好的压缩绿,也可以直接从 Flash 上
运行,不须 load 到 RAM 中,因此节约了 RAM。但是 Cramfs 是只读的,对于需要运
行时修改的目录(如: /etc, /var, /tmp)多有不便,因此,一般将这些目录做成
ramfs 等可写的 fs。
* SquashFS 是对 Cramfs 的增强。突破了 Cramfs 的一些限制,在 Flash 和 RAM 的使
用量方面也具有优势。不过,据开发者介绍,在性能上可能不如 Cramfs。这也是一种
新方法,在嵌入式系统采用之前,需要经过更多的测试。
* XIP(exece-in-place,就地运行) 是一种不须将应用程序 load 到 RAM 就可以运行
的技术,无疑可以减少 RAM 的使用。不过在嵌入式系统我还没有遇到这种技术的使用

posted @ 2008-12-29 16:58 九宝 阅读(891) | 评论 (0)编辑 收藏

ClearCase简单使用 (转)

1. When you come to work, the first thing you need to do is: Create a View
   Command:
 

ct mkview -tag <view_tag> <view_storage_path>

   example:

ct mkview -tag alex_test /net/nj2/

   Other Command:

ct lsview                  list all the views reside in the hosts

ct lsview | grep name      list specified view by name

ct rmview -tag <view_tag>  remove an exist view

2. After you create a vew, you need to Set the View to enter it. Then you are able to see the vob content only when you set the view.

ct setview <view_tag>

Example:

ct setview alex_test

Other Commands

ct pwv                     see which view you are currently in

exit                       quit from current view

3. When you are in a view, you need to set the config spec correctly to pick up the right version of element.

ct catcs                   view your config spec

ct edcs                    edit your config spec by vi editor

Other Commands

ct catcs > filename        Copy your config spec to a file

ct setcs filename          Set your config spec from a file

What doew config spec say ? For example:

element* CHECKEDOUT

element* .../ISGcq00123456/LASTEST

element* BLUETOOTH_00.07.00

element* AP_SIPC.01.32.00

element* AP_IB2.00.38_ARM

element* /main/LATEST

Command

element <file path> <version path>

file path: hello.c, *, /vob/su_java/...

version path: Label or Branch

4. Now you may have a task to do. You have a CR assigned, and you know the baseline version.

  • Set config spec to the baseline version.
  • Create branch type associated with the CR.

ct mkbrtype ISGcq00123456

  • Make branch on the baseline version

ct mkbranch ISGcq00123456 hello.c@@/main/2

   Result: hello.c@@/main/ISGcq00123456/0 is created and checked out(a copy of hello.c in the dir was created and you can edited it. If there is not hello.c in the dir, the clearcase would submit a error).

  • Add a rule to pick up this branch in the config spec, just below the CHECKEDOUT rule.

element* .../ISGcq00123456/LATEST

Accessional:

  • Branch type shall have naming convention designed by every project.
  • Don't want check out:

ct mkbranch -nco ISGcq00123456 hello.c@@/main/2

  • Remove a branch from an element:

ct rmbranch hello.c@@/main/ISGcq00123456.

   Make sure no checked out version on this branch

  • Rename a branch name

ct rename brtype:old_name brtype:new_name

   It will apply to all the created branch.

  • Remove a branch type as well as all the related element branch

ct rmtype -rmall brtype:ISGcq00123456

5. After making your CR branch on the file to be changed, check out the version if it hasn't been checked out(checkout后会产生一个自己的私有文件,你可以自己修改,别人看不到,只有这个文件被checkin后才会放到vobs里).

ct co -nc hello.c@@/main/ISGcq00123456/0

    Then, you are able to edit this file. After you finish the change, check in the file to vob.

ct ci -nc hello.c

    The result is, the element will increase one version on the branch:

hello.c@@/main/ISGcq00123456/1

Accessional
  • A checked out version is only in your view. Other engineer can not see it. If you remove that view, you will lost the checked out version.
  • You can undo checkout by:

ct unco hello.c

  • If a checked version has no change, it can't be checked in. You will get an error message like "The file is identical"
  • An unreserved checked out will not block other people check out the same version. Normally, we just use reserved checkout.
  • You can only check out a file on the branch which has mastership role.
6. If your task is to create a new file, you need to do below steps:
  • Make branch on the directory that you will add the file to

ct mkbranch ISGcq00123456 /vob/su_jave/code/src

  • The directory will be automatically checked out. Then make element in this dir.

ct mkelem -nco hello.c

     Create a folder

ct mkelem -eltype directory test

      Dont check it out, because you need to make the CR branch on this file.

ct mkbranch ISGcq00123456 hello.c

  • Check in this directory. Otherwise, other people can not see your new file.

ct ci -nc /vob/su_java/code/src

Accessional

  • We usually only check in the file, but forget to check in the directory. This will cause the file you created can't be stored in the VOB and can't be seen by other people.
  • Go to the top project folder, use below command to list all checked out files and directories int the current dir and sub dir in your view. It will help you check in all elements.

ct lsco -cview -r

7. Now, your task is ongoing. In coding and testing, you may need to merge your file to other version. below example gives the merge steps:

Example: Merge file from hello.c@@/main/branchfrom/5 to hello.c@@/main/branchto/2

ct co -nc hello.c@@/main/branchto/2

ct merge -to hello.c hello.c@@/main/branchfrom/5

     Usually you may also need to compare two versions

ct diff hello.c hello.c hello.c@@/main/branchfrom/5 hello.c@@/main/branchto/2

     Compare this version from the previous version

ct diff -pre hello.c@@/main/branchto/2

Accessional

  • Use this command to list all versions of an element

ct lsvt hello.c

     include the merge info

ct lsvt -merge hello.c

     Remove a merge arrow:

ct rmmerge hello.c@@/main/branchfrom/5 hello.c@@/main/branchto/2

     Dont do actual merge, just draw a merge line

ct merge -ndata hello.c@@/main/branchfrom/5 hello.c@@/main/branchto/2

In what cases we need merge:

  • Integrate with the code developed by someone else.
  • If baseline version has been incresed, need upermage.
  • Merge for release.

8. If you want to remove an un-use version, use the command

ct rmver hello.c@@/main/branchto/2

     Then the version 2 will be removed, but next time the version will increase from 1 to 3.

     If you want to remove a file, you can use remove name command:

ct rmname hello.c

     Be sure to make branch and check out the current directory before rmove it, just like the steps of make element.

     If you want to rename a file, you can use

ct mv old_name new_name

    

     If you want to create an element link, you can use

ct ln source_file file_link

     (checkout current folder like above)

9. Now you may have completed the task of coding, testing, inspection, and prepare to release it. You need to check your developed version is complied with below rules:

  • Must make branch from the baseline version.
  • Must have up merged your branch if the baseline version is not the LATEST version.
  • All the files and directories have no checkou.

10. How to label the version

     Make the label type:

ct mklbtype BLUETOOTH_00.07.00

     Make label on a version:

ct mklabel BLUETOOTH_00.07.00 hello.c@@/main/branchto/2

     Move a label from the old version to a new version:

ct mklabel -replace BLUETOOTH_00.07.00 hello.c@@/main/branchto/3

     Remove label on a version:

ct rmlabel BLUETOOTH_00.07.00 hello.c@@/main/branchto/3

     Remove the label type

ct rmtype lbtype:BLUETOOTH_00.07.00

11. How to search the reuqired version

     Find all files with the version(.../ISGcq00373766/LATEST) and with no label SAMBA_AP_DSL_BLUETOOTH_00.00.07:

ct find /vob/directory -version 'version(.../ISGcq00373766/LATEST)  && !version(SAMBA_AP_DSL_BLUETOOTH_00.00.07)' -print

     Find all files with the version SAMBA_AP_DSL_BLUETOOTH_00.00.07, and then search STRING in all found files:

ct find .-version 'version(SAMBA_AP_DSL_BLUETOOTH_00.00.07)' -exec 'grep STRING $CLEARCASE_PN'

posted @ 2008-11-12 14:14 九宝 阅读(1216) | 评论 (0)编辑 收藏

cramfs文件系统(转)

1、cramfs的特点

在嵌入式的环境之下,内存和外存资源都需要节约使用。如果使用RAMDISK方式来使用文件系统,那么在系统运行之后,首先要把外存(Flash)上的映像文件解压缩到内存中,构造起RAMDISK环境,才可以开始运行程序。但是它也有很致命的弱点。在正常情况下,同样的代码不仅在外存中占据了空间(以压缩后的形式存在),而且还在内存中占用了更大的空间(以解压缩之后的形式存在),这违背了嵌入式环境下尽量节省资源的要求。

使用cramfs就是一种解决这个问题的方式。cramfs是一个压缩式的文件系统,它并不需要一次性地将文件系统中的所有内容都解压缩到内存之中,而只是在系统需要访问某个位置的数据的时侯,马上计算出该数据在cramfs中的位置,将其实时地解压缩到内存之中,然后通过对内存的访问来获取文件系统中需要读取的数据。cramfs中的解压缩以及解压缩之后的内存中数据存放位置都是由cramfs文件系统本身进行维护的,用户并不需要了解具体的实现过程,因此这种方式增强了透明度,对开发人员来说,既方便,又节省了存储空间。

cramfs拥有以下一些特性:

采用实时解压缩方式,但解压缩的时侯有延迟。

cramfs的数据都是经过处理、打包的,对其进先写操作有一定困难。所以cramfs不支持写操作,这个特性刚好适合嵌入式应用中使用Flash存储文件系统的场合。

在cramfs中,文件最大不能超过16MB。

支持组标识(gid),但是mkcramfs只将gid的低8位保存下来,因此只有这8位是有效的。

支持硬链接。但是cramfs并没有完全处理好,硬链接的文件属性中,链接数仍然为1.

cramfs的目录中,没有“.”和“..”这两项。因此,cramfs中的目录的链接数通常也仅有一个。

cramfs中,不会保存文件的时间戳(timestamps)信息。当然,正在使用的文件由于inode保存在内存中,因此其时间可以暂时地变更为最新时间,但是不会保存到cramfs文件系统中去。

当前版本的cramfs只支持PAGE_CACHE_SIZE为4096的内核。因此,如果发现cramfs不能正常读写的时侯,可以检查一下内核的参数设置。


2、使用cramfs

可以从
http://sourceforge.net/projects/cramfs/下载cramfs-1.1.tar.gz。然后执行

tar zxvf cramfs-1.1.tar.gz

进入解包之后生成cramfs-1.1目录,执行编译命令:

make

编译完成之后,会生成mkcramfs和cramfsck两个工具,其中cramfsck工具是用来创建cramfs文件系统的,而mkcramfs工具则用来进行cramfs文件系统的释放以及检查。

下面是mkcramfs的命令格式:

mkcramfs [-h] [-e edition] [-i file] [-n name] dirname outfile

mkcramfs的各个参数解释如下:

-h:显示帮助信息

-e edition:设置生成的文件系统中的版本号

-i file:将一个文件映像插入这个文件系统之中(只能在Linux2.4.0以后的内核版本中使用)

-n name:设定cramfs文件系统的名字

dirname:指明需要被压缩的整个目录树

outfile:最终输出的文件


cramfsck的命令格式:

cramfsck [-hv] [-x dir] file

cramfsck的各个参数解释如下:

-h:显示帮助信息

-x dir:释放文件到dir所指出的目录中

-v:输出信息更加详细

file:希望测试的目标文件

posted @ 2008-08-14 15:43 九宝 阅读(495) | 评论 (0)编辑 收藏

linux创建2种新文件方式

linux下没有文件后缀来比较文件格式的用法
只有两种文件基于文本格式的sh和可以执行的2进制文件

vi filename
在编辑好你的文件后可以用wq!保存
这样就可以生成一个你以编辑好的文件
还有vim gedit等文件编辑器
也可以用上楼说的生成一个文件

touch filename

posted @ 2008-07-10 15:50 九宝 阅读(255) | 评论 (0)编辑 收藏

Bash Shell-使用内置的set和shopt命令设置bash选项

set -o 打印所以的选项
set -o vi 打开选项
set +o vi 关闭选项

shopt -p 打印所以的选项
shopt -s cdspell打开选项
shopt -u cdspell关闭选项

posted @ 2008-07-10 15:49 九宝 阅读(246) | 评论 (0)编辑 收藏

Shell 运算和进制转换(转)

Shell 运算和进制转换

Shell 提供大量的基本运算操作,在脚本中非常有用。Shell 对您提供的算术表达式求值,执行运算展开式,此时使用得出的结果替换表达式。以下面的格式提供运算表达式:

$(( expression ))
                        

您可以使用 echo 在命令行显示运算展开式的结果,了解其工作情况。现在尝试清单 5 所显示的结果。


清单 5. Bourne Shell 中的运算展开式
                     
                        $ echo $((10+40))
                        50
                        $ echo $((5*(3+3)))
                        30
                        

您还可以将展开式分配给变量。尝试清单 6 所显示的结果。


清单 6. 将运算展开式分配给 Shell 变量
                     
                        $ myvar = 10
                        $ echo $myvar
                        10
                        $ echo $(($myvar-2))
                        8
                        $ myvar = $(($myvar+5))
                        $ echo $myvar
                        15
                        $ result = $(($myvar-10))
                        $ echo $result
                        5
                        $
                        

表 2 列出了在大多数 Bourne 以及与 Bourne 兼容的 Shell中可以使用的运算符。正如上面第二个示例,使用圆括号括起来的语句有更高的优先级。实际上,Shell 算术优先级通常根据 C 语言的规则来确定。


表 2. Shell 条件表达式
运算符 描述
+
-
*
/
% 求余
< 小于(1 代表真,0 代表假)
<= 小于等于(1 代表真,0 代表假)
> 大于(1 代表真,0 代表假)
>= 大于等于(1 代表真,0 代表假)
<< 按位向左移位:将给定的整数或第一个表达式向左移动第二个表达式表示的位数
>> 按位向右移位:将给定的整数或第一个表达式向右移动第二个表达式表示的位数




回页首


使用 Shell 运算进行进制转换

假定在您的脚本中有一些数字,您需要以另外的进制处理这些数字。使用 Shell 运算可以很容易地自动实现这类转换。一种情况是使用 Shell 运算把一个数字从给定的进制转换位十进制。如果数字以运算展开式的形式提供,那么假定它带有十进制符号,除非 它前面带有 0(这种情况假定是八进制)或 0x(这种情况假定是十六进制)。键入以下内容以得到一些八进制和十六进制值的十进制输出:

$ echo $((013))
                        $ echo $((0xA4))
                                        

您还可以使用以下格式指定 2 到 64 之间的任意进制:

$((BASE#NUMBER))
                        

通过在 Shell 提示符后键入清单 7 中所示的行,尝试将二进制、八进制、十六进制以及其他进制的数转换为十进制。


清单 7. 在 Shell 中将任意进制的数以十进制输出
                     
                        echo $((2#1101010))
                        echo $((8#377))
                        echo $((16#D8))
                        echo $((12#10))
                        echo $((36#ZZYY))
                        

使用 bc 进行进制转换

在 Shell 中进行进制转换的另一个诀窍是使用 bc,它是一种任意精度运算语言,大多数 UNIX 安装程序都提供。因为它允许您指定输出进制,所以当您需要以十进制以外的进制输出时,这是一种很好的技术。

bc 的特殊变量 ibaseobase 分别包含用于输入和输出的进制的值。缺省情况下,都被设置为 10。要执行进制转换,需要改变其中的一个或两个值,然后提供一个数字。立即尝试,如清单 8 中所示。


清单 8. 使用 bc 执行进制转换
                     
                        $ bc -ql
                                            10
                        10
                        obase=16
                                            10
                        A
                        ibase=2
                                            10
                        2
                        
                                                 Control-D
                                            
                        $
                        

要快速执行进制转换,可以联合使用 bcecho形成快捷的单命令行程序,将给定的值通过管道传输给 bc。键入清单 9 中显示的内容。


清单 9. Shell 单命令行 bc 程序
                     
                        $ echo 'obase=16; 47' | bc
                        2F
                        $ echo 'obase=10; ibase=16; A03' | bc
                        2563
                        $
                        

警告:当您设置 bc 的输入进制以后,输入 bc 的所有数字都使用该进制,包括您提供用于设置输出进制的数字。因此最好先设置输出进制,否则可能会产生意想不到的结果,如清单 10 中所示。


清单 10. 设置输入和输出进制的先后顺序的重要性
                     
                        $ echo 'ibase=16; obase=10; A' | bc
                        A
                        $ echo 'ibase=16; obase=A; A' | bc
                        10
                        $
                        

posted @ 2008-07-09 14:46 九宝 阅读(1638) | 评论 (0)编辑 收藏

执行shell程序文件有4种方法(转)

执行shell程序文件有4种方法
  (1)#chmod +x file(在/etc/profile中,加入export PATH=${PATH}:~/yourpath,就可以在命令行下直接运行,像执行普通命令一样)
  (2)#sh file
  (3)# . file
  (4)#source file

posted @ 2008-07-08 10:21 九宝 阅读(196) | 评论 (0)编辑 收藏

Bitwise operators and Shift operators

位运算符与逻辑运算符基本相似,不过后者的对象只是表示真和假的二值运算,位运算符的对象则是二进制数。Java语言中字节、字符和整数等都可以转换为二进制,所以位运算符的对象也可以是它们。常见位运算符有:
按位进行与运算 : &
按位进行或运算 : |
按位进行位异运算: ^
按位进行取反运算: ~
按位进行循环左移:<<,运算符左侧对象左移由右侧指定的位数,低位补0,最高位抛弃。带符号的左移位运算相当于对左操作数进行乘2运算。
按位进行循环右移:>>,运算符左侧对象右移由右侧指定的位数,若值为正,在最高位插入0,若值为负,在最高位插入1,即移入的最高位和原最高符号位相同。带符号的右移位运算相当于对左边的运算对象进行除2运算。
按位进行无符号右移:>>>,无论运算符左边的运算对象取值正负,都在高位插入0,即移入位始终补0.
要注意是没有按位进行无符号左移的。位运算符的操作数只能是整数,char,byte,short,
int和long,进行位运算时,总是先将字符型值、字节型值和短整型值转换为整型再进行位运算。位运算符游标的操作数用于指定移动的位数,按规定其不应超过左侧数的进制表示位数。
The bitwise operators allow you to manipulate individual bits in an integral primitive data type.Bitwise operators perform Boolean algebra on the corresponding bits in the two arguments to produce the result. The bitwise operators come from C’s low-level orientation, where you often manipulate hardware
directly and must set the bits in hardware registers. Java was originally designed to be embedded in TV set-top boxes, so this low-level orientation still made sense. However, you probably won’t use the bitwise operators much.
The bitwise AND operator (&) produces a one in the output bit if both input bits are one; otherwise, it produces a zero.
The bitwise OR operator (|) produces a one in the output bit if either input bit is a one and produces a zero only if both input bits are zero.
The bitwise EXCLUSIVE OR, or XOR (^), produces a one in the output bit if one or the other input bit is a one, but not both.
The bitwise NOT (~, also called the ones complement operator) is a unary operator; it takes only one argument. (All other bitwise operators are binary operators.) Bitwise NOT produces the opposite of the input bit—a one if the input bit is zero, a zero if the input bit is one.

posted @ 2008-05-20 13:22 九宝 阅读(366) | 评论 (0)编辑 收藏

仅列出标题
共9页: 上一页 1 2 3 4 5 6 7 8 9 下一页