CompilerThreadFactory.java revision 12651:6ef01bd40ce2
1249259Sdim/*
2249259Sdim * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
3249259Sdim * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4249259Sdim *
5249259Sdim * This code is free software; you can redistribute it and/or modify it
6249259Sdim * under the terms of the GNU General Public License version 2 only, as
7249259Sdim * published by the Free Software Foundation.
8249259Sdim *
9249259Sdim * This code is distributed in the hope that it will be useful, but WITHOUT
10249259Sdim * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11249259Sdim * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12249259Sdim * version 2 for more details (a copy is included in the LICENSE file that
13249259Sdim * accompanied this code).
14249259Sdim *
15249259Sdim * You should have received a copy of the GNU General Public License version
16249259Sdim * 2 along with this work; if not, write to the Free Software Foundation,
17249259Sdim * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18249259Sdim *
19249259Sdim * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20249259Sdim * or visit www.oracle.com if you need additional information or have any
21249259Sdim * questions.
22249259Sdim */
23249259Sdimpackage org.graalvm.compiler.core;
24249259Sdim
25249259Sdimimport java.util.concurrent.ThreadFactory;
26249259Sdim
27249259Sdimimport org.graalvm.compiler.debug.DebugConfig;
28249259Sdim
29249259Sdim/**
30249259Sdim * Facility for creating {@linkplain CompilerThread compiler threads}.
31249259Sdim */
32249259Sdimpublic class CompilerThreadFactory implements ThreadFactory {
33249259Sdim
34249259Sdim    /**
35249259Sdim     * Capability to get a thread-local debug configuration for the current thread.
36249259Sdim     */
37263508Sdim    public interface DebugConfigAccess {
38249259Sdim        /**
39263508Sdim         * Get a thread-local debug configuration for the current thread. This will be null if
40263508Sdim         * debugging is disabled.
41263508Sdim         */
42263508Sdim        DebugConfig getDebugConfig();
43249259Sdim    }
44263508Sdim
45263508Sdim    protected final String threadNamePrefix;
46249259Sdim    protected final DebugConfigAccess debugConfigAccess;
47249259Sdim
48263508Sdim    public CompilerThreadFactory(String threadNamePrefix, DebugConfigAccess debugConfigAccess) {
49263508Sdim        this.threadNamePrefix = threadNamePrefix;
50263508Sdim        this.debugConfigAccess = debugConfigAccess;
51263508Sdim    }
52263508Sdim
53249259Sdim    @Override
54249259Sdim    public Thread newThread(Runnable r) {
55249259Sdim        return new CompilerThread(r, threadNamePrefix, debugConfigAccess);
56249259Sdim    }
57249259Sdim}
58249259Sdim