金麟岂是池中物,一遇风云便化龙
Posts tagged apple
有关64位Snow Leopard
Mar 30th
这篇小tip一直想写,却一直懒得写,今天补上
64位的好处?
谷歌一下你会知道得更多
SL的默认设置?
默认以64位兼容模式启动,即内核为32位,但兼容64位应用程序
如何获知你的内核是跑在32位还是64位下?
打开活动监视器,找到“kernal_task”,看“种类”一列(没有的话加上)是否是“Intel(64位)”
如何知道你的系统是否支持64位?
根据这篇post,可以使用如下命令:
ioreg -l -p IODeviceTree | grep firmware-abi
如何在启动时在32位与64位之间切换?
启动时按住“3”和“2”键或“6”和“4”键(超赞apple这种灵光),但是需要注意,只在本次启动有效,重启后将回到之前的模式
如何使内核一直以64位启动?
根据这篇post,使用如下命令:
nvram boot-args="arch=x86_64"Snow Leopard下的JDK链接有问题
Jan 26th
今天在SL下build JRex,在执行ant make的时候总是出现以下错误:
compile:
[javac] Compiling 86 source files to /Users/ijay/Projects/mozilla/embedding/JRex/classes
[javac] /Users/ijay/Projects/mozilla/embedding/JRex/src/java/netscape/javascript/JSObject.java:38: ?????? sun.plugin.javascript ??????
[javac] import sun.plugin.javascript.JSContext;
[javac] ^
[javac] /Users/ijay/Projects/mozilla/embedding/JRex/src/java/netscape/javascript/JSObject.java:172: ?????? sun.plugin.javascript ??????
[javac] if (c instanceof sun.plugin.javascript.JSContext)
[javac] ^
[javac] /Users/ijay/Projects/mozilla/embedding/JRex/src/java/netscape/javascript/JSObject.java:174: ?Ҳ???????
[javac] ???ţ? ?? JSContext
[javac] λ?ã? ?? netscape.javascript.JSObject
[javac] JSContext j = (JSContext) c;
[javac] ^
[javac] /Users/ijay/Projects/mozilla/embedding/JRex/src/java/netscape/javascript/JSObject.java:174: ?Ҳ???????
[javac] ???ţ? ?? JSContext
[javac] λ?ã? ?? netscape.javascript.JSObject
[javac] JSContext j = (JSContext) c;
[javac] ^
[javac] 4 ????BUILD FAILED
检查了一下build.xml引入的JRex.properties,其中有一行内容如下:
classpath =${build};${java.home}/lib/plugin.jar;${java.home}/lib/deploy.jar;${java.home}/lib/jaws.jar
于是又挨个去找那几个jar包(其中“plugin.jar”最像),最终发现了问题:/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home/lib/plugin.jar(即“${java.home}/lib/plugin.jar”)是一个符号链接,指向“/System/Library/Frameworks/JavaVM.framework/Versions/A/Resources/Deploy.bundle/Contents/Home/lib/plugin2.jar”,而plugin2.jar不存在……
把原先的符号链接删除,重建链接指向…/plugin.jar,问题解决
已向apple提交该bug
Mac OS X的内存管理策略
Nov 25th
参考了apple的这篇官方文档。下面是我看了之后的理解,欢迎大家拍砖
先是有关三种内存空间的定义:
- The active list contains pages that are currently mapped into memory and have been recently accessed.
- The inactive list contains pages that are currently resident in physical memory but have not been accessed recently. These pages contain valid data but may be released from memory at any time.
- The free list contains pages of physical memory that are not associated with any address space of VM object. These pages are available for immediate use by any process that needs them.
然后是内核页换出策略:
Paging Virtual Memory Out
The kernel continuously compares the number of physical pages in the free list against a threshold value. When the number of pages in the free list dips below this threshold, the kernel reclaims physical pages for the free list by swapping inactive pages out of memory. To do this, the kernel iterates all resident pages in the active and inactive lists, performing the following steps:
- If a page in the active list is not recently touched, it is moved to the inactive list.
- If a page in the inactive list is not recently touched, the kernel finds the page’s VM object.
- If the VM object has never been paged before, the kernel calls an initialization routine that creates and assigns a default pager object.
- The VM object’s default pager attempts to write the page out to the backing store.
- If the pager succeeds, the kernel frees the physical memory occupied by the page and moves the page from the inactive to the free list.
即:当free内存小于一个阈值时内核将做页交换,将active内存中最近未使用的内存移入inactive,将inactive中最近未使用的vo交换出去,并释放内存给free
最后是mac下malloc的实质:
Allocating and Accessing Virtual Memory
Applications usually allocate memory using the malloc routine. This routine finds free space on an existing page or allocates new pages using vm_allocate to create space for the new memory block. Through the vm_allocate routine, the kernel performs a series of initialization steps:
- It maps a range of memory in the virtual address space of this process by creating a map entry; the map entry is a simple structure that defines the starting and ending addresses of the region.
- The range of memory is backed by the default pager.
- The kernel creates and initializes a VM object, associating it with the map entry.
At this point there are no pages resident in physical memory and no pages in the backing store. Everything is mapped virtually within the system. When a program accesses the region, by reading or writing to a specific address in it, a fault occurs because that address has not been mapped to physical memory. The kernel also recognizes that the VM object has no backing store for the page on which this address occurs. The kernel then performs the following steps for each page fault:
- It acquires a page from the free list and fills it with zeroes.
- It inserts a reference to this page in the VM object’s list of resident pages.
- It maps the virtual page to the physical page by filling in a data structure called the pmap. The pmap contains the page table used by the processor (or by a separate memory management unit) to map a given virtual address to the actual hardware address.
首先是lazy加载,即调用malloc后只创建vo及其映射,并未真正分配内存。当首次对该vo进行读或写操作时,内核开始分配内存,即从free内存中申请页并清零,并将此页地址记入vo的常驻页中,随后将虚拟地址和物理地址通过pmap结构映射
最终的结论就是:mac系统中的可用内存大小是free + 部分inactive + 部分active,其中“部分inactive”和“部分active”都指“最近未使用的那部分”。而至于“最近使用”的部分应该隐含了两层意义:一、正在被某进程使用;二、之前使用该片内存页的进程已退出,但可能在被降级(active -> inactive,inactive -> free)之前该程序又启动新的进程,重复使用之前的内存页
iTunes Store 中国 已开放注册
Aug 4th
iPhone 3GS vs HTC Hero
Aug 4th
iPhone 3GS vs HTC Hero – Dogfight, Pt 1
iPhone 3GS vs HTC Hero – Dogfight, Pt 2
iPhone 3GS vs HTC Hero – Dogfight, Pt 3








