comparison graal/com.oracle.max.base/src/com/sun/max/profile/ValueMetrics.java @ 4142:bc8527f3071c

Adjust code base to new level of warnings.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Sun, 18 Dec 2011 05:24:06 +0100
parents e233f5660da4
children
comparison
equal deleted inserted replaced
4141:04d21be7a24f 4142:bc8527f3071c
21 * questions. 21 * questions.
22 */ 22 */
23 package com.sun.max.profile; 23 package com.sun.max.profile;
24 24
25 import java.util.*; 25 import java.util.*;
26 import java.util.Arrays;
27 26
28 import com.sun.max.*; 27 import com.sun.max.*;
29 import com.sun.max.profile.Metrics.*; 28 import com.sun.max.profile.Metrics.*;
30 import com.sun.max.program.*; 29 import com.sun.max.program.*;
31 30
110 return missed > 0 ? -1 : 0; 109 return missed > 0 ? -1 : 0;
111 } 110 }
112 111
113 @Override 112 @Override
114 public Map<Integer, Integer> asMap() { 113 public Map<Integer, Integer> asMap() {
115 final Map<Integer, Integer> map = new HashMap<Integer, Integer>(); 114 final Map<Integer, Integer> map = new HashMap<>();
116 for (int i = 0; i != counts.length; ++i) { 115 for (int i = 0; i != counts.length; ++i) {
117 map.put(lowValue + i, counts[i]); 116 map.put(lowValue + i, counts[i]);
118 } 117 }
119 return map; 118 return map;
120 } 119 }
162 return missed > 0 ? -1 : 0; 161 return missed > 0 ? -1 : 0;
163 } 162 }
164 163
165 @Override 164 @Override
166 public Map<Integer, Integer> asMap() { 165 public Map<Integer, Integer> asMap() {
167 final Map<Integer, Integer> map = new HashMap<Integer, Integer>(); 166 final Map<Integer, Integer> map = new HashMap<>();
168 for (int i = 0; i != count.length; ++i) { 167 for (int i = 0; i != count.length; ++i) {
169 map.put(set[i], count[i]); 168 map.put(set[i], count[i]);
170 } 169 }
171 return map; 170 return map;
172 } 171 }
227 226
228 @Override 227 @Override
229 public Map<Integer, Integer> asMap() { 228 public Map<Integer, Integer> asMap() {
230 reduce(); 229 reduce();
231 // TODO: another map implementation might be better. 230 // TODO: another map implementation might be better.
232 final Map<Integer, Integer> map = new HashMap<Integer, Integer>(); 231 final Map<Integer, Integer> map = new HashMap<>();
233 if (values != null) { 232 if (values != null) {
234 for (int i = 0; i < values.length; i++) { 233 for (int i = 0; i < values.length; i++) {
235 map.put(values[i], counts[i]); 234 map.put(values[i], counts[i]);
236 } 235 }
237 } 236 }
352 public static class HashedIntegerDistribution extends IntegerDistribution { 351 public static class HashedIntegerDistribution extends IntegerDistribution {
353 private Map<Integer, Distribution> map; 352 private Map<Integer, Distribution> map;
354 353
355 private Map<Integer, Distribution> map() { 354 private Map<Integer, Distribution> map() {
356 if (map == null) { 355 if (map == null) {
357 map = new HashMap<Integer, Distribution>(); 356 map = new HashMap<>();
358 } 357 }
359 return map; 358 return map;
360 } 359 }
361 360
362 @Override 361 @Override
379 return 0; 378 return 0;
380 } 379 }
381 380
382 @Override 381 @Override
383 public Map<Integer, Integer> asMap() { 382 public Map<Integer, Integer> asMap() {
384 final Map<Integer, Integer> result = new HashMap<Integer, Integer>(); 383 final Map<Integer, Integer> result = new HashMap<>();
385 for (Map.Entry<Integer, Distribution> entry : map().entrySet()) { 384 for (Map.Entry<Integer, Distribution> entry : map().entrySet()) {
386 result.put(entry.getKey(), entry.getValue().total); 385 result.put(entry.getKey(), entry.getValue().total);
387 } 386 }
388 return result; 387 return result;
389 } 388 }
407 406
408 public static class HashedObjectDistribution<T> extends ObjectDistribution<T> { 407 public static class HashedObjectDistribution<T> extends ObjectDistribution<T> {
409 private Map<T, Distribution> map; 408 private Map<T, Distribution> map;
410 private Map<T, Distribution> map() { 409 private Map<T, Distribution> map() {
411 if (map == null) { 410 if (map == null) {
412 map = new IdentityHashMap<T, Distribution>(); 411 map = new IdentityHashMap<>();
413 } 412 }
414 return map; 413 return map;
415 } 414 }
416 415
417 public HashedObjectDistribution() { 416 public HashedObjectDistribution() {
436 return 0; 435 return 0;
437 } 436 }
438 437
439 @Override 438 @Override
440 public Map<T, Integer> asMap() { 439 public Map<T, Integer> asMap() {
441 final Map<T, Integer> result = new IdentityHashMap<T, Integer>(); 440 final Map<T, Integer> result = new IdentityHashMap<>();
442 for (Map.Entry<T, Distribution> entry : map().entrySet()) { 441 for (Map.Entry<T, Distribution> entry : map().entrySet()) {
443 result.put(entry.getKey(), entry.getValue().total); 442 result.put(entry.getKey(), entry.getValue().total);
444 } 443 }
445 return result; 444 return result;
446 } 445 }
484 return missed > 0 ? -1 : 0; 483 return missed > 0 ? -1 : 0;
485 } 484 }
486 485
487 @Override 486 @Override
488 public Map<T, Integer> asMap() { 487 public Map<T, Integer> asMap() {
489 final Map<T, Integer> map = new IdentityHashMap<T, Integer>(); 488 final Map<T, Integer> map = new IdentityHashMap<>();
490 for (int i = 0; i != count.length; ++i) { 489 for (int i = 0; i != count.length; ++i) {
491 map.put(set[i], count[i]); 490 map.put(set[i], count[i]);
492 } 491 }
493 return map; 492 return map;
494 } 493 }
608 607
609 private static <T> ObjectDistribution<T> createObjectDistribution(Approximation approx) { 608 private static <T> ObjectDistribution<T> createObjectDistribution(Approximation approx) {
610 if (approx instanceof FixedApproximation) { 609 if (approx instanceof FixedApproximation) {
611 final FixedApproximation fixedApprox = (FixedApproximation) approx; 610 final FixedApproximation fixedApprox = (FixedApproximation) approx;
612 final T[] values = Utils.cast(fixedApprox.values); 611 final T[] values = Utils.cast(fixedApprox.values);
613 return new FixedSetObjectDistribution<T>(values); 612 return new FixedSetObjectDistribution<>(values);
614 } 613 }
615 if (approx == EXACT) { 614 if (approx == EXACT) {
616 return new HashedObjectDistribution<T>(); 615 return new HashedObjectDistribution<>();
617 } 616 }
618 // default is to use the hashed object distribution 617 // default is to use the hashed object distribution
619 return new HashedObjectDistribution<T>(); 618 return new HashedObjectDistribution<>();
620 } 619 }
621 620
622 /** 621 /**
623 * This is a utility method to create a new object distribution that only records occurrences of 622 * This is a utility method to create a new object distribution that only records occurrences of
624 * objects in the specified set. 623 * objects in the specified set.
626 * @param <T> the type of the objects being profiled 625 * @param <T> the type of the objects being profiled
627 * @param name the name of the metric 626 * @param name the name of the metric
628 * @param set the set of objects for which to record exact profiling information 627 * @param set the set of objects for which to record exact profiling information
629 * @return a new distribution capable of producing an exact profile of the occurence of the specified objects 628 * @return a new distribution capable of producing an exact profile of the occurence of the specified objects
630 */ 629 */
630 @SafeVarargs
631 public static <T> ObjectDistribution<T> newObjectDistribution(String name, T... set) { 631 public static <T> ObjectDistribution<T> newObjectDistribution(String name, T... set) {
632 return newObjectDistribution(name, new FixedApproximation(set)); 632 return newObjectDistribution(name, new FixedApproximation(set));
633 } 633 }
634 634
635 /** 635 /**
723 * 723 *
724 * @param distribution the distribution to wrap in a synchronization 724 * @param distribution the distribution to wrap in a synchronization
725 * @return a synchronized view of the distribution 725 * @return a synchronized view of the distribution
726 */ 726 */
727 public static <T> ObjectDistribution<T> threadSafe(ObjectDistribution<T> distribution) { 727 public static <T> ObjectDistribution<T> threadSafe(ObjectDistribution<T> distribution) {
728 return new ThreadsafeObjectDistribution<T>(distribution); 728 return new ThreadsafeObjectDistribution<>(distribution);
729 } 729 }
730 } 730 }