锘??xml version="1.0" encoding="utf-8" standalone="yes"?> 聽//testMap.htm
I am getting Out of Memory errors, how can I allocate more memory to FishEye?
Since the default memory setting usually is around 64MB or 128MB, you might have to adjust the settings to run a bigger FishEye instance with sufficient memory.
There are a number of different memory errors that the JVM will throw. The most common are listed as follows. After having set the FISHEYE_OPTS and restarting your server, go to Administration > Sys Info/Support > System Info, and check your JVM Input Arguments to ensure that your server is picking up your FISHEYE_OPTS as expected. To solve this error, you will need to add the argument -Xmx1024m to FISHEYE_OPTS, in addition to any argument you use to set the heap size. Often you need to increase the amount of memory allocated to fisheye during the initial scan and period and once this is completed you can reduce back down. FISHEYE_OPTS="-Xms128m -Xmx1024m -XX:MaxPermSize=256m" After having set the FISHEYE_OPTS and restarting your server, go to Administration > Sys Info/Support > System Info, and check your JVM Input Arguments to ensure that your server is picking up your FISHEYE_OPTS as expected.
If you get the error message: java.lang.OutOfMemoryError: PermGen space this means that you have exceeded Java's fixed 64MB block for loading class files. You will need to add the argument -XX:MaxPermSize=256m to FISHEYE_OPTS, in addition to any argument you use to set the heap size. FISHEYE_OPTS="-Xms128m -Xmx512m -XX:MaxPermSize=256m" After having set the FISHEYE_OPTS and restarting your server, go to Administration > Sys Info/Support > System Info, and check your JVM Input Arguments to ensure that your server is picking up your FISHEYE_OPTS as expected. This error occurs when the operating system is unable to create new threads. This is due to the JVM Heap taking up the available RAM.
Big heaps take away from the space that can be allocated for the stack of a new thread
To fix this problem, you should reduce the size of your JVM Heap and also the size of the stack per thread. FISHEYE_OPTS="-Xms128m -Xmx1024m -XX:MaxPermSize=256m -Xss512k" Please refer to this guide as a reference for JVM tuning. After having set the FISHEYE_OPTS and restarting your server, go to Administration > Sys Info/Support > System Info, and check your JVM Input Arguments to ensure that your server is picking up your FISHEYE_OPTS as expected. This error indicates that the JVM took too long to free up memory during its GC process. This error can be thrown from the Parallel or Concurrent collectors. The parallel collector will throw an OutOfMemoryError if too much time is being spent in garbage collection: if more than 98% of the total time is spent in garbage collection and less than 2% of the heap is recovered, an OutOfMemoryError will be thrown. This feature is designed to prevent applications from running for an extended period of time while making little or no progress because the heap is too small. If necessary, this feature can be disabled by adding the option -XX:-UseGCOverheadLimit to the command line. To overcome this issue, you need to make sure that all processes can't allocate more memory than there is system memory. In practice this is impossible to do for all processes. At a minimum you should make sure that all your jvm's do not have a total maximum memory allocation than your normally available system memory. Please refer to this guide for more information. Essentially the native objects does not have enough memory to use. This is usually because you have allocated too much memory to your heap reducing the amount available for native objects. See this article. The solution is to reduce the amount of heap memory you have allocated. For example if you have set -Xmx4096, you should consider reducing this to -Xmx2048m. Remember if you are using a 32bit JVM you cannot allocate more than -Xmx2048m for linux (and even less for windows). Using a 64 bit JVM can resolve this problem, but is not recommended for fisheye/crucible instances (refer to System Requirements). I used to be able to open *.sql files in my Eclipse text editor. For some reason that stopped working this morning: 聽聽聽 Invalid menu handle. 聽聽聽 Problems opening an editor... unable to open external editor. To fix this behavior for ALL files of a certain extension: 聽聽聽 Window > Preferences - ... and on the Preferences Tree: 聽聽聽 General > Editors > File Associations - ... add your File Type extension, for example *.sql ... and finally add your Associated Editor. I chose "internal editors" - "text editor" You can also change the behavior "temporarily" for a single file. Right click the file, click "Open With..." and select the editor...
Array.prototype.remove = function(s) {
for (var i = 0; i < this.length; i++) {
if (s == this[i])
this.splice(i, 1);
}
}
/**
* Simple Map
*
*
* var m = new Map();
* m.put('key','value');
* ...
* var s = "";
* m.each(function(key,value,index){
* s += index+":"+ key+"="+value+"\n";
* });
* alert(s);
*
* @author dewitt
* @date 2008-05-24
*/
function Map() {
/** 瀛樻斁閿殑鏁扮粍(閬嶅巻鐢ㄥ埌) */
this.keys = new Array();
/** 瀛樻斁鏁版嵁 */
this.data = new Object();
/**
* 鏀懼叆涓涓敭鍊煎
* @param {String} key
* @param {Object} value
*/
this.put = function(key, value) {
if(this.data[key] == null){
this.keys.push(key);
}
this.data[key] = value;
};
/**
* 鑾峰彇鏌愰敭瀵瑰簲鐨勫?
* @param {String} key
* @return {Object} value
*/
this.get = function(key) {
return this.data[key];
};
/**
* 鍒犻櫎涓涓敭鍊煎
* @param {String} key
*/
this.remove = function(key) {
this.keys.remove(key);
this.data[key] = null;
};
/**
* 閬嶅巻Map,鎵ц澶勭悊鍑芥暟
*
* @param {Function} 鍥炶皟鍑芥暟 function(key,value,index){..}
*/
this.each = function(fn){
if(typeof fn != 'function'){
return;
}
var len = this.keys.length;
for(var i=0;i<len;i++){
var k = this.keys[i];
fn(k,this.data[k],i);
}
};
/**
* 鑾峰彇閿兼暟緇?綾諱技Java鐨別ntrySet())
* @return 閿煎璞key,value}鐨勬暟緇?
*/
this.entrys = function() {
var len = this.keys.length;
var entrys = new Array(len);
for (var i = 0; i < len; i++) {
entrys[i] = {
key : this.keys[i],
value : this.data[i]
};
}
return entrys;
};
/**
* 鍒ゆ柇Map鏄惁涓虹┖
*/
this.isEmpty = function() {
return this.keys.length == 0;
};
/**
* 鑾峰彇閿煎鏁伴噺
*/
this.size = function(){
return this.keys.length;
};
/**
* 閲嶅啓toString
*/
this.toString = function(){
var s = "{";
for(var i=0;i<this.keys.length;i++,s+=','){
var k = this.keys[i];
s += k+"="+this.data[k];
}
s+="}";
return s;
};
}
function testMap(){
var m = new Map();
m.put('key1','Comtop');
m.put('key2','鍗楁柟鐢電綉');
m.put('key3','鏅柊鑺卞洯');
alert("init:"+m);
m.put('key1','搴鋒嫇鏅?);
alert("set key1:"+m);
m.remove("key2");
alert("remove key2: "+m);
var s ="";
m.each(function(key,value,index){
s += index+":"+ key+"="+value+"\n";
});
alert(s);
}
涓銆佺悆鎷嶅拰鐞冪殑鎬葷粨鏄?.1榪滐紝鐞冩媿姣旂悆璐?鍏冿紝 閭d箞鐞冪殑浠鋒牸鏄灝?錛?br />
浜屻佸鏋?鍙版満鍣ㄧ敤浜?鍒嗛挓鏉ョ敓浜?涓浂浠訛紝閭d箞100鍙版満鍣ㄧ敓浜?00涓浂浠墮渶瑕佺敤澶氬皯鍒嗛挓 錛?br />
涓夈佸湪涓涓箹閲屾湁涓綃囩潯鑾詫紝鐫¤幉鐨勯潰縐瘡澶╂墿澶т竴鍊嶃傚鏋滅潯鑾茶鐩栨暣涓箹闇瑕?8澶╋紝閭d箞瀹冭鐩栧崐涓箹闇瑕佸灝戝ぉ 錛?br />
鐩磋鍛婅瘔鎴戜滑錛?絳旀鍒嗗埆鏄細0 .1鍏冿紝 100鍒嗛挓鍜?4澶┿?緹庡浗鐮旂┒浜哄憳鍚ц繖涓夐亾棰樻販鏉傚湪闂嵎涓10鎵澶у鐨?000澶氬悕鏈鐢熻В絳旓紝 鍙戠幇澶ч儴鍒嗕漢閮藉嚟鐩磋鍥炵瓟銆?浣嗘槸鐩磋鏄敊鐨勩?姝g‘鐨勭瓟妗堝垎鍒槸錛?0.05鍏冦?鍒嗛挓鍜?7澶┿?鎸夌瓟瀵逛竴棰樼殑涓鍒嗚綆楋紝榪欎簺瀛︾敓鐨勫鉤鍧囧垎鍊煎緱1.24鍒嗐傚嵆浣挎槸閭d簺緇欏嚭姝g‘絳旀鐨勪漢錛?寰寰涔熸槸棣栧厛鎯沖埌鐩磋鐨勭瓟妗堬紝 鐒跺悗鎰忚瘑鍒拌繖涓瓟妗堟槸閿欒鐨勶紝 鎵嶆壘鍒拌繚鍙嶇洿瑙夌殑姝g‘絳旀銆傜洿瑙夊叾瀹炴槸涓縐嶆棤鎰忚瘑鐨勬湰鑳藉弽搴旓紝 涓嶇粡鎬濊冨揩閫熷湴鑷彂浜х敓錛屼笉鍙椾漢鐨勫績鐞嗙姸鎬佺殑褰卞搷銆傜悊鎬ф濈淮鍒欓渶瑕佸仛鏈夋剰璇嗙殑鎬濅細琚冦傚弽搴旇鎱㈠緱澶氥傜洿瑙夊鎴戜滑鐨勭敓瀛樿嚦鍏抽噸瑕併?鎴戜滑鐪嬪埌涓寮犺劯錛屼笉鍙兘瑕佺粡榪囨濊冩墠鑳借鯨璁ゅ嚭鏄啛浜猴紱鐪嬪埌涓鍧楃煶澶磋繋闈㈢牳鏉ワ紝 涓嶅彲鑳界瓑鍒版兂璧蜂細琚牳浼ゆ墠韜插紑銆傝繖浜涢兘瑕侀潬鐩磋鍋氬嚭蹇熺殑鑷彂鍙嶅簲銆備絾鏄湪闈復鏇村鏉傜殑闂鏃跺氨闇瑕佺敤鍒扮悊鎬ф濈淮鎵嶈兘瑙e喅銆?br />聽
鍦ㄧ敓媧諱腑鎴戜滑浜ゆ浛浣跨敤榪欎袱濂楁濈淮緋葷粺銆備緥濡傦紝鎴戜滑璁叉瘝璇椂錛岀敤鐨勬槸鐩磋鎬濈淮錛岃岃澶栬鏄敤鐨勬槸鐞嗘ф濈淮錛屽洜姝や笉鍙兘鍍忚姣嶈閭d箞嫻佸埄銆傛垜浠惉鍒版皵璞″憳鐢ㄦ憚姘忔姤鍑烘皵娓╂椂錛屼細鐩磋鎰熷埌姘旀俯鐨勯珮浣庯紝浣嗘槸濡傛灉鍚埌鐨勬槸鍗庢皬娓╁害錛屽氨瑕佺敤鍒扮悊鎬ф濈淮浜嗏斺旂編鍥戒漢鍒欑浉鍙嶏紝閫氳繃鍙嶅鐨勮緇冿紝鏈夊彲鑳借鐞嗘ф濈淮杞寲鎴愮洿瑙夈?渚嬪錛屼漢浠湪瀛﹀紑杞︽椂錛岃闈犵悊鎬ф濈淮榪涜鍒ゆ柇錛屽弽搴旀瘮杈冩參錛屽紑杞︽椂闂撮暱浜嗭紝鍦ㄦ煇縐嶇▼搴︿笂灝辨垚浜嗕竴縐嶆湰鑳斤紝鍏鋒湁閫熷害鐨勫簲鍙樿兘鍔涖?br />
浣嗘槸鏈夋椂瀵瑰悓涓涓棶棰橈紝鐩磋鍜岀悊鎬ф濈淮浼氱粰鍑虹浉浜掑啿紿佺殑絳旀錛岃岀洿瑙夊線寰鎴樿儨鐞嗘э紝浠庤岃浜轟駭鐢熺儲鎭箋?img src ="http://www.tkk7.com/nikita/aggbug/339802.html" width = "1" height = "1" />
絎竴鐐瑰緩璁紝鈥滀笉瑕佹ヤ簬瀵繪壘鈥濄?6宀佺殑 鎵緗楅棬璇達紝鈥滀涪涓滆タ鐨勭涓鍙嶅簲鍙兘鏄炕綆卞掓煖錛屾極鏃犵洰鐨勭殑鑳′貢鎶樿吘錛岃繖鏄緢澶氫漢甯哥姱鐨勯敊璇濄?br />
絎簩鐐瑰緩璁亾鍑轟簡鎵緗楅棬瀵葷墿瀛︾殑綺懼崕銆傗滀笢瑗挎病鏈変涪錛屼涪澶辯殑鏄綘姝e父鐨勬濈淮鈥濄備粬璇達紝鈥滄病鏈変涪澶辯殑涓滃洓錛屽彧鏈変笉浼氭壘鐨勪漢鈥濄傛墍浠ワ紝鎴戜滑涓嶅緱涓嶆帴綰崇涓変釜寤鴻錛岀洸鐩殑鎭愭厡浼氶伄钄芥垜浠殑鐪肩潧銆傚紑濮嬪鎵句箣鍓嶏紝涓瀹氳蹇冩佸鉤鍜岋紝鑷俊婊℃弧銆備笉濡ㄥ厛鍧愪笅鏉ュ枬鑼訛紝鐒跺悗寮濮嬪繖媧匯?br />
寤鴻鍥涘緢綆鍗曪紝 鈥滀笢瑗跨粡甯鎬細鍛嗗湪鏈鍒濈殑鍦版柟錛屸濊繖浣嶅搱寮楀ぇ瀛﹂珮鏉愮敓璇達紝鈥滀綘鏄笉鏄湁瀛樻斁涓滆タ鐨勫浐瀹氬湴鐐癸紵濡傛灉鏈夛紝鍏堟壘閭i噷錛?鍒鐪肩潧宸﹀彸鏈変綘鐨勬濈淮銆傚濂楀彲鑳藉氨鏀懼湪甯哥敤鐨勮。鏋朵笂錛屽瓧鍏稿彲鑳藉氨鏀懼湪涔︽涓娿傗?br />
鑷充簬絎簲鐐瑰緩璁紝澶у鎴栬閮芥湁綾諱技鐨勭粡楠屻傗滃綋浣犲績緇鉤闈欎笅鏉ユ椂錛?浣犳垨璁鎬細濂囪抗鑸殑璁拌搗涓㈠け鐨勪笢瑗褲傜獊鐒惰璧瘋嚜宸辨病鏈変涪錛?鍙槸鏀鵑敊浜嗕綅緗傗?br />
鏈夌殑鏃跺欙紝灝卞儚絎叚鐐瑰緩璁殑閭f牱錛屼綘鍙兘姝e湪鐩村嬀鍕劇殑鐩潃瑕佹壘鐨勪笢瑗匡紝鍗村氨鏄滅湅鈥濅笉瑙併傗滃綋涓涓漢鎬ュ寙鍖嗐佹濈淮澶勪簬楂樺害嬋鍔ㄧ姸鎬佹椂錛?寰堝鏄撴垚涓衡樼潄鐪肩瀻鈥欍傜湅涓嶅埌瑕佹壘鐨勪笢瑗褲傝鍐嶄粩緇嗗湴瀵繪壘涓閬嶃傗?br />
鎵浠ワ紝褰撲綘鍢撮噷鍢熷摑鐫鈥滆濺閽ュ寵鈥濈殑鏃跺欙紝鐗㈣絎竷鐐瑰緩璁?鈥滈伄钄芥晥搴斺濄傝濺閽ュ寵鍏跺疄灝卞湪浣犺涓虹殑鍦版柟錛?鍙笉榪囪鏌愪釜鐗╀綋鐩栦綇浜?銆?br />
鈥滄巰寮浠諱綍鑳介伄鎸′笢瑗跨殑鐗╁搧錛屽鎶ョ焊錛屽鏋滆繕娌℃湁錛岄偅涔堥噰綰崇鍏偣寤鴻銆傗濇湁鐨勪笢瑗垮彧鏄◢寰尓鍔ㄤ簡涓鐐逛綅緗紝铏界劧寰堝皬錛?鍗磋凍浠ヨ浠栦滑閫冪浣犵殑瑙嗙嚎銆?钘忓湪鎵撳瓧鏈轟笅鐨勯搮絎旓紝鏀懼湪鎶藉眽鏈閲岄潰鐨勫伐鍏風瓑絳夈傗滄牴鎹垜浠殑瑙傚療錛屼笢瑗挎尓鍔ㄧ殑璺濈涓嶈秴榪?8鑻卞錛屼互18鑻卞涓哄崐寰勭敾鍦嗭紝 浠旂粏鍦ㄨ繖涓尯鍩熸煡鎵撅紝 鑳滃埄鐨勬鐜囧氨姣旇緝澶с傗?br />
絎節鐐瑰緩璁瘬浜庡父璇嗕箣涓紝褰撲綘涓㈠け涓滆タ鏃訛紝濂藉ソ鎯蟲兂涓㈠湪鍝効銆傗滃綋浣犵簿鐤插姏灝界殑緲婚亶鎵鏈夌殑鍦版柟錛?娌℃湁鍙戠幇铔涗笣椹抗鏃訛紝浣犲緱鍒版渶緇堢殑緇撹錛?涔熷氨鏄鍗佹潯寤鴻錛屼笉鏄綘鐨勯敊銆傛崲鍙ヨ瘽璇達紝灝辨槸鍒漢鍊熶簡浣犵殑闆ㄤ紴錛屽悆浜嗕綘鐨勬補鐐稿湀錛屾嬁璧頒簡浣犵殑杞﹂挜鍖欍傗?br />
鈥滃叾瀹炶繕鏈夌鍗佷竴鐐瑰緩璁紝鈥濇墍緗楅棬璇達紝鈥滄棤璁哄浣曪紝 鏈変簺鏃跺欙紝 鍛借繍浼氶夋嫨鎶婃煇浜涗笢瑗夸粠浣犵殑璐駭涓案涔呯殑鎷胯蛋銆?鎺ュ彈榪欎竴鐐癸紝 鐒跺悗緇х畫鑷繁鐨勭敓媧匯傗?br />
On this page:
Out Of Memory Errors
In the following, you will be required to set your memory settings via your FISHEYE_OPTS Environment Variables.
You will need to restart your server after setting your FISHEYE_OPTS.
OutOfMemoryError: Java Heap Space
If you are running Fisheye/Crucible as a windows service, increasing memory needs to be done in the wrapper.conf file. Refere to the Can Fisheye be run as a Windows Service for instructions.
OutOfMemoryError: PermGen space, or Permanent Generation Size
OutOfMemoryError: unable to create new native thread
For Linux the maximum heap size of the JVM cannot be greater than 2GB. If you only have 2GB RAM in your server, it is not recommended to set the Max size of the JVM that high.
The size of the stack per thread can also contribute to this problem. The stack size can reduce the number of threads that can be created.
The stack size can be changed with the following (example) parameter being added to your FISHEYE_OPTS:OutOfMemoryError: GC overhead limit exceeded
This kind of OutOfMemoryError can be caused if your java process is starting to use swapped memory for its heap. This will cause the JVM to take a lot longer than normal to perform normal GC operations. This can eventually cause a timeout to occur and cause this error.
java.lang.OutOfMemoryError: requested 32756 bytes for ChunkPool::allocate. Out of swap space?
Read the Tuning FishEye page for more detail on adjusting resource limits and performance settings in FishEye.
婧愯嚜 錛?a >http://confluence.atlassian.com/display/FISHEYE/Fix+Out+of+Memory+errors+by+increasing+available+memory#FixOutofMemoryerrorsbyincreasingavailablememory-OutOfMemoryError%3Aunabletocreatenewnativethread,
In today's world, a typical enterprise application will have multiple components and will be distributed across various systems and networks. In Java, everything is represented as objects; if two Java components want to communicate with each other, there needs be a mechanism to exchange data. One way to achieve this is to define your own protocol and transfer an object. This means that the receiving end must know the protocol used by the sender to re-create the object, which would make it very difficult to talk to third-party components. Hence, there needs to be a generic and efficient protocol to transfer the object between components. Serialization is defined for this purpose, and Java components use this protocol to transfer objects.
Figure 1 shows a high-level view of client/server communication, where an object is transferred from the client to the server through serialization.
In order to serialize an object, you need to ensure that the class of the object implements the java.io.Serializable
interface, as shown in Listing 1.
import java.io.Serializable;
class TestSerial implements Serializable {
public byte version = 100;
public byte count = 0;
}
In Listing 1, the only thing you had to do differently from creating a normal class is implement the java.io.Serializable
interface. The Serializable
interface is a marker interface; it declares no methods at all. It tells the serialization mechanism that the class can be serialized.
Now that you have made the class eligible for serialization, the next step is to actually serialize the object. That is done by calling the writeObject()
method of the java.io.ObjectOutputStream
class, as shown in Listing 2.
public static void main(String args[]) throws IOException {
FileOutputStream fos = new FileOutputStream("temp.out");
ObjectOutputStream oos = new ObjectOutputStream(fos);
TestSerial ts = new TestSerial();
oos.writeObject(ts);
oos.flush();
oos.close();
}
Listing 2 stores the state of the TestSerial
object in a file called temp.out
. oos.writeObject(ts);
actually kicks off the serialization algorithm, which in turn writes the object to temp.out
.
To re-create the object from the persistent file, you would employ the code in Listing 3.
public static void main(String args[]) throws IOException {
FileInputStream fis = new FileInputStream("temp.out");
ObjectInputStream oin = new ObjectInputStream(fis);
TestSerial ts = (TestSerial) oin.readObject();
System.out.println("version="+ts.version);
}
In Listing 3, the object's restoration occurs with the oin.readObject()
method call. This method call reads in the raw bytes that we previously persisted and creates a live object that is an exact replica of the original object graph. Because readObject()
can read any serializable object, a cast to the correct type is required.
Executing this code will print version=100
on the standard output.
What does the serialized version of the object look like? Remember, the sample code in the previous section saved the serialized version of the TestSerial
object into the file temp.out
. Listing 4 shows the contents of temp.out
, displayed in hexadecimal. (You need a hexadecimal editor to see the output in hexadecimal format.)
AC ED 00 05 73 72 00 0A 53 65 72 69 61 6C 54 65
73 74 A0 0C 34 00 FE B1 DD F9 02 00 02 42 00 05
63 6F 75 6E 74 42 00 07 76 65 72 73 69 6F 6E 78
70 00 64
If you look again at the actual TestSerial
object, you'll see that it has only two byte members, as shown in Listing 5.
public byte version = 100;
public byte count = 0;
The size of a byte variable is one byte, and hence the total size of the object (without the header) is two bytes. But if you look at the size of the serialized object in Listing 4, you'll see 51 bytes. Surprise! Where did the extra bytes come from, and what is their significance? They are introduced by the serialization algorithm, and are required in order to to re-create the object. In the next section, you'll explore this algorithm in detail.
By now, you should have a pretty good knowledge of how to serialize an object. But how does the process work under the hood? In general the serialization algorithm does the following:
java.lang.object
.
I've written a different example object for this section that will cover all possible cases. The new sample object to be serialized is shown in Listing 6.
class parent implements Serializable {
int parentVersion = 10;
}
class contain implements Serializable{
int containVersion = 11;
}
public class SerialTest extends parent implements Serializable {
int version = 66;
contain con = new contain();
public int getVersion() {
return version;
}
public static void main(String args[]) throws IOException {
FileOutputStream fos = new FileOutputStream("temp.out");
ObjectOutputStream oos = new ObjectOutputStream(fos);
SerialTest st = new SerialTest();
oos.writeObject(st);
oos.flush();
oos.close();
}
}
This example is a straightforward one. It serializes an object of type SerialTest
, which is derived from parent
and has a container object, contain
. The serialized format of this object is shown in Listing 7.
AC ED 00 05 73 72 00 0A 53 65 72 69 61 6C 54 65
73 74 05 52 81 5A AC 66 02 F6 02 00 02 49 00 07
76 65 72 73 69 6F 6E 4C 00 03 63 6F 6E 74 00 09
4C 63 6F 6E 74 61 69 6E 3B 78 72 00 06 70 61 72
65 6E 74 0E DB D2 BD 85 EE 63 7A 02 00 01 49 00
0D 70 61 72 65 6E 74 56 65 72 73 69 6F 6E 78 70
00 00 00 0A 00 00 00 42 73 72 00 07 63 6F 6E 74
61 69 6E FC BB E6 0E FB CB 60 C7 02 00 01 49 00
0E 63 6F 6E 74 61 69 6E 56 65 72 73 69 6F 6E 78
70 00 00 00 0B
Figure 2 offers a high-level look at the serialization algorithm for this scenario.
Let's go through the serialized format of the object in detail and see what each byte represents. Begin with the serialization protocol information:
AC ED
: STREAM_MAGIC
. Specifies that this is a serialization protocol.
00 05
: STREAM_VERSION
. The serialization version.
0x73
: TC_OBJECT
. Specifies that this is a new Object
. The first step of the serialization algorithm is to write the description of the class associated with an instance. The example serializes an object of type SerialTest
, so the algorithm starts by writing the description of the SerialTest
class.
0x72
: TC_CLASSDESC
. Specifies that this is a new class.
00 0A
: Length of the class name.
53 65 72 69 61 6c 54 65 73 74
: SerialTest
, the name of the class.
05 52 81 5A AC 66 02 F6
: SerialVersionUID
, the serial version identifier of this class.
0x02
: Various flags. This particular flag says that the object supports serialization.
00 02
: Number of fields in this class. Next, the algorithm writes the field int version = 66;
.
0x49
: Field type code. 49 represents "I", which stands for Int
.
00 07
: Length of the field name.
76 65 72 73 69 6F 6E
: version
, the name of the field. And then the algorithm writes the next field, contain con = new contain();
. This is an object, so it will write the canonical JVM signature of this field.
0x74
: TC_STRING
. Represents a new string.
00 09
: Length of the string.
4C 63 6F 6E 74 61 69 6E 3B
: Lcontain;
, the canonical JVM signature.
0x78
: TC_ENDBLOCKDATA
, the end of the optional block data for an object. The next step of the algorithm is to write the description of the parent
class, which is the immediate superclass of SerialTest
.
0x72
: TC_CLASSDESC
. Specifies that this is a new class.
00 06
: Length of the class name.
70 61 72 65 6E 74
: SerialTest
, the name of the class
0E DB D2 BD 85 EE 63 7A
: SerialVersionUID
, the serial version identifier of this class.
0x02
: Various flags. This flag notes that the object supports serialization.
00 01
: Number of fields in this class. Now the algorithm will write the field description for the parent
class. parent
has one field, int parentVersion = 100;
.
0x49
: Field type code. 49 represents "I", which stands for Int
.
00 0D
: Length of the field name.
70 61 72 65 6E 74 56 65 72 73 69 6F 6E
: parentVersion
, the name of the field.
0x78
: TC_ENDBLOCKDATA
, the end of block data for this object.
0x70
: TC_NULL
, which represents the fact that there are no more superclasses because we have reached the top of the class hierarchy. So far, the serialization algorithm has written the description of the class associated with the instance and all its superclasses. Next, it will write the actual data associated with the instance. It writes the parent class members first:
00 00 00 0A
: 10, the value of parentVersion
. Then it moves on to SerialTest
.
00 00 00 42
: 66, the value of version
. The next few bytes are interesting. The algorithm needs to write the information about the contain
object, shown in Listing 8.
contain con = new contain();
Remember, the serialization algorithm hasn't written the class description for the contain
class yet. This is the opportunity to write this description.
0x73
: TC_OBJECT
, designating a new object.
0x72
: TC_CLASSDESC
.
00 07
: Length of the class name.
63 6F 6E 74 61 69 6E
: contain
, the name of the class.
FC BB E6 0E FB CB 60 C7
: SerialVersionUID
, the serial version identifier of this class.
0x02
: Various flags. This flag indicates that this class supports serialization.
00 01
: Number of fields in this class. Next, the algorithm must write the description for contain
's only field, int containVersion = 11;
.
0x49
: Field type code. 49 represents "I", which stands for Int
.
00 0E
: Length of the field name.
63 6F 6E 74 61 69 6E 56 65 72 73 69 6F 6E
: containVersion
, the name of the field.
0x78
: TC_ENDBLOCKDATA
. Next, the serialization algorithm checks to see if contain
has any parent classes. If it did, the algorithm would start writing that class; but in this case there is no superclass for contain
, so the algorithm writes TC_NULL
.
0x70
: TC_NULL
. Finally, the algorithm writes the actual data associated with contain
.
00 00 00 0B
: 11, the value of containVersion
. In this tip, you have seen how to serialize an object, and learned how the serialization algorithm works in detail. I hope this article gives you more detail on what happens when you actually serialize an object.
From 聽錛?http://www.javaworld.com/community/node/2915