os.linux: Do not rely on static initialisation order for layouts
authorMatthew Khouzam <matthew.khouzam@ericsson.com>
Wed, 6 Apr 2016 22:14:00 +0000 (18:14 -0400)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Thu, 7 Apr 2016 13:57:19 +0000 (09:57 -0400)
Expose DefaultLayout#getInstance() instead of DefaultLayout#INSTANCE

This solves a weird problem where the layout could be null.

To reproduce this problem, define and run the following test suite:
@RunWith(Suite.class)
@Suite.SuiteClasses({
VirtualMachineAnalysisTest.class,
LttngKernelAnalysisTest.class,
PartialStateSystemTest.class,
StateSystemInMemoryTest.class,
StateSystemFullHistoryTest.class
})
public class TestSuite { }

Change-Id: I772ee0944334283d4b36118001a858322921d98a
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/69864
Reviewed-by: Alexandre Montplaisir <alexmonthy@efficios.com>
Tested-by: Alexandre Montplaisir <alexmonthy@efficios.com>
Reviewed-by: Hudson CI
analysis/org.eclipse.tracecompass.analysis.os.linux.core.tests/stubs/org/eclipse/tracecompass/analysis/os/linux/core/tests/stubs/trace/KernelEventLayoutStub.java
analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/analysis/os/linux/core/trace/DefaultEventLayout.java
analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/analysis/os/linux/core/trace/IKernelAnalysisEventLayout.java

index 4f9a854588b943ec232be9efb90134c15a71493a..37574bd08e167ae3c463f40296dc8d392120bdd3 100644 (file)
@@ -10,7 +10,6 @@
 package org.eclipse.tracecompass.analysis.os.linux.core.tests.stubs.trace;
 
 import org.eclipse.tracecompass.analysis.os.linux.core.trace.DefaultEventLayout;
-import org.eclipse.tracecompass.analysis.os.linux.core.trace.IKernelAnalysisEventLayout;
 
 /**
  * Class to extend to be able to set the event names for the os unit tests.
@@ -26,7 +25,7 @@ public class KernelEventLayoutStub extends DefaultEventLayout {
         super();
     }
 
-    private static final IKernelAnalysisEventLayout INSTANCE = new KernelEventLayoutStub();
+    private static final KernelEventLayoutStub INSTANCE = new KernelEventLayoutStub();
 
     /**
      * Get an instance of this event layout
@@ -36,7 +35,7 @@ public class KernelEventLayoutStub extends DefaultEventLayout {
      *
      * @return The instance
      */
-    public static IKernelAnalysisEventLayout getInstance() {
+    public static synchronized KernelEventLayoutStub getInstance() {
         return INSTANCE;
     }
 
index e34d32cff164cef7d4e2b00fee0b7a9ddcfd3211..6d1d709c691f99cfe17315ca6602589b99fb4845 100644 (file)
@@ -15,6 +15,7 @@ package org.eclipse.tracecompass.analysis.os.linux.core.trace;
 import java.util.Collection;
 
 import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
 
 import com.google.common.collect.ImmutableList;
 
@@ -30,6 +31,26 @@ import com.google.common.collect.ImmutableList;
  */
 public class DefaultEventLayout implements IKernelAnalysisEventLayout {
 
+    private static @Nullable DefaultEventLayout INSTANCE;
+
+    /**
+     * The instance of this event layout
+     *
+     * This object is completely immutable, so no need to create additional
+     * instances via the constructor.
+     *
+     * @return the instance
+     * @since 2.0
+     */
+    public static synchronized DefaultEventLayout getInstance() {
+        DefaultEventLayout inst = INSTANCE;
+        if (inst == null) {
+            inst = new DefaultEventLayout();
+            INSTANCE = inst;
+        }
+        return inst;
+    }
+
     /* Event names */
     private static final String IRQ_HANDLER_ENTRY = "irq_handler_entry"; //$NON-NLS-1$
     private static final String IRQ_HANDLER_EXIT = "irq_handler_exit"; //$NON-NLS-1$
@@ -47,8 +68,7 @@ public class DefaultEventLayout implements IKernelAnalysisEventLayout {
     private static final String SCHED_WAKING = "sched_waking"; //$NON-NLS-1$
     private static final String SCHED_WAKEUP = "sched_wakeup"; //$NON-NLS-1$
     private static final String SCHED_WAKEUP_NEW = "sched_wakeup_new"; //$NON-NLS-1$
-    private static final Collection<String> SCHED_WAKEUP_EVENTS =
-            ImmutableList.of(SCHED_WAKEUP, SCHED_WAKEUP_NEW);
+    private static final Collection<String> SCHED_WAKEUP_EVENTS = ImmutableList.of(SCHED_WAKEUP, SCHED_WAKEUP_NEW);
 
     private static final String SCHED_PROCESS_FORK = "sched_process_fork"; //$NON-NLS-1$
     private static final String SCHED_PROCESS_EXIT = "sched_process_exit"; //$NON-NLS-1$
@@ -96,14 +116,6 @@ public class DefaultEventLayout implements IKernelAnalysisEventLayout {
     protected DefaultEventLayout() {
     }
 
-    /**
-     * The instance of this event layout
-     *
-     * This object is completely immutable, so no need to create additional
-     * instances via the constructor.
-     */
-    static final IKernelAnalysisEventLayout INSTANCE = new DefaultEventLayout();
-
     // ------------------------------------------------------------------------
     // Event names
     // ------------------------------------------------------------------------
@@ -191,6 +203,7 @@ public class DefaultEventLayout implements IKernelAnalysisEventLayout {
     public String eventCompatSyscallExitPrefix() {
         return SYSCALL_EXIT_PREFIX;
     }
+
     /**
      * @since 2.0
      */
index 91feb0fd6c55892c6bf25d137f6b145e603ad206..6ff8fdc0336fb053eb5961552a2d481af06dddad 100644 (file)
@@ -34,7 +34,7 @@ public interface IKernelAnalysisEventLayout {
      * The standard layout, very useful for test vectors that are not kernel
      * based.
      */
-    IKernelAnalysisEventLayout DEFAULT_LAYOUT = DefaultEventLayout.INSTANCE;
+    IKernelAnalysisEventLayout DEFAULT_LAYOUT = DefaultEventLayout.getInstance();
 
     /**
      * Whenever a process appears for the first time in a trace, we assume it
This page took 0.030491 seconds and 5 git commands to generate.