Skip to content

Commit 526ad75

Browse files
theaoqiheiherxiangzhaihaominwsunny868
committed
Initial Linux/LoongArch64 Port
A complete (i.e., template interpreter, C1 JIT compiler, C2 JIT compiler, Vector API, ZGC and Shenandoah GC) LoongArch64 port has been implemented. Co-authored-by: Ao Qi <[email protected]> Co-authored-by: Wang Rui <[email protected]> Co-authored-by: Zhai Xiang <[email protected]> Co-authored-by: Wang Haomin <[email protected]> Co-authored-by: Sun Guoyun <[email protected]> Co-authored-by: Pan Xuefeng <[email protected]> Co-authored-by: Sun Xu <[email protected]>
1 parent c104089 commit 526ad75

File tree

195 files changed

+68884
-227
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

195 files changed

+68884
-227
lines changed

make/autoconf/jvm-features.m4

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
# questions.
2424
#
2525

26+
#
27+
# This file has been modified by Loongson Technology in 2022. These
28+
# modifications are Copyright (c) 2020, 2022, Loongson Technology, and are made
29+
# available on the same license terms set forth above.
30+
#
31+
2632
###############################################################################
2733
# Terminology used in this file:
2834
#
@@ -292,7 +298,8 @@ AC_DEFUN_ONCE([JVM_FEATURES_CHECK_SHENANDOAHGC],
292298
if test "x$OPENJDK_TARGET_CPU_ARCH" = "xx86" || \
293299
test "x$OPENJDK_TARGET_CPU" = "xaarch64" || \
294300
test "x$OPENJDK_TARGET_CPU" = "xppc64le" || \
295-
test "x$OPENJDK_TARGET_CPU" = "xriscv64"; then
301+
test "x$OPENJDK_TARGET_CPU" = "xriscv64" || \
302+
test "x$OPENJDK_TARGET_CPU" = "xloongarch64"; then
296303
AC_MSG_RESULT([yes])
297304
else
298305
AC_MSG_RESULT([no, $OPENJDK_TARGET_CPU])
@@ -350,6 +357,13 @@ AC_DEFUN_ONCE([JVM_FEATURES_CHECK_ZGC],
350357
AC_MSG_RESULT([no, $OPENJDK_TARGET_OS-$OPENJDK_TARGET_CPU])
351358
AVAILABLE=false
352359
fi
360+
elif test "x$OPENJDK_TARGET_CPU" = "xloongarch64"; then
361+
if test "x$OPENJDK_TARGET_OS" = "xlinux"; then
362+
AC_MSG_RESULT([yes])
363+
else
364+
AC_MSG_RESULT([no, $OPENJDK_TARGET_OS-$OPENJDK_TARGET_CPU])
365+
AVAILABLE=false
366+
fi
353367
else
354368
AC_MSG_RESULT([no, $OPENJDK_TARGET_OS-$OPENJDK_TARGET_CPU])
355369
AVAILABLE=false

make/autoconf/platform.m4

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
# questions.
2424
#
2525

26+
#
27+
# This file has been modified by Loongson Technology in 2022. These
28+
# modifications are Copyright (c) 2018, 2022, Loongson Technology, and are made
29+
# available on the same license terms set forth above.
30+
#
31+
2632
# Support macro for PLATFORM_EXTRACT_TARGET_AND_BUILD.
2733
# Converts autoconf style CPU name to OpenJDK style, into
2834
# VAR_CPU, VAR_CPU_ARCH, VAR_CPU_BITS and VAR_CPU_ENDIAN.
@@ -545,11 +551,20 @@ AC_DEFUN([PLATFORM_SETUP_LEGACY_VARS_HELPER],
545551
HOTSPOT_$1_CPU=ppc_64
546552
elif test "x$OPENJDK_$1_CPU" = xppc64le; then
547553
HOTSPOT_$1_CPU=ppc_64
554+
elif test "x$OPENJDK_$1_CPU" = xloongarch; then
555+
HOTSPOT_$1_CPU=loongarch_64
556+
elif test "x$OPENJDK_$1_CPU" = xloongarch64; then
557+
HOTSPOT_$1_CPU=loongarch_64
548558
fi
549559
AC_SUBST(HOTSPOT_$1_CPU)
550560
551561
# This is identical with OPENJDK_*, but define anyway for consistency.
552562
HOTSPOT_$1_CPU_ARCH=${OPENJDK_$1_CPU_ARCH}
563+
# Override hotspot cpu definitions for LOONGARCH platforms
564+
if test "x$OPENJDK_$1_CPU" = xloongarch64; then
565+
HOTSPOT_TARGET_CPU_ARCH=loongarch
566+
fi
567+
553568
AC_SUBST(HOTSPOT_$1_CPU_ARCH)
554569
555570
# Setup HOTSPOT_$1_CPU_DEFINE
@@ -571,6 +586,8 @@ AC_DEFUN([PLATFORM_SETUP_LEGACY_VARS_HELPER],
571586
HOTSPOT_$1_CPU_DEFINE=RISCV32
572587
elif test "x$OPENJDK_$1_CPU" = xriscv64; then
573588
HOTSPOT_$1_CPU_DEFINE=RISCV64
589+
elif test "x$OPENJDK_$1_CPU" = xloongarch64; then
590+
HOTSPOT_$1_CPU_DEFINE=LOONGARCH64
574591
575592
# The cpu defines below are for zero, we don't support them directly.
576593
elif test "x$OPENJDK_$1_CPU" = xsparc; then
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
/*
2+
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
3+
* Copyright (c) 2015, 2022, Loongson Technology. All rights reserved.
4+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5+
*
6+
* This code is free software; you can redistribute it and/or modify it
7+
* under the terms of the GNU General Public License version 2 only, as
8+
* published by the Free Software Foundation.
9+
*
10+
* This code is distributed in the hope that it will be useful, but WITHOUT
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13+
* version 2 for more details (a copy is included in the LICENSE file that
14+
* accompanied this code).
15+
*
16+
* You should have received a copy of the GNU General Public License version
17+
* 2 along with this work; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19+
*
20+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21+
* or visit www.oracle.com if you need additional information or have any
22+
* questions.
23+
*
24+
*/
25+
26+
#include "precompiled.hpp"
27+
#include "ci/ciMethod.hpp"
28+
#include "interpreter/interpreter.hpp"
29+
#include "oops/klass.inline.hpp"
30+
#include "runtime/frame.inline.hpp"
31+
32+
// asm based interpreter deoptimization helpers
33+
int AbstractInterpreter::size_activation(int max_stack,
34+
int temps,
35+
int extra_args,
36+
int monitors,
37+
int callee_params,
38+
int callee_locals,
39+
bool is_top_frame) {
40+
// Note: This calculation must exactly parallel the frame setup
41+
// in AbstractInterpreterGenerator::generate_method_entry.
42+
43+
// fixed size of an interpreter frame:
44+
int overhead = frame::java_frame_sender_sp_offset -
45+
frame::interpreter_frame_initial_sp_offset;
46+
// Our locals were accounted for by the caller (or last_frame_adjust
47+
// on the transition) Since the callee parameters already account
48+
// for the callee's params we only need to account for the extra
49+
// locals.
50+
int size = overhead +
51+
(callee_locals - callee_params)*Interpreter::stackElementWords +
52+
monitors * frame::interpreter_frame_monitor_size() +
53+
temps* Interpreter::stackElementWords + extra_args;
54+
55+
return size;
56+
}
57+
58+
// How much stack a method activation needs in words.
59+
int AbstractInterpreter::size_top_interpreter_activation(Method* method) {
60+
61+
const int entry_size = frame::interpreter_frame_monitor_size();
62+
63+
// total overhead size: entry_size + (saved ebp thru expr stack bottom).
64+
// be sure to change this if you add/subtract anything to/from the overhead area
65+
const int overhead_size = -(frame::interpreter_frame_initial_sp_offset) + entry_size;
66+
67+
const int stub_code = 6; // see generate_call_stub
68+
// return overhead_size + method->max_locals() + method->max_stack() + stub_code;
69+
const int method_stack = (method->max_locals() + method->max_stack()) *
70+
Interpreter::stackElementWords;
71+
return overhead_size + method_stack + stub_code;
72+
}
73+
74+
void AbstractInterpreter::layout_activation(Method* method,
75+
int tempcount,
76+
int popframe_extra_args,
77+
int moncount,
78+
int caller_actual_parameters,
79+
int callee_param_count,
80+
int callee_locals,
81+
frame* caller,
82+
frame* interpreter_frame,
83+
bool is_top_frame,
84+
bool is_bottom_frame) {
85+
// Note: This calculation must exactly parallel the frame setup
86+
// in AbstractInterpreterGenerator::generate_method_entry.
87+
// If interpreter_frame!=NULL, set up the method, locals, and monitors.
88+
// The frame interpreter_frame, if not NULL, is guaranteed to be the
89+
// right size, as determined by a previous call to this method.
90+
// It is also guaranteed to be walkable even though it is in a skeletal state
91+
92+
// fixed size of an interpreter frame:
93+
94+
int max_locals = method->max_locals() * Interpreter::stackElementWords;
95+
int extra_locals = (method->max_locals() - method->size_of_parameters()) * Interpreter::stackElementWords;
96+
97+
#ifdef ASSERT
98+
assert(caller->sp() == interpreter_frame->sender_sp(), "Frame not properly walkable(2)");
99+
#endif
100+
101+
interpreter_frame->interpreter_frame_set_method(method);
102+
// NOTE the difference in using sender_sp and interpreter_frame_sender_sp
103+
// interpreter_frame_sender_sp is the original sp of the caller (the unextended_sp)
104+
// and sender_sp is fp+8
105+
intptr_t* locals = interpreter_frame->sender_sp() + max_locals - 1;
106+
107+
#ifdef ASSERT
108+
if (caller->is_interpreted_frame()) {
109+
assert(locals < caller->fp() + frame::interpreter_frame_initial_sp_offset, "bad placement");
110+
}
111+
#endif
112+
113+
interpreter_frame->interpreter_frame_set_locals(locals);
114+
BasicObjectLock* montop = interpreter_frame->interpreter_frame_monitor_begin();
115+
BasicObjectLock* monbot = montop - moncount;
116+
interpreter_frame->interpreter_frame_set_monitor_end(montop - moncount);
117+
118+
//set last sp;
119+
intptr_t* esp = (intptr_t*) monbot - tempcount*Interpreter::stackElementWords -
120+
popframe_extra_args;
121+
interpreter_frame->interpreter_frame_set_last_sp(esp);
122+
// All frames but the initial interpreter frame we fill in have a
123+
// value for sender_sp that allows walking the stack but isn't
124+
// truly correct. Correct the value here.
125+
//
126+
if (extra_locals != 0 &&
127+
interpreter_frame->sender_sp() == interpreter_frame->interpreter_frame_sender_sp() ) {
128+
interpreter_frame->set_interpreter_frame_sender_sp(caller->sp() + extra_locals);
129+
}
130+
*interpreter_frame->interpreter_frame_cache_addr() = method->constants()->cache();
131+
*interpreter_frame->interpreter_frame_mirror_addr() = method->method_holder()->java_mirror();
132+
}
133+

0 commit comments

Comments
 (0)