Package: StaticSentinel

StaticSentinel

nameinstructionbranchcomplexitylinemethod
StaticSentinel()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
activating(String, int)
M: 28 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
entering(String, long)
M: 34 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
evalPP(String, Long)
M: 64 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 20 C: 0
0%
M: 1 C: 0
0%
leaving(String, int)
M: 30 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
requesting(String, int)
M: 15 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
stateChanged()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
waiting(String, int, int)
M: 16 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%

Coverage

1: package org.overture.codegen.runtime;
2:
3: import java.lang.reflect.InvocationTargetException;
4: import java.lang.reflect.Method;
5: import java.util.Map;
6:
7: public class StaticSentinel
8: {
9:
10:         static Map<String, Long> m;
11:         static StaticOperationsCounters counter;
12:
13:         // public StaticSentinel(long fnr)
14:         // {
15:         // counter = new StaticOperationsCounters((int)fnr);
16:         // }
17:
18:         public synchronized static void entering(String classname, long fnr)
19:         {
20:                 // int fnr = (int) fnr2; //Here the long value is casted into in to be used as index to the arrays.
21:                 requesting(classname, (int) fnr);// the #req counter is changed to add one to it.
22:                 try
23:                 {
24:•                        if (!evalPP(classname, fnr)) // the first evaluation of the permition predicate.
25:                         {
26:                                 waiting(classname, (int) fnr, +1);// if the permission predicate is false. It add one to the #waiting
27:                                                                                                         // counter.
28:•                                while (!evalPP(classname, fnr))// reevaluation of the permission predicate.
29:                                 {
30:                                         Sentinel.class.wait(); // actual thread wait method. This freeze the thread waiting for the
31:                                                                                         // execution of its method.
32:                                 }
33:                                 waiting(classname, (int) fnr, -1); // if predicate changes to true, #waiting is changed to remove one.
34:                         }
35:                 } catch (InterruptedException e)
36:                 {
37:                 }
38:                 activating(classname, (int) fnr);// the #act and the #active counters are change to add one to them
39:         }
40:
41:         // this method is registering the termination of a method.
42:         public synchronized static void leaving(String classname, int fnr2)
43:         {
44:                 int fn = fnr2;
45:                 m.put(classname, StaticOperationsCounters.fin[fn]++);// fin[fn]++; //changes the #fin counter adding one to it.
46:                 m.put(classname, StaticOperationsCounters.active[fn]--); // changes the #active counter removing one to it.
47:                 stateChanged();
48:         }
49:
50:         // this method notifies the threads that a counter has be changed to reevaluate their permission predicates.
51:         public synchronized static void stateChanged()
52:         {
53:                 StaticSentinel.class.notifyAll();
54:         }
55:
56:         // The method that actually changes the #req history counter.
57:         private synchronized static void requesting(String classname, int fn)
58:         {
59:                 m.put(classname, StaticOperationsCounters.req[fn]++);
60:                 stateChanged();
61:         }
62:
63:         // The method that actually changing the #act and #active history counters.
64:         private synchronized static void activating(String classname, int fn)
65:         {
66:                 m.put(classname, StaticOperationsCounters.act[fn]++);
67:                 m.put(classname, StaticOperationsCounters.active[fn]++);
68:                 stateChanged();
69:         }
70:
71:         // The method that actually changing the #waiting history counter.
72:         // The offset defines how many methods of the same name are waiting.
73:         private synchronized static void waiting(String classname, int fnr,
74:                         int offset)
75:         {
76:                 m.put(classname, StaticOperationsCounters.waiting[fnr] += offset);
77:                 stateChanged();
78:         }
79:
80:         public static boolean evalPP(String ClassName, Long fnr)
81:         {
82:                 try
83:                 {
84:                         Class<?> c = Class.forName(ClassName);
85:                         Method m = c.getDeclaredMethod("evaluatePP", Number.class);
86:                         Object o = m.invoke(c.newInstance(), fnr);
87:
88:                         return (Boolean) o;
89:                 } catch (ClassNotFoundException e)
90:                 {
91:                         System.out.println("class not found!!");
92:                 } catch (NoSuchMethodException e)
93:                 {
94:                         System.out.println("method not found!!");
95:                 } catch (SecurityException e)
96:                 {
97:                         System.out.println("alla not found!!");
98:                 } catch (IllegalAccessException e)
99:                 {
100:                         System.out.println("invoke did not work!!");
101:                 } catch (IllegalArgumentException e)
102:                 {
103:                         System.out.println("false arguments!!");
104:                 } catch (InvocationTargetException e)
105:                 {
106:                         System.out.println("invocation target not found!!");
107:                 } catch (InstantiationException e)
108:                 {
109:                         System.out.println("new instance not applied!!");
110:                 }
111:                 return true;
112:         }
113: }