Skip to content

Commit 4471e4f

Browse files
committed
Revert "Revert "ART: Give JIT thread pool workers a peer""
This reverts commit 9dfb707. Accept a live Java thread for the JIT, and adjust the tests accordingly. Bug: 31684920 Test: m ART_TEST_JIT=true ART_TEST_INTERPRETER=true test-art-host Change-Id: I92cbae1eaae05711b9069335cf1a5f7eb58b9fd8
1 parent b78a8af commit 4471e4f

File tree

5 files changed

+69
-24
lines changed

5 files changed

+69
-24
lines changed

runtime/jit/jit.cc

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,12 @@ Jit::Jit() : dump_info_on_shutdown_(false),
145145
cumulative_timings_("JIT timings"),
146146
memory_use_("Memory used for compilation", 16),
147147
lock_("JIT memory use lock"),
148-
use_jit_compilation_(true) {}
148+
use_jit_compilation_(true),
149+
hot_method_threshold_(0),
150+
warm_method_threshold_(0),
151+
osr_method_threshold_(0),
152+
priority_thread_weight_(0),
153+
invoke_transition_weight_(0) {}
149154

150155
Jit* Jit::Create(JitOptions* options, std::string* error_msg) {
151156
DCHECK(options->UseJitCompilation() || options->GetProfileSaverOptions().IsEnabled());
@@ -289,7 +294,11 @@ bool Jit::CompileMethod(ArtMethod* method, Thread* self, bool osr) {
289294
void Jit::CreateThreadPool() {
290295
// There is a DCHECK in the 'AddSamples' method to ensure the tread pool
291296
// is not null when we instrument.
292-
thread_pool_.reset(new ThreadPool("Jit thread pool", 1));
297+
298+
// We need peers as we may report the JIT thread, e.g., in the debugger.
299+
constexpr bool kJitPoolNeedsPeers = true;
300+
thread_pool_.reset(new ThreadPool("Jit thread pool", 1, kJitPoolNeedsPeers));
301+
293302
thread_pool_->SetPthreadPriority(kJitPoolThreadPthreadPriority);
294303
Start();
295304
}

runtime/runtime.cc

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -672,24 +672,6 @@ bool Runtime::Start() {
672672

673673
started_ = true;
674674

675-
// Create the JIT either if we have to use JIT compilation or save profiling info.
676-
// TODO(calin): We use the JIT class as a proxy for JIT compilation and for
677-
// recoding profiles. Maybe we should consider changing the name to be more clear it's
678-
// not only about compiling. b/28295073.
679-
if (jit_options_->UseJitCompilation() || jit_options_->GetSaveProfilingInfo()) {
680-
std::string error_msg;
681-
if (!IsZygote()) {
682-
// If we are the zygote then we need to wait until after forking to create the code cache
683-
// due to SELinux restrictions on r/w/x memory regions.
684-
CreateJit();
685-
} else if (jit_options_->UseJitCompilation()) {
686-
if (!jit::Jit::LoadCompilerLibrary(&error_msg)) {
687-
// Try to load compiler pre zygote to reduce PSS. b/27744947
688-
LOG(WARNING) << "Failed to load JIT compiler with error " << error_msg;
689-
}
690-
}
691-
}
692-
693675
if (!IsImageDex2OatEnabled() || !GetHeap()->HasBootImageSpace()) {
694676
ScopedObjectAccess soa(self);
695677
StackHandleScope<2> hs(soa.Self());
@@ -714,6 +696,27 @@ bool Runtime::Start() {
714696

715697
Thread::FinishStartup();
716698

699+
// Create the JIT either if we have to use JIT compilation or save profiling info. This is
700+
// done after FinishStartup as the JIT pool needs Java thread peers, which require the main
701+
// ThreadGroup to exist.
702+
//
703+
// TODO(calin): We use the JIT class as a proxy for JIT compilation and for
704+
// recoding profiles. Maybe we should consider changing the name to be more clear it's
705+
// not only about compiling. b/28295073.
706+
if (jit_options_->UseJitCompilation() || jit_options_->GetSaveProfilingInfo()) {
707+
std::string error_msg;
708+
if (!IsZygote()) {
709+
// If we are the zygote then we need to wait until after forking to create the code cache
710+
// due to SELinux restrictions on r/w/x memory regions.
711+
CreateJit();
712+
} else if (jit_options_->UseJitCompilation()) {
713+
if (!jit::Jit::LoadCompilerLibrary(&error_msg)) {
714+
// Try to load compiler pre zygote to reduce PSS. b/27744947
715+
LOG(WARNING) << "Failed to load JIT compiler with error " << error_msg;
716+
}
717+
}
718+
}
719+
717720
// Send the start phase event. We have to wait till here as this is when the main thread peer
718721
// has just been generated, important root clinits have been run and JNI is completely functional.
719722
{

test/911-get-stack-trace/src/PrintThread.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ public static void printAll(Object[][] stacks) {
4444
if (name.contains("Daemon")) {
4545
// Do not print daemon stacks, as they're non-deterministic.
4646
stackSerialization = "<not printed>";
47+
} else if (name.startsWith("Jit thread pool worker")) {
48+
// Skip JIT thread pool. It may or may not be there depending on configuration.
49+
continue;
4750
} else {
4851
StringBuilder sb = new StringBuilder();
4952
for (String[] stackElement : (String[][])stackInfo[1]) {

test/924-threads/src/Main.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.Comparator;
2121
import java.util.concurrent.CountDownLatch;
2222
import java.util.HashMap;
23+
import java.util.Iterator;
2324
import java.util.List;
2425
import java.util.Map;
2526

@@ -162,8 +163,20 @@ public void run() {
162163

163164
private static void doAllThreadsTests() {
164165
Thread[] threads = getAllThreads();
165-
Arrays.sort(threads, THREAD_COMP);
166-
System.out.println(Arrays.toString(threads));
166+
List<Thread> threadList = new ArrayList<>(Arrays.asList(threads));
167+
168+
// Filter out JIT thread. It may or may not be there depending on configuration.
169+
Iterator<Thread> it = threadList.iterator();
170+
while (it.hasNext()) {
171+
Thread t = it.next();
172+
if (t.getName().startsWith("Jit thread pool worker")) {
173+
it.remove();
174+
break;
175+
}
176+
}
177+
178+
Collections.sort(threadList, THREAD_COMP);
179+
System.out.println(threadList);
167180
}
168181

169182
private static void doTLSTests() throws Exception {

test/925-threadgroups/src/Main.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@
1414
* limitations under the License.
1515
*/
1616

17+
import java.util.ArrayList;
1718
import java.util.Arrays;
1819
import java.util.Comparator;
20+
import java.util.Collections;
21+
import java.util.Iterator;
22+
import java.util.List;
1923

2024
public class Main {
2125
public static void main(String[] args) throws Exception {
@@ -64,10 +68,23 @@ private static void checkChildren(ThreadGroup tg) {
6468
Thread[] threads = (Thread[])data[0];
6569
ThreadGroup[] groups = (ThreadGroup[])data[1];
6670

67-
Arrays.sort(threads, THREAD_COMP);
71+
List<Thread> threadList = new ArrayList<>(Arrays.asList(threads));
72+
73+
// Filter out JIT thread. It may or may not be there depending on configuration.
74+
Iterator<Thread> it = threadList.iterator();
75+
while (it.hasNext()) {
76+
Thread t = it.next();
77+
if (t.getName().startsWith("Jit thread pool worker")) {
78+
it.remove();
79+
break;
80+
}
81+
}
82+
83+
Collections.sort(threadList, THREAD_COMP);
84+
6885
Arrays.sort(groups, THREADGROUP_COMP);
6986
System.out.println(tg.getName() + ":");
70-
System.out.println(" " + Arrays.toString(threads));
87+
System.out.println(" " + threadList);
7188
System.out.println(" " + Arrays.toString(groups));
7289

7390
if (tg.getParent() != null) {

0 commit comments

Comments
 (0)