From: <jsa...@us...> - 2008-11-06 22:00:01
|
Revision: 61 http://flexotask.svn.sourceforge.net/flexotask/?rev=61&view=rev Author: jsauerbach Date: 2008-11-06 21:59:58 +0000 (Thu, 06 Nov 2008) Log Message: ----------- Restore correct memory space when there is a system-level error. Modified Paths: -------------- trunk/flexotask/src/com/ibm/realtime/flexotask/system/FlexotaskThreadFactoryImpl.java Modified: trunk/flexotask/src/com/ibm/realtime/flexotask/system/FlexotaskThreadFactoryImpl.java =================================================================== --- trunk/flexotask/src/com/ibm/realtime/flexotask/system/FlexotaskThreadFactoryImpl.java 2008-11-06 21:58:31 UTC (rev 60) +++ trunk/flexotask/src/com/ibm/realtime/flexotask/system/FlexotaskThreadFactoryImpl.java 2008-11-06 21:59:58 UTC (rev 61) @@ -79,44 +79,49 @@ SchedulerWrapper.class.getName(); /* Create the FlexotaskScheduler's memory space */ - long oldSpace = FlexotaskSystemSupport.createMemorySpace(true); - if (oldSpace == 0) { - throw new IllegalStateException("Unable to create scheduler memory space"); - } - - /* Clone the runnables into the scheduler's memory space. Because the target memory space - * has been labelled as a scheduler memory space, the deepClone function will selectively - * suppress the cloning of any object that is already in an Flexotask memory space. This enables - * the scheduler runnables to reach the FlexotaskRoots and FlexotaskIn[Out]putPorts of individual - * within the graph, although it cannot reach any objects on the external heap. Because this clone - * operation isn't essential for testing (although it would be nice to have it to catch subtle errors), - * we don't do it unless we're running in a Flexotask VM. If we did it with simulated deep cloning we - * would require every class used by every scheduler to have deep clone support. - */ - FlexotaskSchedulerRunnable[] clonedRunnables; - if (FlexotaskSystemSupport.isFlexotaskVM()) { - clonedRunnables = (FlexotaskSchedulerRunnable[]) FlexotaskSystemSupport.deepClone(runnables, null); - } else { - clonedRunnables = runnables; - } + Thread[] ans; + try { + long oldSpace = FlexotaskSystemSupport.createMemorySpace(true); + if (oldSpace == 0) { + throw new IllegalStateException("Unable to create scheduler memory space"); + } + + /* Clone the runnables into the scheduler's memory space. Because the target memory space + * has been labelled as a scheduler memory space, the deepClone function will selectively + * suppress the cloning of any object that is already in an Flexotask memory space. This enables + * the scheduler runnables to reach the FlexotaskRoots and FlexotaskIn[Out]putPorts of individual + * within the graph, although it cannot reach any objects on the external heap. Because this clone + * operation isn't essential for testing (although it would be nice to have it to catch subtle errors), + * we don't do it unless we're running in a Flexotask VM. If we did it with simulated deep cloning we + * would require every class used by every scheduler to have deep clone support. + */ + FlexotaskSchedulerRunnable[] clonedRunnables; + if (FlexotaskSystemSupport.isFlexotaskVM()) { + clonedRunnables = (FlexotaskSchedulerRunnable[]) FlexotaskSystemSupport.deepClone(runnables, null); + } else { + clonedRunnables = runnables; + } - /* Pin the locks before passing them to individual runnables */ - FlexotaskValidator.verbosePinObjects(locks, "scheduler locks"); - graph.addPinnedObjects(locks); + /* Pin the locks before passing them to individual runnables */ + FlexotaskValidator.verbosePinObjects(locks, "scheduler locks"); - /* Create the Thread[] answer and its various dependent objects, also in the scheduler heap */ - Thread[] ans = new Thread[runnables.length]; - for (int i = 0; i < ans.length; i++) { - FlexotaskSchedulerRunnable runnable = clonedRunnables[i]; - runnable.setTimerService(timer); - runnable.setSchedulerLocks(locks); - ans[i] = new Thread(new SchedulerWrapper(runnable, tracerFactory.newThreadContext(), graph)); - runnables[i] = runnable; - } + /* Create the Thread[] answer and its various dependent objects, also in the scheduler heap */ + ans = new Thread[runnables.length]; + for (int i = 0; i < ans.length; i++) { + FlexotaskSchedulerRunnable runnable = clonedRunnables[i]; + runnable.setTimerService(timer); + runnable.setSchedulerLocks(locks); + ans[i] = new Thread(new SchedulerWrapper(runnable, tracerFactory.newThreadContext(), graph)); + runnables[i] = runnable; + } + } finally { + /* Restore original memory space */ + FlexotaskSystemSupport.runOnPublicHeap(); + tracerFactory.endThreadCreation(); + } - /* Restore original memory space */ - FlexotaskSystemSupport.restoreMemorySpace(oldSpace); - tracerFactory.endThreadCreation(); + /* Record the new pinned locks in the graph */ + graph.addPinnedObjects(locks); /* return */ return ans; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |