FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
mercury/java/runtime/JavaInternal.java at master · Mercury-Language/mercury · GitHub
Mercury-Language
/
mercury
Public
Notifications
You must be signed in to change notification settings
Fork
71
Star
1.1k
Code
Issues
13
Pull requests
8
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
mercury
/
java
/
runtime
/
JavaInternal.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
146 lines (129 loc) · 4.44 KB
Breadcrumbs
mercury
/
java
/
runtime
/
JavaInternal.java
Copy path
File metadata and controls
146 lines (129 loc) · 4.44 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// vim: ts=4 sw=4 expandtab ft=java
//
// Copyright (C) 2001-2003, 2009 The University of Melbourne.
// Copyright (C) 2014, 2017-2018 The Mercury Team.
// This file is distributed under the terms specified in COPYING.LIB.
//
// All modifications to this file will require changes to:
// compiler/mlds_to_java.m
package
jmercury
.
runtime
;
/**
* Internals and static objects for Mercury's runtime system on the Java
* backend.
* This class is used to store the main module's name (progname), command
* line arguments and the exit status. We can't put them in one of the
* library modules because we need to hold them in a class variable in a top
* level class.
*
* The class also contains utility methods and other objects such as a
* reference to the thread pool.
*
* No instance of this class is ever created, all of its members and methods
* are static.
*/
public
class
JavaInternal
{
/**
* Private constructor.
* This private constructor doesn't do anything and isn't called by
* anyone. It exists only to prevent people from creating an instance.
*/
private
JavaInternal
() {
}
private
static
MercuryThreadPool
thread_pool
=
null
;
private
static
MercuryOptions
options
=
null
;
public
static
synchronized
MercuryThreadPool
getThreadPool
() {
if
(
thread_pool
==
null
) {
thread_pool
=
new
MercuryThreadPool
(
getOptions
().
getNumProcessors
());
}
return
thread_pool
;
}
public
static
synchronized
MercuryOptions
getOptions
() {
if
(
options
==
null
) {
options
=
new
MercuryOptions
();
options
.
process
();
}
return
options
;
}
public
static
java
.
lang
.
String
progname
;
public
static
java
.
lang
.
String
[]
args
;
public
static
int
exit_status
;
private
static
ExceptionReporter
exception_reporter
;
private
static
java
.
util
.
List
<
Runnable
>
finalisers
=
new
java
.
util
.
ArrayList
<
Runnable
>();
public
static
void
register_finaliser
(
Runnable
hook
) {
finalisers
.
add
(
hook
);
}
public
static
void
run_finalisers
() {
for
(
Runnable
r
:
finalisers
) {
r
.
run
();
}
}
/**
* Run the main task.
* The main task is executed by the thread pool so that when it blocks
* the thread pool is notified correctly.
*/
public
static
void
runMain
(
Runnable
main
)
{
try
{
getThreadPool
().
runMain
(
main
);
}
catch
(
jmercury
.
runtime
.
MercuryFatalError
e
) {
System
.
out
.
flush
();
System
.
err
.
println
(
"Mercury runtime: "
+
e
.
getMessage
());
System
.
err
.
flush
();
if
(
exit_status
==
0
) {
exit_status
=
1
;
}
}
}
/**
* Set the exception reporter if one is not set already.
* The specified object will be used by reportUncaughtException to
* report exceptions. See the comment for reportUncaughtException()
% @param reporter The new exception reporter object.
*/
public
static
void
setExceptionReporter
(
ExceptionReporter
reporter
)
{
if
(
null
==
exception_reporter
) {
exception_reporter
=
reporter
;
}
}
/**
* Report uncaught exceptions.
* This reports exceptions using the exception reporter object, if it is
* set. Otherwise we make a best effort at reporting it.
*
* Exception reporting code is written in exception.m which we cannot
* link to from here. When that code starts it should set an exception
* reporter object.
*/
public
static
void
reportUncaughtException
(
jmercury
.
runtime
.
Exception
e
)
{
if
(
null
!=
exception_reporter
) {
exception_reporter
.
reportUncaughtException
(
e
);
}
else
{
System
.
out
.
flush
();
System
.
err
.
println
(
"Uncaught exception: "
+
e
.
getMessage
());
System
.
err
.
flush
();
}
if
(
shouldPrintStackTrace
()) {
e
.
printStackTrace
(
System
.
err
);
}
if
(
exit_status
==
0
) {
exit_status
=
1
;
}
}
/**
* Should we print Java stack traces when we catch Mercury exceptions?
*/
public
static
boolean
shouldPrintStackTrace
() {
return
System
.
getenv
(
"MERCURY_SUPPRESS_STACK_TRACE"
) ==
null
;
}
/**
* Interface for reporting exceptions.
*/
public
interface
ExceptionReporter
{
public
void
reportUncaughtException
(
jmercury
.
runtime
.
Exception
e
);
}
}
Back
|
FazBrowse Home
|
New Git URL