r88959 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88958‎ | r88959 | r88960 >
Date:06:25, 27 May 2011
Author:tstarling
Status:ok
Tags:
Comment:
Some HipHop fixes:
* Scan the C++ for volatile classes and show a warning with a list of them
* Fixed volatile classes Revision, CoreLinkFunctions and FileRepoStatus, made them non-volatile by patching the referring code
* Added some configuration for the build process to DefaultSettings.php.
* Split a few functions off MakeHipHop::execute()
* Only include UtfNormalDefines.php in interpreted mode, since in compiled mode, the constants exist from startup
* Apparently HipHop does not support set_exception_handler(). Added a try/catch block around the main part of index.php instead.
* Fixed ini_get() dependencies in Special:Upload. Upload now works, if you disable ZipDirectoryReader.
Modified paths:
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/Init.php (modified) (history)
  • /trunk/phase3/includes/Setup.php (modified) (history)
  • /trunk/phase3/includes/filerepo/FileRepo.php (modified) (history)
  • /trunk/phase3/includes/parser/Parser_LinkHooks.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialUpload.php (modified) (history)
  • /trunk/phase3/includes/upload/UploadBase.php (modified) (history)
  • /trunk/phase3/index.php (modified) (history)
  • /trunk/phase3/maintenance/hiphop/make (modified) (history)
  • /trunk/phase3/maintenance/userDupes.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/userDupes.inc
@@ -174,7 +174,7 @@
175175 * @access private
176176 */
177177 function newSchema() {
178 - return class_exists( 'Revision' );
 178+ return MWInit::classExists( 'Revision' );
179179 }
180180
181181 /**
Index: trunk/phase3/maintenance/hiphop/make
@@ -4,7 +4,6 @@
55 require( dirname( __FILE__ ) . '/../Maintenance.php' );
66
77 class MakeHipHop extends Maintenance {
8 -
98 function execute() {
109 $startTime = time();
1110
@@ -63,13 +62,21 @@
6463 ' --parse-on-demand=false' .
6564 ' --program=mediawiki-hphp' .
6665 ' --output-dir=' . wfEscapeShellArg( $outDir ) .
67 - ' --log=3' );
 66+ ' --log=3', $ret );
6867
 68+ if ( $ret ) {
 69+ $this->error( "hphp hit an error. Stopping build.\n" );
 70+ exit( 1 );
 71+ }
 72+
6973 # Sanity check, quickly make sure we've got an output directory
7074 if( !is_dir( $outDir ) ) {
7175 $this->error( "No output directory", true );
7276 }
7377
 78+ # Warn about volatile classes
 79+ $this->checkVolatileClasses( $outDir );
 80+
7481 # Copy the generated C++ files into the source directory for cmake
7582 $iter = new RecursiveIteratorIterator(
7683 new RecursiveDirectoryIterator( $outDir ),
@@ -140,7 +147,7 @@
141148 }
142149
143150 $cmd = 'cmake' .
144 - ' -D CMAKE_BUILD_TYPE:string=Debug' .
 151+ " -D CMAKE_BUILD_TYPE:string=" . wfEscapeShellArg( $GLOBALS['wgHipHopBuildType'] ) .
145152 ' -D PROGRAM_NAME:string=mediawiki-hphp';
146153
147154 if ( file_exists( '/usr/bin/ccache' ) ) {
@@ -155,19 +162,7 @@
156163
157164 # Determine appropriate make concurrency
158165 # Compilation can take a lot of memory, let's assume that that is limiting.
159 - $mem = false;
160 - foreach ( file( '/proc/meminfo' ) as $line ) {
161 - if ( preg_match( '/^MemTotal:\s+(\d+)\s+kB/', $line, $m ) ) {
162 - $mem = intval( $m[1] );
163 - break;
164 - }
165 - }
166 - if ( $mem ) {
167 - $procs = floor( $mem / 1000000 );
168 - $procs = $procs >= 1 ? $procs : 1; // No less than 1
169 - } else {
170 - $procs = 1;
171 - }
 166+ $procs = $this->getNumProcs();
172167
173168 # Run make. This is the slow step.
174169 passthru( 'make -j' . wfEscapeShellArg( $procs ) );
@@ -188,6 +183,47 @@
189184 echo $elapsed . "s\n";
190185 echo "The MediaWiki executable is at build/persistent/mediawiki-hphp\n";
191186 }
 187+
 188+ function checkVolatileClasses( $dir ) {
 189+ $lines = file( "$dir/sys/dynamic_table_class.cpp" );
 190+ $classes = array();
 191+ foreach ( $lines as $line ) {
 192+ if ( preg_match( '/^\s+\(const char \*\)"([^"]*)", \(const char \*\)-1/', $line, $m ) ) {
 193+ $classes[] = $m[1];
 194+ }
 195+ }
 196+ if ( !count( $classes ) ) {
 197+ print "No volatile classes found\n";
 198+ return;
 199+ }
 200+ sort( $classes );
 201+ $classes = array_unique( $classes );
 202+ print "WARNING: The following classes are volatile: " . implode( ', ', $classes ) . "\n";
 203+ }
 204+
 205+ function getNumProcs() {
 206+ global $wgHipHopCompilerProcs;
 207+ if ( $wgHipHopCompilerProcs !== 'detect' ) {
 208+ return intval( $wgHipHopCompilerProcs );
 209+ }
 210+
 211+ if ( !file_exists( '/proc/meminfo' ) ) {
 212+ return 1;
 213+ }
 214+ $mem = false;
 215+ foreach ( file( '/proc/meminfo' ) as $line ) {
 216+ if ( preg_match( '/^MemTotal:\s+(\d+)\s+kB/', $line, $m ) ) {
 217+ $mem = intval( $m[1] );
 218+ break;
 219+ }
 220+ }
 221+ if ( $mem ) {
 222+ // At least one process
 223+ return max( 1, floor( $mem / 1000000 ) );
 224+ } else {
 225+ return 1;
 226+ }
 227+ }
192228 }
193229
194230 $maintClass = 'MakeHipHop';
Index: trunk/phase3/includes/upload/UploadBase.php
@@ -75,7 +75,7 @@
7676 }
7777
7878 # Check php's file_uploads setting
79 - if( !wfIniGetBool( 'file_uploads' ) ) {
 79+ if( !wfIsHipHop() && !wfIniGetBool( 'file_uploads' ) ) {
8080 return false;
8181 }
8282 return true;
Index: trunk/phase3/includes/parser/Parser_LinkHooks.php
@@ -254,8 +254,8 @@
255255 }
256256 if( $return === true ) {
257257 # True (treat as plain link) was returned, call the defaultLinkHook
258 - $args = array( $parser, $holders, $markers, $title, $titleText, &$paramText, &$leadingColon );
259 - $return = call_user_func_array( array( 'CoreLinkFunctions', 'defaultLinkHook' ), $args );
 258+ $return = CoreLinkFunctions::defaultLinkHook( $parser, $holders, $markers, $title,
 259+ $titleText, $paramText, $leadingColon );
260260 }
261261 if( $return === false ) {
262262 # False (no link) was returned, output plain wikitext
Index: trunk/phase3/includes/Setup.php
@@ -337,9 +337,9 @@
338338 require_once( "$IP/includes/Hooks.php" );
339339 require_once( "$IP/includes/ProxyTools.php" );
340340 require_once( "$IP/includes/ImageFunctions.php" );
 341+ require_once( "$IP/includes/normal/UtfNormalDefines.php" );
341342 wfProfileOut( $fname . '-includes' );
342343 }
343 -require_once( MWInit::compiledPath( 'includes/normal/UtfNormalDefines.php' ) );
344344
345345 wfProfileIn( $fname . '-misc1' );
346346
Index: trunk/phase3/includes/Init.php
@@ -90,4 +90,13 @@
9191 }
9292 return $r !== false;
9393 }
 94+
 95+ /**
 96+ * Call a static method of a class with variable arguments without causing
 97+ * it to become volatile.
 98+ */
 99+ static function callStaticMethod( $className, $methodName, $args ) {
 100+ $r = new ReflectionMethod( $className, $methodName );
 101+ return $r->invokeArgs( null, $args );
 102+ }
94103 }
Index: trunk/phase3/includes/filerepo/FileRepo.php
@@ -606,7 +606,7 @@
607607 function newFatal( $message /*, parameters...*/ ) {
608608 $params = func_get_args();
609609 array_unshift( $params, $this );
610 - return call_user_func_array( array( 'FileRepoStatus', 'newFatal' ), $params );
 610+ return MWInit::callStaticMethod( 'FileRepoStatus', 'newFatal', $params );
611611 }
612612
613613 /**
Index: trunk/phase3/includes/DefaultSettings.php
@@ -5309,6 +5309,25 @@
53105310 /** @} */ # End job queue }
53115311
53125312 /************************************************************************//**
 5313+ * @name HipHop compilation
 5314+ * @{
 5315+ */
 5316+
 5317+/**
 5318+ * The HipHop build type. Can be either "Debug" or "Release".
 5319+ */
 5320+$wgHipHopBuildType = 'Debug';
 5321+
 5322+/**
 5323+ * Number of parallel processes to use during HipHop compilation, or "detect"
 5324+ * to guess from system properties.
 5325+ */
 5326+$wgHipHopCompilerProcs = 'detect';
 5327+
 5328+/** @} */ # End of HipHop compilation }
 5329+
 5330+
 5331+/************************************************************************//**
53135332 * @name Miscellaneous
53145333 * @{
53155334 */
Index: trunk/phase3/includes/specials/SpecialUpload.php
@@ -863,9 +863,13 @@
864864 );
865865 }
866866
867 - $this->mMaxUploadSize['file'] = min(
868 - wfShorthandToInteger( ini_get( 'upload_max_filesize' ) ),
869 - UploadBase::getMaxUploadSize( 'file' ) );
 867+ $this->mMaxUploadSize['file'] = UploadBase::getMaxUploadSize( 'file' );
 868+ # Limit to upload_max_filesize unless we are running under HipHop and
 869+ # that setting doesn't exist
 870+ if ( !wfIsHipHop() ) {
 871+ $this->mMaxUploadSize['file'] = min( $this->mMaxUploadSize['file'],
 872+ wfShorthandToInteger( ini_get( 'upload_max_filesize' ) ) );
 873+ }
870874
871875 $descriptor['UploadFile'] = array(
872876 'class' => 'UploadSourceField',
Index: trunk/phase3/index.php
@@ -66,7 +66,11 @@
6767 # does *not* load $wgTitle
6868 require ( dirname( __FILE__ ) . '/includes/WebStart.php' );
6969
70 -wfIndexMain();
 70+try {
 71+ wfIndexMain();
 72+} catch ( Exception $e ) {
 73+ wfExceptionHandler( $e );
 74+}
7175
7276 function wfIndexMain() {
7377 global $wgRequest, $wgShowHostnames, $mediaWiki, $wgTitle, $wgUseAjax, $wgUseFileCache;

Sign-offs

UserFlagDate
Hasharinspected11:20, 27 May 2011

Follow-up revisions

RevisionCommit summaryAuthorDate
r90338As discussed in r85918 CR. Move everything from wfIndexMain() at index.php to...platonides14:50, 18 June 2011

Status & tagging log