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 8.4KB

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