annotate graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/util/NodesToDoubles.java @ 9467:3531cdfddff6

Ensure probabilities are never negative. Add additional assertions.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Wed, 01 May 2013 16:30:52 +0200
parents 8f01fe16e473
children 4278ab23c66f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9234
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents:
diff changeset
1 /*
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents:
diff changeset
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents:
diff changeset
4 *
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents:
diff changeset
7 * published by the Free Software Foundation.
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents:
diff changeset
8 *
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents:
diff changeset
13 * accompanied this code).
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents:
diff changeset
14 *
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents:
diff changeset
18 *
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents:
diff changeset
21 * questions.
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents:
diff changeset
22 */
9238
8f01fe16e473 refactorings and cleanups for the removal of FixedNode.probability
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9234
diff changeset
23 package com.oracle.graal.nodes.util;
9234
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents:
diff changeset
24
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents:
diff changeset
25 import java.util.*;
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents:
diff changeset
26
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents:
diff changeset
27 import com.oracle.graal.nodes.*;
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents:
diff changeset
28
9238
8f01fe16e473 refactorings and cleanups for the removal of FixedNode.probability
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9234
diff changeset
29 public class NodesToDoubles {
9234
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents:
diff changeset
30
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents:
diff changeset
31 private final IdentityHashMap<FixedNode, Double> nodeProbabilities;
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents:
diff changeset
32
9238
8f01fe16e473 refactorings and cleanups for the removal of FixedNode.probability
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9234
diff changeset
33 public NodesToDoubles(int numberOfNodes) {
9234
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents:
diff changeset
34 this.nodeProbabilities = new IdentityHashMap<>(numberOfNodes);
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents:
diff changeset
35 }
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents:
diff changeset
36
9238
8f01fe16e473 refactorings and cleanups for the removal of FixedNode.probability
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9234
diff changeset
37 public void put(FixedNode n, double value) {
9467
3531cdfddff6 Ensure probabilities are never negative. Add additional assertions.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9238
diff changeset
38 assert value >= 0.0;
9234
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents:
diff changeset
39 nodeProbabilities.put(n, value);
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents:
diff changeset
40 }
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents:
diff changeset
41
9238
8f01fe16e473 refactorings and cleanups for the removal of FixedNode.probability
Christian Haeubl <haeubl@ssw.jku.at>
parents: 9234
diff changeset
42 public double get(FixedNode n) {
9234
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents:
diff changeset
43 Double value = nodeProbabilities.get(n);
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents:
diff changeset
44 assert value != null;
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents:
diff changeset
45 return value;
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents:
diff changeset
46 }
b9cf7d0b598e removal of FixedNode.probability (draft)
Christian Haeubl <haeubl@ssw.jku.at>
parents:
diff changeset
47 }