Java Code Examples for sun.jvm.hotspot.memory.Universe

Following code examples demonstrate how to use sun.jvm.hotspot.memory.Universefrom java. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use sun.jvm.hotspot.memory.Universeand various code implementation of this class.

	public void run() {
		VM vm = VM.getVM();
		Universe universe = vm.getUniverse();
		universe.print();
		
	    CollectedHeap heap = universe.heap();
	   
	    if ( heap instanceof GenCollectedHeap ){
	    	System.out.println("This is GenCollectedHeap.");
	    	
	    	GenCollectedHeap genHeap = (GenCollectedHeap) heap;  
	    	System.out.println("Generation:*****************************");
            int gens = genHeap.nGens();
	    	System.out.println("Gens Number:"+gens);
	    	for ( int i=0;i<gens;i++){
	    		System.out.println(genHeap.getGen(i));	
	    	}
	    	System.out.println(genHeap.perm());
	    	
	    	DefNewGeneration defNewGen = (DefNewGeneration)genHeap.getGen(0);
	    	EdenSpace engeSpace = defNewGen.eden();
	    	ContiguousSpace fromSpace = defNewGen.from();
	    	ContiguousSpace toSpace   = defNewGen.to();
	    	System.out.println("****************************************");
	    	
	    }
	} 


    @Override
    public HotSpotSACompressedReferencesResult run(HotSpotServiceabilityAgentContext context,
                                                   NoHotSpotServiceabilityAgentParameter param) {
        try {
            Class<?> universeClass = HotSpotServiceabilityAgentUtil.getUniverseClass();
            Class<?> vmClass = HotSpotServiceabilityAgentUtil.getVmClass();
            VM vm = HotSpotServiceabilityAgentUtil.getVMInstance();

            Method getKlassOopSizeMethod = null;
            Method isCompressedKlassOopsEnabledMethod = null;
            Method getNarrowKlassBaseMethod = null;
            Method getNarrowKlassShiftMethod = null;

            try {
                getKlassOopSizeMethod = vmClass.getMethod("getKlassPtrSize");
                isCompressedKlassOopsEnabledMethod = vmClass.getMethod("isCompressedKlassPointersEnabled");
                getNarrowKlassBaseMethod = universeClass.getMethod("getNarrowKlassBase");
                getNarrowKlassShiftMethod = universeClass.getMethod("getNarrowKlassShift");
            } catch (NoSuchMethodException e) {
            }

            int addressSize = (int) vm.getOopSize();
            int objectAlignment = vm.getObjectAlignmentInBytes();

            int oopSize = vm.getHeapOopSize();
            boolean compressedOopsEnabled = vm.isCompressedOopsEnabled();
            long narrowOopBase = Universe.getNarrowOopBase();
            int narrowOopShift = Universe.getNarrowOopShift();

            

            int klassOopSize = getKlassOopSizeMethod != null ? 
                    (Integer) getKlassOopSizeMethod.invoke(vm) : oopSize;
            boolean compressedKlassOopsEnabled = isCompressedKlassOopsEnabledMethod != null ? 
                    (Boolean) isCompressedKlassOopsEnabledMethod.invoke(vm) : compressedOopsEnabled;
            long narrowKlassBase = getNarrowKlassBaseMethod != null ? 
                    (Long) getNarrowKlassBaseMethod.invoke(null) : narrowOopBase;
            int narrowKlassShift = getNarrowKlassShiftMethod != null ? 
                    (Integer) getNarrowKlassShiftMethod.invoke(null) : narrowOopShift;

            return new HotSpotSACompressedReferencesResult(addressSize, objectAlignment, 
                    oopSize, compressedOopsEnabled, narrowOopBase, narrowOopShift, 
                    klassOopSize, compressedKlassOopsEnabled, narrowKlassBase, narrowKlassShift);
        } catch (Throwable t) {
            throw new RuntimeException(t.getMessage(), t);
        }
    } 

    public void run() {
        VM vm = VM.getVM();
        Universe universe = vm.getUniverse();
        CollectedHeap heap = universe.heap();

        if (heap instanceof ParallelScavengeHeap) {
            ParallelScavengeHeap psHeap = (ParallelScavengeHeap) heap;
            PSYoungGen youngGen = psHeap.youngGen();
            PSOldGen oldGen = psHeap.oldGen();
            MutableSpace edenSpace = youngGen.edenSpace();
            MutableSpace fromSpace = youngGen.fromSpace();
            MutableSpace toSpace = youngGen.toSpace();

            show("ParallelScavengeHeap", psHeap.capacity(), psHeap.used());
            show("  PSYoungGen", youngGen.capacity(), youngGen.used());
            show("    eden space", edenSpace.capacity(), edenSpace.used());
            show("    from space", fromSpace.capacity(), fromSpace.used());
            show("    to space", toSpace.capacity(), toSpace.used());
            show("  PSOldGen", oldGen.capacity(), oldGen.used());
        }

        ObjectHeap objectHeap = vm.getObjectHeap();
        objectHeap.iterate(new HeapPrinter(System.out));
    } 

	public void run() {
		VM vm = VM.getVM();
		Universe universe = vm.getUniverse();
		CollectedHeap heap = universe.heap();
	
		puts("GC heap name: " + heap.kind());		
		if(heap instanceof ParallelScavengeHeap) {
			ParallelScavengeHeap psHeap = (ParallelScavengeHeap)heap;
			PSPermGen perm = psHeap.permGen();
			MutableSpace permObjSpace = perm.objectSpace();
			puts("Perm gen: [" + permObjSpace.bottom() + "," + permObjSpace.end() + ")");
			long permSize = 0;
			for(VM.Flag f : VM.getVM().getCommandLineFlags()) {
				if("PermSize".equals(f.getName())) {
					permSize = Long.parseLong(f.getValue());
					break;
				}
			}
			puts("PermSize: " + permSize);
			
			puts();
			
			ObjectHeap objHeap = vm.getObjectHeap();
			HeapVisitor heapVisitor = new HeapPrinter(System.out);
			objHeap.iteratePerm(heapVisitor);
		}
	} 

        while (true) {
            try {
                Thread.sleep(10000L);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            VM vm = VM.getVM();
            StringBuilder sb = new StringBuilder(500);
            sb.append("CPU: ").append(vm.getCPU()).append("\n");

            Universe universe = vm.getUniverse();
            CollectedHeap heap = universe.heap();

            sb.append("Heap Capacity: ").append(heap.capacity()).append("\n");
            sb.append("Heap Used Capacity: ").append(heap.used()).append("\n");
            JavaThread thread = vm.getThreads().first();
            int threadCnt = 0;
            Map<JavaThreadState,Integer> stateMap = new HashMap<JavaThreadState,Integer>();
            while(thread != null){
                threadCnt++;
                thread.getThreadState();
                Integer cnt = stateMap.get(thread.getThreadState());
                if(cnt == null){
                    cnt = 0;
                }
                stateMap.put(thread.getThreadState(), ++cnt);
                thread = thread.next();
            }
            sb.append("Thread Count: ").append(threadCnt).append("\n");
            sb.append("\t");
            for(Map.Entry<JavaThreadState,Integer> entry : stateMap.entrySet()){
                sb.append(entry.getKey()).append(": ").append(entry.getValue()).append("\t");
            }
            sb.append("\n");
            System.out.println(sb);

        } 

    public void run() {
       VM vm = VM.getVM();
       Universe universe = vm.getUniverse();
        CollectedHeap heap = universe.heap();
        if (heap instanceof ParallelScavengeHeap) {
            ParallelScavengeHeap psHeap = (ParallelScavengeHeap) heap;
            PSYoungGen y = psHeap.youngGen();
            MutableSpace youngObjSpace = y.edenSpace();
            youngCapacity = youngObjSpace.capacity();
            l.debug(youngCapacity);
		    ob.onNext(getYoungCapacity());
			ob.onCompleted();
        }
    } 

        while (true) {
            try {
                Thread.sleep(1000L);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            VM vm = VM.getVM();
            StringBuilder sb = new StringBuilder(500);
            sb.append("CPU: ").append(vm.getCPU()).append("\n");

            Universe universe = vm.getUniverse();
            CollectedHeap heap = universe.heap();

            sb.append("Heap Capacity: ").append(heap.capacity()).append("\n");
            sb.append("Heap Used Capacity: ").append(heap.used()).append("\n");
            JavaThread thread = vm.getThreads().first();
            int threadCnt = 0;
            Map<JavaThreadState,Integer> stateMap = new HashMap<JavaThreadState,Integer>();
            while(thread != null){
                threadCnt++;
                thread.getThreadState();
                Integer cnt = stateMap.get(thread.getThreadState());
                if(cnt == null){
                    cnt = 0;
                }
                stateMap.put(thread.getThreadState(), ++cnt);
                thread = thread.next();
            }
            sb.append("Thread Count: ").append(threadCnt).append("\n");
            sb.append("\t");
            for(Map.Entry<JavaThreadState,Integer> entry : stateMap.entrySet()){
                sb.append(entry.getKey()).append(": ").append(entry.getValue()).append("\t");
            }
            sb.append("\n");

        } 

Advertisement
Advertisement