Package: ThreadState

ThreadState

nameinstructionbranchcomplexitylinemethod
ThreadState(DBGPReader, CPUValue)
M: 0 C: 22
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
init()
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
isPure()
M: 2 C: 5
71%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 1
100%
M: 0 C: 1
100%
isStepping()
M: 2 C: 5
71%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 1
100%
M: 0 C: 1
100%
reschedule(Context, ILexLocation)
M: 0 C: 16
100%
M: 1 C: 5
83%
M: 1 C: 3
75%
M: 0 C: 5
100%
M: 0 C: 1
100%
setAtomic(boolean)
M: 0 C: 16
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
setBreaks(ILexLocation, RootContext, Context)
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
setPure(boolean)
M: 0 C: 16
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 4
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: *
3: *        Copyright (C) 2008 Fujitsu Services Ltd.
4: *
5: *        Author: Nick Battle
6: *
7: *        This file is part of VDMJ.
8: *
9: *        VDMJ is free software: you can redistribute it and/or modify
10: *        it under the terms of the GNU General Public License as published by
11: *        the Free Software Foundation, either version 3 of the License, or
12: *        (at your option) any later version.
13: *
14: *        VDMJ is distributed in the hope that it will be useful,
15: *        but WITHOUT ANY WARRANTY; without even the implied warranty of
16: *        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17: *        GNU General Public License for more details.
18: *
19: *        You should have received a copy of the GNU General Public License
20: *        along with VDMJ. If not, see <http://www.gnu.org/licenses/>.
21: *
22: ******************************************************************************/
23:
24: package org.overture.interpreter.runtime;
25:
26: import java.io.Serializable;
27:
28: import org.overture.ast.intf.lex.ILexLocation;
29: import org.overture.interpreter.debug.DBGPReader;
30: import org.overture.interpreter.scheduler.BasicSchedulableThread;
31: import org.overture.interpreter.scheduler.ISchedulableThread;
32: import org.overture.interpreter.scheduler.InitThread;
33: import org.overture.interpreter.values.CPUValue;
34:
35: /**
36: * A class to hold some runtime information for each thread.
37: */
38:
39: public class ThreadState implements Serializable
40: {
41:         private static final long serialVersionUID = 1L;
42:         public final long threadId;
43:         public final DBGPReader dbgp;
44:         public final CPUValue CPU;
45:
46:         private int atomic = 0; // Don't reschedule if >0
47:         private int pure = 0;        // In a pure operation if >0
48:
49:         public ILexLocation stepline; // Breakpoint stepping values
50:         public RootContext nextctxt;
51:         public Context outctxt;
52:
53:         public ThreadState(DBGPReader dbgp, CPUValue cpu)
54:         {
55:                 this.dbgp = dbgp;
56:                 this.threadId = BasicSchedulableThread.getThread(Thread.currentThread()).getId();
57:                 this.CPU = cpu;
58:                 init();
59:         }
60:
61:         public void init()
62:         {
63:                 setBreaks(null, null, null);
64:         }
65:
66:         public synchronized void setBreaks(ILexLocation stepline,
67:                         RootContext nextctxt, Context outctxt)
68:         {
69:                 this.stepline = stepline;
70:                 this.nextctxt = nextctxt;
71:                 this.outctxt = outctxt;
72:         }
73:
74:         public synchronized boolean isStepping()
75:         {
76:•                return stepline != null;
77:         }
78:
79:         public void reschedule(Context ctxt, ILexLocation location)
80:         {
81:•                if (atomic == 0)
82:                 {
83:                         // Initialization doesn't occur from SchedulableThreads
84:
85:                         ISchedulableThread s = BasicSchedulableThread.getThread(Thread.currentThread());
86:
87:•                        if (s != null && !(s instanceof InitThread))
88:                         {
89:                                 s.step(ctxt, location);
90:                         }
91:                 }
92:         }
93:
94:         public synchronized void setAtomic(boolean atomic)
95:         {
96:•                if (atomic)
97:                 {
98:                         this.atomic++;
99:                 } else
100:                 {
101:                         this.atomic--;
102:                 }
103:         }
104:
105:         /**
106:          * We set the pure mode when calling a function. The thread stays in pure mode until
107:          * the outermost function call returns. Note that operations can only be called in
108:          * this mode if they are also pure.
109:          */
110:         public synchronized void setPure(boolean pure)
111:         {
112:•                if (pure)
113:                 {
114:                         this.pure++;
115:                 }
116:                 else
117:                 {
118:                         this.pure--;
119:                 }
120:         }
121:         
122:         public synchronized boolean isPure()
123:         {
124:•                return pure > 0;
125:         }
126: }