• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright (C) 2003 Vladimir Roubtsov. All rights reserved.
2  *
3  * This program and the accompanying materials are made available under
4  * the terms of the Common Public License v1.0 which accompanies this distribution,
5  * and is available at http://www.eclipse.org/legal/cpl-v10.html
6  *
7  * $Id: RTCoverageDataPersister.java,v 1.1.2.2 2004/07/16 23:32:03 vlad_r Exp $
8  */
9 package com.vladium.emma.rt;
10 
11 import java.io.File;
12 
13 import com.vladium.emma.IAppConstants;
14 import com.vladium.emma.data.DataFactory;
15 import com.vladium.emma.data.ICoverageData;
16 import com.vladium.logging.Logger;
17 
18 // ----------------------------------------------------------------------------
19 /**
20  * @author Vlad Roubtsov, (C) 2004
21  */
22 abstract
23 class RTCoverageDataPersister
24 {
25     // public: ................................................................
26 
27     // protected: .............................................................
28 
29     // package: ...............................................................
30 
31     /*
32      * Stateless package-private method shared by RT and RTExitHook for coverage
33      * data persistence. This method was moved out of RT class after build 4120
34      * in order to decrease classloading dependency set for RTExitHook
35      * (FR SF978671).
36      */
dumpCoverageData(final ICoverageData cdata, final boolean useSnapshot, final File outFile, final boolean merge)37     static void dumpCoverageData (final ICoverageData cdata, final boolean useSnapshot,
38                                   final File outFile, final boolean merge)
39     {
40         try
41         {
42             if (cdata != null)
43             {
44                 // use method-scoped loggers everywhere in RT:
45                 final Logger log = Logger.getLogger ();
46                 final boolean info = log.atINFO ();
47 
48                 final long start = info ? System.currentTimeMillis () : 0;
49                 {
50                     final ICoverageData cdataView = useSnapshot ? cdata.shallowCopy () : cdata;
51 
52                     synchronized (Object.class) // fake a JVM-global critical section when multilply loaded RT's write to the same file
53                     {
54                         DataFactory.persist (cdataView, outFile, merge);
55                     }
56                 }
57                 if (info)
58                 {
59                     final long end = System.currentTimeMillis ();
60 
61                     log.info ("runtime coverage data " + (merge ? "merged into" : "written to") + " [" + outFile.getAbsolutePath () + "] {in " + (end - start) + " ms}");
62                 }
63             }
64         }
65         catch (Throwable t)
66         {
67             // log
68             t.printStackTrace ();
69 
70             // TODO: do better chaining in JRE 1.4+
71             throw new RuntimeException (IAppConstants.APP_NAME + " failed to dump coverage data: " + t.toString ());
72         }
73     }
74 
75     // private: ...............................................................
76 
77 } // end of class
78 // ----------------------------------------------------------------------------