You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

build.gradle 7.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. // Global settings
  2. project.ext {
  3. // Source JRE used for compilation, etc
  4. if (!project.hasProperty('jre')) {
  5. jre = System.getProperty('java.home')
  6. }
  7. os = Os.current()
  8. arch = Arch.current()
  9. if (!project.hasProperty('targetJre')) {
  10. targetJre = jre
  11. }
  12. }
  13. def targetJreFile = file(targetJre)
  14. def jreFile = file(jre)
  15. // HotSpot itself
  16. project('hotspot') {
  17. task clean(type: InvokeMake) {
  18. onlyIf { file('hotspot').exists() }
  19. args 'clean'
  20. }
  21. task prepareJvm {
  22. onlyIf { jreFile.canonicalPath != targetJreFile.canonicalPath }
  23. doLast {
  24. ant.copy(todir: targetJreFile) {
  25. fileset(dir: jreFile)
  26. }
  27. ant.chmod(file: new File(targetJreFile, 'bin/java'), perm: '0755')
  28. }
  29. }
  30. task clone(description: 'Clone HotSpot repository') {
  31. onlyIf { !file('hotspot').exists() }
  32. doLast {
  33. exec {
  34. workingDir '..'
  35. executable 'hg'
  36. args 'clone', hotspotRepository
  37. }
  38. }
  39. }
  40. task patch(description: 'Patch HotSpot sources', dependsOn: clone) << {
  41. exec {
  42. executable 'hg'
  43. args 'pull'
  44. }
  45. exec {
  46. executable 'hg'
  47. args 'update', '-C', '-r', hotspotTag
  48. }
  49. new ByteArrayOutputStream().withStream { os ->
  50. exec {
  51. workingDir 'hotspot'
  52. executable 'hg'
  53. args 'status'
  54. standardOutput os
  55. }
  56. // Purge unversioned files
  57. def str = os.toString()
  58. def matcher = str =~ /(?m)^\?\s+(.*)$/
  59. matcher.each {
  60. ant.delete(file: new File(file('hotspot'), it[1]))
  61. }
  62. }
  63. // Use hg import since ant.patchfile requires 'patch' to be installed
  64. exec {
  65. executable 'hg'
  66. args 'import', '--no-commit', "../patches/${flavor}-${hotspotTag}.patch"
  67. }
  68. }
  69. def arguments = ['product': ['ENABLE_FULL_DEBUG_SYMBOLS=0'],
  70. 'fastdebug': ['ENABLE_FULL_DEBUG_SYMBOLS=1', 'STRIP_POLICY=no_strip', 'ZIP_DEBUGINFO_FILES=0']]
  71. ['product', 'fastdebug'].each { k ->
  72. // Compile given kind of DCEVM
  73. def compile = task("compile${k.capitalize()}", type: InvokeMake) {
  74. args arguments[k]
  75. args k
  76. doLast {
  77. ant.copy(todir: "build/${k}", overwrite: true) {
  78. fileset(dir: "build/${os.buildPath}/${os.buildPath}_${arch.buildArch}_${compiler}/${k}",
  79. includes: 'libjvm.so,libjsig.so,jvm.dll,jsig.dll,libjvm.dylib,libjsig.dylib')
  80. }
  81. }
  82. }
  83. compile.mustRunAfter(patch)
  84. // Install given kind of DCEVM into destination JRE
  85. task("install${k.capitalize()}", dependsOn: [prepareJvm, compile]) << {
  86. def installPath = new File(new File(targetJreFile, arch == Arch.X86 ? os.installPath32 : os.installPath64), jvmName)
  87. logger.info("Installing DCEVM runtime into JRE with JVM name '${jvmName}' and kind '${k}' at ${installPath}")
  88. ant.copy(todir: installPath, overwrite: true) {
  89. fileset(dir: "build/${os.buildPath}/${os.buildPath}_${arch.buildArch}_${compiler}/${k}",
  90. includes: 'libjvm.so,libjsig.so,jvm.dll,jsig.dll,libjvm.dylib,libjsig.dylib')
  91. }
  92. }
  93. }
  94. }
  95. // Java projects for testing DCEVM
  96. def setup(prjs, closure) {
  97. prjs.each { prj ->
  98. project(prj, closure)
  99. }
  100. }
  101. setup(['agent', 'dcevm'], {
  102. apply plugin: 'java'
  103. apply plugin: 'idea'
  104. repositories {
  105. mavenCentral()
  106. }
  107. })
  108. project('agent') {
  109. jar {
  110. manifest {
  111. from "src/main/java/META-INF/MANIFEST.MF"
  112. }
  113. }
  114. }
  115. project('native') {
  116. apply plugin: 'base'
  117. task compile(type: Exec) {
  118. doFirst {
  119. buildDir.mkdirs()
  120. }
  121. if (os != Os.WINDOWS) {
  122. commandLine 'gcc'
  123. args "-I${jre}/../include"
  124. args "-I${jre}/../include/linux"
  125. args '-shared'
  126. args 'natives.c'
  127. args '-o'
  128. args 'build/libnatives.so'
  129. } else {
  130. commandLine 'cmd', '/c', 'compile.cmd'
  131. environment ARCH: arch == Arch.X86 ? 'x86' : 'x64'
  132. environment JAVA_HOME: jre
  133. }
  134. }
  135. }
  136. project('dcevm') {
  137. dependencies {
  138. compile project(':agent')
  139. compile group: 'asm', name: 'asm-all', version: '3.3.+'
  140. compile files(jre + '/../lib/tools.jar')
  141. testCompile group: 'junit', name: 'junit', version: '4.11'
  142. }
  143. def m = System.getProperty('java.version') =~ /^1\.([0-9]+)\.*/
  144. def major = m[0][1].toInteger()
  145. if (major >= 7) {
  146. sourceSets.test.java.srcDirs += 'src/test/java7'
  147. }
  148. if (major >= 8) {
  149. sourceSets.test.java.srcDirs += 'src/test/java8'
  150. }
  151. test {
  152. executable new File(targetJreFile, 'bin/java')
  153. systemProperty 'dcevm.test.light', (flavor == 'light')
  154. if (kind == 'fastdebug') {
  155. jvmArgs '-XX:LogFile=build/hotspot.log'
  156. }
  157. jvmArgs "-XXaltjvm=${jvmName}"
  158. jvmArgs '-javaagent:../agent/build/libs/agent.jar'
  159. if (arch == Arch.X86_64) {
  160. jvmArgs(project.oops == "compressed" ? '-XX:+UseCompressedOops' : "-XX:-UseCompressedOops")
  161. }
  162. jvmArgs "-XX:TraceRedefineClasses=${traceRedefinition}"
  163. ignoreFailures = true
  164. outputs.upToDateWhen { false }
  165. useJUnit {
  166. excludeCategories ('com.github.dcevm.test.category.' + (flavor == 'light' ? 'Full' : 'Light'))
  167. }
  168. }
  169. test.dependsOn project(':hotspot').tasks[kind == 'fastdebug' ? 'installFastdebug' : 'installProduct']
  170. }
  171. enum Arch {
  172. X86(["i386", "i486", "i586", "x86"], 'i486', 32),
  173. X86_64(["x86_64", "x64", "amd64"], 'amd64', 64)
  174. final List<String> names
  175. final String buildArch
  176. final int bits
  177. Arch(List<String> names, String buildArch, int bits) {
  178. this.names = names
  179. this.buildArch = buildArch
  180. this.bits = bits
  181. }
  182. static Arch find(String token) {
  183. Arch res = values().find({ v -> v.names.contains(token) })
  184. return res
  185. }
  186. static Arch current() {
  187. return find(System.getProperty("os.arch"))
  188. }
  189. }
  190. enum Os {
  191. MAC('bsd', 'lib', 'lib'),
  192. WINDOWS('windows', 'bin', 'bin'),
  193. UNIX('linux', 'lib/i386', 'lib/amd64')
  194. final String buildPath;
  195. final String installPath32;
  196. final String installPath64;
  197. Os(String buildPath, String installPath32, String installPath64) {
  198. this.buildPath = buildPath
  199. this.installPath32 = installPath32
  200. this.installPath64 = installPath64
  201. }
  202. static Os current() {
  203. return values().find { os -> org.apache.tools.ant.taskdefs.condition.Os.isFamily(os.name().toLowerCase()) }
  204. }
  205. }
  206. // Helper task to run make targets against hotspot
  207. class InvokeMake extends org.gradle.api.tasks.Exec {
  208. InvokeMake() {
  209. def root = project.rootProject
  210. logging.captureStandardOutput LogLevel.INFO
  211. if (root.os != Os.WINDOWS) {
  212. commandLine 'make', '-C', 'make'
  213. } else {
  214. // Using launcher script
  215. commandLine 'cmd', '/c', '..\\build.cmd'
  216. environment ARCH: root.arch == Arch.X86 ? 'x86' : 'x64'
  217. }
  218. args 'OPENJDK=true'
  219. args "HOTSPOT_BUILD_VERSION=dcevm${root.flavor}-${root.buildNumber}"
  220. args "ARCH_DATA_MODEL=${root.arch.bits}"
  221. args "ALT_BOOTDIR=${root.jre.replace('\\', '/')}/.."
  222. // Replacing backslashes is essential for Windows!
  223. args 'COMPILER_WARNINGS_FATAL=false' // Clang is very serious about warnings
  224. args 'HOTSPOT_BUILD_JOBS=4'
  225. }
  226. }