/** * Get the list of memory pool associated with the * given MemoryManagerMXBean. **/ protected String[] getMemoryPools(Object userData, MemoryManagerMXBean mmm, long mmarc) { final String listTag = "JvmMemManager." + mmarc + ".getMemoryPools"; String[] result=null; if (userData instanceof Map) { result = (String[])((Map)userData).get(listTag); if (result != null) return result; } if (mmm!=null) { result = mmm.getMemoryPoolNames(); } if ((result!=null)&&(userData instanceof Map)) { Map<Object, Object> map = Util.cast(userData); map.put(listTag,result); } return result; }
protected void updateTreeMap(TreeMap<SnmpOid, Object> table, Object userData, SnmpTableHandler mmHandler, SnmpTableHandler mpHandler, Map<String, SnmpOid> poolIndexMap) { if (mmHandler instanceof SnmpCachedData) { updateTreeMap(table,userData,(SnmpCachedData)mmHandler, mpHandler,poolIndexMap); return; } SnmpOid mmIndex=null; while ((mmIndex = mmHandler.getNext(mmIndex))!=null) { final MemoryManagerMXBean mmm = (MemoryManagerMXBean)mmHandler.getData(mmIndex); if (mmm == null) continue; updateTreeMap(table,userData,mmm,mmIndex,poolIndexMap); } }
protected void runTest() { List<MemoryManagerMXBean> beans = ManagementFactory.getMemoryManagerMXBeans(); Optional<MemoryManagerMXBean> any = beans .stream() .filter(bean -> CC_MANAGER.equals(bean.getName())) .findAny(); Asserts.assertTrue(any.isPresent(), "Bean not found: " + CC_MANAGER); MemoryManagerMXBean ccManager = any.get(); Asserts.assertNotNull(ccManager, "Found null for " + CC_MANAGER); String names[] = ccManager.getMemoryPoolNames(); for (String name : names) { counters.put(name, counters.containsKey(name) ? counters.get(name) + 1 : 1); } for (BlobType btype : BlobType.getAvailable()) { Asserts.assertEQ(counters.get(btype.getMemoryPool().getName()), 1, "Found unexpected amount of beans for pool " + btype.getMemoryPool().getName()); } Asserts.assertEQ(BlobType.getAvailable().size(), counters.keySet().size(), "Unexpected amount of bean names"); }
protected void updateTreeMap(TreeMap<SnmpOid, Object> table, Object userData, SnmpTableHandler mmHandler, SnmpTableHandler mpHandler, Map poolIndexMap) { if (mmHandler instanceof SnmpCachedData) { updateTreeMap(table,userData,(SnmpCachedData)mmHandler, mpHandler,poolIndexMap); return; } SnmpOid mmIndex=null; while ((mmIndex = mmHandler.getNext(mmIndex))!=null) { final MemoryManagerMXBean mmm = (MemoryManagerMXBean)mmHandler.getData(mmIndex); if (mmm == null) continue; updateTreeMap(table,userData,mmm,mmIndex,poolIndexMap); } }
public String[] getMemoryManagerNames() { /* get the memory managers and check which of them manage this pool */ Iterator<MemoryManagerMXBean> iter = memBean.getMemoryManagerMXBeans() .iterator(); List<String> result = new LinkedList<String>(); while (iter.hasNext()) { MemoryManagerMXBean bean = iter.next(); String[] managedPools = bean.getMemoryPoolNames(); for (int i = 0; i < managedPools.length; i++) { if (managedPools[i].equals(name)) { result.add(bean.getName()); break; } } } return result.toArray(new String[0]); }
/** * Creates the metadata for the * {@link java.lang.management.MemoryManagerMXBean}. For this type of * platform bean the metadata covers : * <ul> * <li>3 attribute * <li>0 constructors * <li>0 operations * <li>0 notifications * </ul> * * @param map */ private static void addMemoryManagerBeanInfo(HashMap<String, MBeanInfo> map) { // Attributes MBeanAttributeInfo[] attributes = new MBeanAttributeInfo[3]; attributes[0] = new MBeanAttributeInfo("MemoryPoolNames", "[Ljava.lang.String;", "MemoryPoolNames", true, false, false); attributes[1] = new MBeanAttributeInfo("Name", String.class.getName(), "Name", true, false, false); attributes[2] = new MBeanAttributeInfo("Valid", Boolean.TYPE.getName(), "Valid", true, false, true); map.put(MemoryManagerMXBean.class.getName(), new MBeanInfo( MemoryManagerMXBeanImpl.class.getName(), MemoryManagerMXBeanImpl.class.getName(), attributes, null, null, null)); }
protected void updateTreeMap(TreeMap<SnmpOid, Object> table, Object userData, SnmpCachedData mmHandler, SnmpTableHandler mpHandler, Map<String, SnmpOid> poolIndexMap) { final SnmpOid[] indexes = mmHandler.indexes; final Object[] datas = mmHandler.datas; final int size = indexes.length; for (int i=size-1; i>-1; i--) { final MemoryManagerMXBean mmm = (MemoryManagerMXBean)datas[i]; if (mmm == null) continue; updateTreeMap(table,userData,mmm,indexes[i],poolIndexMap); } }
public String[] getMemoryManagerNames() { MemoryManagerMXBean[] mgrs = getMemoryManagers(); String[] names = new String[mgrs.length]; for (int i = 0; i < mgrs.length; i++) { names[i] = mgrs[i].getName(); } return names; }
private static void verifyThatMetaspaceMemoryManagerExists() { List<MemoryManagerMXBean> managers = ManagementFactory.getMemoryManagerMXBeans(); for (MemoryManagerMXBean manager : managers) { if (manager.getName().equals("Metaspace Manager")) { return; } } throw new RuntimeException("Expected to find a metaspace memory manager"); }
private final int doMemoryManagerMXBeanTest(MBeanServerConnection mbsc) { int errorCount = 0 ; System.out.println("---- MemoryManagerMXBean") ; try { ObjectName filterName = new ObjectName(ManagementFactory.MEMORY_MANAGER_MXBEAN_DOMAIN_TYPE + ",*"); Set<ObjectName> onSet = mbsc.queryNames(filterName, null); for (Iterator<ObjectName> iter = onSet.iterator(); iter.hasNext(); ) { ObjectName memoryManagerName = iter.next() ; System.out.println("-------- " + memoryManagerName) ; MBeanInfo mbInfo = mbsc.getMBeanInfo(memoryManagerName); System.out.println("getMBeanInfo\t\t" + mbInfo); errorCount += checkNonEmpty(mbInfo); MemoryManagerMXBean memoryManager = null; memoryManager = JMX.newMXBeanProxy(mbsc, memoryManagerName, MemoryManagerMXBean.class) ; System.out.println("getMemoryPoolNames\t\t" + Arrays.deepToString(memoryManager.getMemoryPoolNames())); System.out.println("getName\t\t" + memoryManager.getName()); System.out.println("isValid\t\t" + memoryManager.isValid()); } System.out.println("---- OK\n") ; } catch (Exception e) { Utils.printThrowable(e, true) ; errorCount++ ; System.out.println("---- ERROR\n") ; } return errorCount ; }