53 HashMap<String, Long> numInstancesOfClass = new HashMap<String, Long>();
54 HashMap<String, Long> sizeOfInstances = new HashMap<String, Long>();
55
56 for (RecordedEvent event : objectCountEvents) {
57 String className = Events.assertField(event, "objectClass.name").notEmpty().getValue();
58 long count = Events.assertField(event, "count").atLeast(0L).getValue();
59 long totalSize = Events.assertField(event, "totalSize").atLeast(1L).getValue();
60 System.out.println(className);
61 numInstancesOfClass.put(className, count);
62 sizeOfInstances.put(className, totalSize);
63 }
64 System.out.println(numInstancesOfClass);
65 final String fooArrayName = "[Ljdk/jfr/event/gc/objectcount/Foo;";
66 Asserts.assertTrue(numInstancesOfClass.containsKey(fooArrayName), "Expected an event for the Foo array");
67 Asserts.assertEquals(sizeOfInstances.get(fooArrayName), expectedFooArraySize(Constants.oneMB), "Wrong size of the Foo array");
68 }
69
70 private static long expectedFooArraySize(long count) {
71 boolean runsOn32Bit = System.getProperty("sun.arch.data.model").equals("32");
72 int bytesPerWord = runsOn32Bit ? 4 : 8;
73 int objectHeaderSize = bytesPerWord * 3; // length will be aligned on 64 bits
74 int alignmentInOopArray = runsOn32Bit ? 4 : 0;
75 int ptrSize = bytesPerWord;
76 return objectHeaderSize + alignmentInOopArray + count * ptrSize;
77 }
78 }
|
53 HashMap<String, Long> numInstancesOfClass = new HashMap<String, Long>();
54 HashMap<String, Long> sizeOfInstances = new HashMap<String, Long>();
55
56 for (RecordedEvent event : objectCountEvents) {
57 String className = Events.assertField(event, "objectClass.name").notEmpty().getValue();
58 long count = Events.assertField(event, "count").atLeast(0L).getValue();
59 long totalSize = Events.assertField(event, "totalSize").atLeast(1L).getValue();
60 System.out.println(className);
61 numInstancesOfClass.put(className, count);
62 sizeOfInstances.put(className, totalSize);
63 }
64 System.out.println(numInstancesOfClass);
65 final String fooArrayName = "[Ljdk/jfr/event/gc/objectcount/Foo;";
66 Asserts.assertTrue(numInstancesOfClass.containsKey(fooArrayName), "Expected an event for the Foo array");
67 Asserts.assertEquals(sizeOfInstances.get(fooArrayName), expectedFooArraySize(Constants.oneMB), "Wrong size of the Foo array");
68 }
69
70 private static long expectedFooArraySize(long count) {
71 boolean runsOn32Bit = System.getProperty("sun.arch.data.model").equals("32");
72 int bytesPerWord = runsOn32Bit ? 4 : 8;
73 // length will be in klass-gap on 64 bits, extra field on 32 bits.
74 int objectHeaderSize = bytesPerWord * (runsOn32Bit ? 3 : 2);
75 int alignmentInOopArray = runsOn32Bit ? 4 : 0;
76 int ptrSize = bytesPerWord;
77 return objectHeaderSize + alignmentInOopArray + count * ptrSize;
78 }
79 }
|