Skip to content

Commit 8be5612

Browse files
committed
[GR-45165] Consolidated Graal module sources to jdk.internal.vm.compiler.
PullRequest: graal/14175
2 parents 41cdea5 + 605001b commit 8be5612

File tree

3,481 files changed

+317
-1759
lines changed

Some content is hidden

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

3,481 files changed

+317
-1759
lines changed

compiler/mx.compiler/mx_compiler.py

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#
22
# ----------------------------------------------------------------------------------------------------
33
#
4-
# Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
4+
# Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
55
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
66
#
77
# This code is free software; you can redistribute it and/or modify it
@@ -91,7 +91,7 @@ def _check_jvmci_version(jdk):
9191
"""
9292
Runs a Java utility to check that `jdk` supports the minimum JVMCI API required by Graal.
9393
"""
94-
source_path = join(_suite.dir, 'src', 'org.graalvm.compiler.hotspot', 'src', 'org', 'graalvm', 'compiler', 'hotspot', 'JVMCIVersionCheck.java')
94+
source_path = join(_suite.dir, 'src', 'jdk.internal.vm.compiler', 'src', 'org', 'graalvm', 'compiler', 'hotspot', 'JVMCIVersionCheck.java')
9595
out = mx.OutputCapture()
9696
mx.run([jdk.java, '-Xlog:disable', source_path], out=out)
9797
global _jdk_jvmci_version
@@ -400,7 +400,53 @@ def _run_benchmark(suite, name, args, vmargs):
400400
mx.abort("Gate for {} benchmark '{}' failed!".format(suite, name))
401401
return exit_code, suite, results
402402

403+
def _check_forbidden_imports(projects, package_substrings, exceptions=None):
404+
"""
405+
Checks Java source files in `projects` to ensure there is no import from
406+
a class in a package whose name does not match `package_substrings`
407+
of a package whose name matches `package_substrings`.
408+
409+
:param projects: list of JavaProjects
410+
:param package_substrings: package name substrings
411+
:param exceptions: set of unqualified Java source file names for which a failing
412+
check produces a warning instead of an abort
413+
"""
414+
# Assumes package name components start with lower case letter and
415+
# classes start with upper-case letter
416+
importStatementRe = re.compile(r'\s*import\s+(?:static\s+)?([a-zA-Z\d_$\.]+\*?)\s*;\s*')
417+
importedRe = re.compile(r'((?:[a-z][a-zA-Z\d_$]*\.)*[a-z][a-zA-Z\d_$]*)\.(?:(?:[A-Z][a-zA-Z\d_$]*)|\*)')
418+
for project in projects:
419+
for source_dir in project.source_dirs():
420+
for root, _, files in os.walk(source_dir):
421+
java_sources = [name for name in files if name.endswith('.java') and name != 'module-info.java']
422+
if len(java_sources) != 0:
423+
java_package = root[len(source_dir) + 1:].replace(os.sep, '.')
424+
if not any((s in java_package for s in package_substrings)):
425+
for n in java_sources:
426+
java_source = join(root, n)
427+
with open(java_source) as fp:
428+
for i, line in enumerate(fp):
429+
m = importStatementRe.match(line)
430+
if m:
431+
imported = m.group(1)
432+
m = importedRe.match(imported)
433+
lineNo = i + 1
434+
if not m:
435+
mx.abort(java_source + ':' + str(lineNo) + ': import statement does not match expected pattern:\n' + line)
436+
imported_package = m.group(1)
437+
for s in package_substrings:
438+
if s in imported_package:
439+
message = f'{java_source}:{lineNo}: forbidden import of a "{s}" package: {imported_package}\n{line}'
440+
if exceptions and n in exceptions:
441+
mx.warn(message)
442+
else:
443+
mx.abort(message)
444+
403445
def compiler_gate_runner(suites, unit_test_runs, bootstrap_tests, tasks, extraVMarguments=None, extraUnitTestArguments=None):
446+
with Task('CheckForbiddenImports:Compiler', tasks, tags=['style']) as t:
447+
# Ensure HotSpot-independent compiler classes do not import HotSpot-specific classes
448+
if t: _check_forbidden_imports([mx.project('jdk.internal.vm.compiler')], ('hotspot', 'libgraal'))
449+
404450
with Task('JDK_java_base_test', tasks, tags=['javabasetest'], report=True) as t:
405451
if t: java_base_unittest(_remove_empty_entries(extraVMarguments) + [])
406452

@@ -1404,5 +1450,6 @@ def mx_post_parse_cmd_line(opts):
14041450
for dist in _suite.dists:
14051451
if hasattr(dist, 'set_archiveparticipant'):
14061452
dist.set_archiveparticipant(GraalArchiveParticipant(dist, isTest=dist.name.endswith('_TEST')))
1453+
14071454
global _vm_prefix
14081455
_vm_prefix = opts.vm_prefix

0 commit comments

Comments
 (0)