拓胜技术专家教你如何深入理解Java占用内存

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

1/303264&&Java?primitive8byteshortintlongfloatdoublecharboolean12484821long[]data=newlong[1000];8*1000bytesdataObject8*1000ObjectJavajvm/4byte32Objectobj=null;//4byteObject[]objs=newObject[1000];//4*1000byteobjnull4byteobjs,1000null4byteobj==nullObject8byteObjectObjectobj=newObject();//????8byte??!!12byte8byteObjectObjectobj=newObject();12byteObject[]objs=newObject[1000];for(inti=0;i1000;i++){2/30objs[i]=newObject();}12*1000bytesObject12bytes??!!!!Object??or4byte12byteObject12bytes!!Integer16bytesInteger=Object+intpublicclassInteger{publicintvalue;}Integer8+4=12bytesjvmObject!Object812816!Byte16bytes!Byte[]bytes=newByte[1000];?()(16+4)*1000bytes?ObjectlengthpublicclassArray{publicintlength;//...}length3/30publicbyte[]bytes=newbyte[1000];System.out.println(bytes.length);//lengthbytespublicclassArray{publicintlength;publicbytebyte0;publicbytebyte1;...publicbytebyte999;}bytes4+[8+4+1*1000]=4+[1012]=4+1016=10204bytes8Object4length100010001012810161020byte[]bytes=newbyte[4];:4+[8+4+4*1]=4+[16]=20;byte[]bytes=newbyte[3];20ObjectObject(Class)Byte[]bytes=newByte[1000];bytes:publicclassArray{publicintlength;publicBytebyte0;.....publicBytebyte999;}4/304+[8+4+4*1000]+16*1000=4+4016+16000=Byte[]20!classObjectpublicclassAbc{publicintn;publicbyteb;publicObjectobj;}[8+4+1+4]=24Abcone=newAbc()4+24=28Abcobj()publicclassAbc{publicbyteb;publicObjectobj=null;}publicclassDef{publicintn;publicbyteb;publicAbcobj=newAbc();}Defone=newDef();//?4+[8+4+1+4]+[8+1+4]=4+24+16=44publicclassAbc{publicbyteb;publicObjectobj=null;}publicclassDef{publicintn;publicbyteb;publicAbc[]objs=newAbc[100];{5/30for(inti=0;i10;i++){objs[i]=newAbc();}}}Defone=newDef();//?kaoObjectStringStringpublicclassString{privatefinalcharvalue[];privatefinalintoffset;privatefinalintcount;privateinthash;//Defaultto0}char[]String[8+4+4+4+4]=24bytes28bytesStrings=;28bytes!!!!!0String4+24+[8+4+2*length]Strings=;28+16=44Strings=ab28+16=44Strings=abc28+24=52StringStringjvm28char[]String[]s=newString[1000];for(inti=0;i1000;i++){s[i]=newString(abcdefasdjflksadjflkasdfj);}6/3028*10001000!String28,28!primitiveHashtable100String[]+int[]100String[]22hashJava™java.lang.OutOfMemoryErrorOutOfMemoryErrorJavaWindows®Linux®OutOfMemoryErrorAIX®JavaJavaJavaJVMJavaOutOfMemoryErrorJavaOutOfMemoryErrorjavaJavaJavaRuntimeEnvironmentJREJavaJavaCJavajavaJavaJavaJavaJavaOutOfMemoryErrorWindowsLinuxAIXIBM®DeveloperKitforJavaIBMAIXLinuxIBMDeveloperKitforJavaIBM32-bitRuntimeEnvironmentforWindowsCRAM——7/30RAM160x00000xFFFF2^16=655361664KB32390313264464321LinuxWindows1.Intel®x86323236PentiumProx86646448PPC6464POWER550390313231390646464RAMWindowsLinuxWindowsLinux——313264WindowsLinuxRAM/18/301.LinuxWindows32Intelx86324GBPhysicalAddressExtensionPAE3664GBRAMPAE324GB64GB4GB32IntelAddressWindowingExtensionWindows32Linux4GB9/3032Windows2GB2GBWindows/3GB/LARGEADDRESSAWARE3GB1GB32Linux3GB1GBLinuxhugemem4GB-232Windows-10/302.32Windows-332Linux-11/303.32Linux-31Linux3902GB390WindowsDDLLinux.so3GBWindowsx86DLLDLLWindowsNT2GB2GB——3GB2GB3GB3GBWindows/3GB1GBI/O/3GB/3GB324GB64GBJavaJavaLinux12/30OOMWindowsJVMJavaJavaJavaJavaJavaJavaJavaJavaJavaJavaJavaSEJavaJavaRealTimeSpecificationforJavaRTSJGCJavaJava-Xmx-XmsmxmsGC-XmxGCJava(JIT)JITJavaJavaJava13/30gccJITJITJavaJavaJavaJavajava.lang.StringSunJDKpermanentgenerationPermGenJava5IBMJavaJavaPermGenJavaJavaJavajava.lang.ClassLoaderJavajava.lang.ClassJavaJavaJava3bootstrapextensionapplicationjava.lang.StringGCGCJEEJavaServerPages(JSP)WebJSP.jsp——WebJavaJavaSunIBMjava.lang.reflectAPIJavajava.lang.reflect.FieldJavaJavaNativeInterfaceJNI14/30JavaJNIJNIJavaJNIJNICC++JavaJavaJNII/OJNI3JavaJNIJavaJavaJNIGetTypeArrayElementsGetTypeArrayRegionJavaIBMDeveloperKitforJava5.0JavaNIOJava1.4I/O(NIO)I/OJavaI/ONIOByteBufferjava.nio.ByteBuffer.allocateDirect()ByteBufferJavaByteBufferI/O—JavaByteBufferJavaI/OJavaByteBufferJavabyte[]4ByteBuffer15/304.java.nio.ByteBufferByteBufferJavaGCGCJavaJavaByteBuffersJavaJavaJavaJavathread-localstorageJavaJava256KB756KB16/30JavaJavaJavaJavaJavaJavaGCJavaOutOfMemoryErrorJavaJavaJVMI/OJavaJavaJavaJVMJavaJNIOutOfMemoryErrorJavaJavaJavaCREADME.htmlcom.ibm.jtc.demos.NativeMemoryGluttongobbleMemory()mallocAllocated1953546736bytesofnativememorybeforerunningout32WindowsSunIBMJavaLinuxx8617/30LinuxPPC32Linux39031Windowsx86SunJavajavaversion1.5.0_11Java(TM)2RuntimeEnvironment,StandardEdition(build1.5.0_11-b03)JavaHotSpot(TM)ClientVM(build1.5.0_11-b03,mixedmode)IBMJavajavaversion1.5.0Java(TM)2RuntimeEnvironment,StandardEdition(buildpwi32devifx-20071025(SR6b))IBMJ9VM(build2.3,J2RE1.5.0IBMJ92.3WindowsXPx86-32j9vmwi3223-20071007(JITenabled)J9VM-20071004_14218_lHdSMRJIT-20070820_1846ifx1_r8GC-200708_10)JCL-20071025com.ibm.jtc.demos.StartingAThreadUnderNativeStarvationJavaIBMJavaStartingAThreadUnderNativeStarvationAllocated1019394912bytesofnativememorybeforerunningoutJVMDUMP006IProcessingDumpEventsysthrow,detailjava/lang/OutOfMemoryError-PleaseWait.JVMDUMP007IJVMRequestingSnapDumpusing'C:\Snap0001.20080323.182114.5172.trc'JVMDUMP010ISnapDumpwrittentoC:\Snap0001.2

1 / 30
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功