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.

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